From 82a696261a92bf52873c9ff7c640fc2dbf5c357f Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sat, 28 Jul 2018 22:31:59 -0400 Subject: [PATCH] Improve organization display pages --- events/forms.py | 12 +- events/migrations/0037_add_org_details.py | 23 ++++ .../0038_add_common_event_continent.py | 19 +++ events/models/events.py | 12 ++ events/models/profiles.py | 41 ++++++ events/templates/events/org_form.html | 3 + .../orgs/create_common_event.html | 2 + .../templates/get_together/orgs/edit_org.html | 13 ++ .../get_together/orgs/show_common_event.html | 46 ++++--- .../templates/get_together/orgs/show_org.html | 40 ++++-- .../get_together/teams/show_team.html | 2 +- get_together/urls.py | 1 + get_together/views/__init__.py | 1 + get_together/views/events.py | 52 +------- get_together/views/orgs.py | 120 ++++++++++++++++++ get_together/views/teams.py | 14 -- 16 files changed, 308 insertions(+), 93 deletions(-) create mode 100644 events/migrations/0037_add_org_details.py create mode 100644 events/migrations/0038_add_common_event_continent.py create mode 100644 events/templates/events/org_form.html create mode 100644 get_together/templates/get_together/orgs/edit_org.html create mode 100644 get_together/views/orgs.py diff --git a/events/forms.py b/events/forms.py index 736abfd..fcd3405 100644 --- a/events/forms.py +++ b/events/forms.py @@ -371,6 +371,15 @@ class SearchForm(forms.Form): 'city': Lookup(source=City, label='name'), } +class OrganizationForm(forms.ModelForm): + class Meta: + model = Team + fields = [ + 'name', + 'description', + 'cover_img', + ] + class NewCommonEventForm(forms.ModelForm): class Meta: model = CommonEvent @@ -380,6 +389,7 @@ class NewCommonEventForm(forms.ModelForm): 'end_time', 'summary', + 'continent', 'country', 'spr', 'city', @@ -388,8 +398,6 @@ class NewCommonEventForm(forms.ModelForm): 'web_url', 'announce_url', - 'category', - 'tags', ] widgets ={ 'country': Lookup(source=Country, label='name'), diff --git a/events/migrations/0037_add_org_details.py b/events/migrations/0037_add_org_details.py new file mode 100644 index 0000000..73c96e9 --- /dev/null +++ b/events/migrations/0037_add_org_details.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0 on 2018-07-29 01:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0036_auto_20180701_2148'), + ] + + operations = [ + migrations.AddField( + model_name='organization', + name='cover_img', + field=models.ImageField(blank=True, null=True, upload_to='org_covers', verbose_name='Cover Image'), + ), + migrations.AddField( + model_name='organization', + name='description', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/events/migrations/0038_add_common_event_continent.py b/events/migrations/0038_add_common_event_continent.py new file mode 100644 index 0000000..328530f --- /dev/null +++ b/events/migrations/0038_add_common_event_continent.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0 on 2018-07-29 01:48 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0037_add_org_details'), + ] + + operations = [ + migrations.AddField( + model_name='commonevent', + name='continent', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='events.Continent'), + ), + ] diff --git a/events/models/events.py b/events/models/events.py index 7f9e98b..b0a6223 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -313,6 +313,7 @@ class CommonEvent(models.Model): end_time = models.DateTimeField(help_text=_('Date and time that the event ends'), verbose_name=_('End Time'), db_index=True) summary = models.TextField(help_text=_('Summary of the Event'), blank=True, null=True) + continent = models.ForeignKey(Continent, null=True, blank=True, on_delete=models.SET_NULL) country = models.ForeignKey(Country, null=True, blank=True, on_delete=models.SET_NULL) spr = models.ForeignKey(SPR, null=True, blank=True, on_delete=models.SET_NULL) city = models.ForeignKey(City, null=True, blank=True, on_delete=models.SET_NULL) @@ -339,6 +340,17 @@ class CommonEvent(models.Model): schema = 'https' return "%s://%s%s" % (schema, site.domain, self.get_absolute_url()) + def location(self): + if not self.continent: + return _('Global') + elif not self.country: + return self.continent + elif not self.spr: + return self.country + elif not self.city: + return self.spr + else: + return self.city @property def slug(self): return slugify(self.name) diff --git a/events/models/profiles.py b/events/models/profiles.py index a17dfd5..b7e5e76 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -132,6 +132,18 @@ class UserProfile(models.Model): return True return False + def can_edit_org(self, org): + try: + if self.user.is_superuser: + return True + except: + return False + if not self.user_id: + return False + if org.owner_profile == self: + return True + return False + def can_create_common_event(self, org): try: if self.user.is_superuser: @@ -196,6 +208,35 @@ class Organization(models.Model): owner_profile = models.ForeignKey(UserProfile, related_name='owned_orgs', blank=False, null=True, on_delete=models.SET_NULL) + cover_img = models.ImageField(verbose_name=_('Cover Image'), upload_to='org_covers', null=True, blank=True) + tile_img = ImageSpecField(source='cover_img', + processors=[ + Adjust(contrast=0.8, color=1), + ResizeToFill(338, 200), + ], + format='PNG') + + banner_img = ImageSpecField(source='cover_img', + processors=[ + Adjust(contrast=0.8, color=1), + ResizeToFill(825, 200), + ], + format='PNG') + + description = models.TextField(blank=True, null=True) + + def save(self, *args, **kwargs): + new_slug = slugify(self.name) + slug_matches = list(Organization.objects.filter(slug=new_slug)) + if len(slug_matches) == 0 or (len(slug_matches) == 1 and slug_matches[0].id == self.id): + self.slug = new_slug + else: + self.slug = '%s-%s' % (new_slug, self.id) + super().save(*args, **kwargs) # Call the "real" save() method. + + def get_absolute_url(self): + return reverse('show-org', kwargs={'org_slug': self.slug}) + def __str__(self): return u'%s' % (self.name) diff --git a/events/templates/events/org_form.html b/events/templates/events/org_form.html new file mode 100644 index 0000000..50dc771 --- /dev/null +++ b/events/templates/events/org_form.html @@ -0,0 +1,3 @@ + +{{ org_form }} +
diff --git a/get_together/templates/get_together/orgs/create_common_event.html b/get_together/templates/get_together/orgs/create_common_event.html index 8a26618..376beaa 100644 --- a/get_together/templates/get_together/orgs/create_common_event.html +++ b/get_together/templates/get_together/orgs/create_common_event.html @@ -31,6 +31,8 @@ $(document).ready(function(){ $("#id_end_time_0").datepicker(); + $("#id_continent").selectmenu(); + $("#country_select").lookup({ search: function(searchText, callback) { if (searchText.length < 3) return callback(searchText, []); diff --git a/get_together/templates/get_together/orgs/edit_org.html b/get_together/templates/get_together/orgs/edit_org.html new file mode 100644 index 0000000..6f0dd77 --- /dev/null +++ b/get_together/templates/get_together/orgs/edit_org.html @@ -0,0 +1,13 @@ +{% extends "get_together/base.html" %} +{% load static %} +{% block content %} +

Update {{org.name}}

+
+{% csrf_token %} +{% include "events/org_form.html" %} +
+ +
+{% endblock %} + + diff --git a/get_together/templates/get_together/orgs/show_common_event.html b/get_together/templates/get_together/orgs/show_common_event.html index 3cd9aec..a5b43cb 100644 --- a/get_together/templates/get_together/orgs/show_common_event.html +++ b/get_together/templates/get_together/orgs/show_common_event.html @@ -78,29 +78,45 @@ {% endif %}{% endblock %} {% block content %} -
+
-

{{ common_event.name }} - {% if can_edit_event %} - Edit - {% endif %} + {% if can_edit_event %} + Edit + {% endif %} + {% if common_event.organization.banner_img %} +
+ {{common_event.organization.name}}'s cover image +

{{ common_event.name }}

+
+ {% else %} +

{{ common_event.name }}

+ {% endif %} + +
{% if settings.SOCIAL_AUTH_TWITTER_KEY %} Tweet {% endif %} {% if settings.SOCIAL_AUTH_FACEBOOK_KEY %} Share {% endif %} -

Organized by {{ common_event.organization.name }}


+
-

{{ common_event.summary|markdown }}

+
+

Organized by {{ common_event.organization.name }}

+ {% if common_event.summary %} +

{{ common_event.summary|markdown }}

+ {% endif %} +
+ +
- + - + {% if common_event.place %} @@ -120,13 +136,14 @@ {% endif %}
Time:{{ common_event.start_time }} - {{ common_event.end_time }}Date:{{ common_event.start_time }} - {{ common_event.end_time }}
Category:{{ common_event.category.name }}Location:{{ common_event.location }}
-
-
+
+ +
-

Participating Teams


+

Participating Teams

- {% for event in common_event.participating_events.all %} + {% for event in participating_events %}
@@ -152,10 +169,9 @@
-
diff --git a/get_together/templates/get_together/orgs/show_org.html b/get_together/templates/get_together/orgs/show_org.html index 61c9441..3cf93cc 100644 --- a/get_together/templates/get_together/orgs/show_org.html +++ b/get_together/templates/get_together/orgs/show_org.html @@ -18,25 +18,45 @@ {% endblock %} {% block content %} -
+
-

Welcome to {{ org.name }} -


+ {% if can_edit_org %} + + {% endif %} + {% if org.banner_img %} +
+ {{org.name}}'s cover image +

Welcome to {{ org.name }}

+
+ {% else %} +

Welcome to {{ org.name }}

+ {% endif %} + {% if org.description %} +
+
+

{{ org.description|markdown }}

+
+
+ {% endif %} + +

Upcoming Events

-
{% for event in upcoming_events %}
-
{{ event.place }}
+
{{ event.location }}
{{ event.start_time }}
{% endfor %} {% if can_create_event %} {% endif %} @@ -44,12 +64,12 @@
{% if recent_events %} +

Recent Events

-
{% for event in recent_events %}
-
{{ event.place }}
+
{{ event.location }}
{{ event.start_time }}
{% endfor %} @@ -59,8 +79,8 @@
-
-

Members


+
+

Member Teams


{% for member in member_list %}
diff --git a/get_together/templates/get_together/teams/show_team.html b/get_together/templates/get_together/teams/show_team.html index f72d922..cf9aea0 100644 --- a/get_together/templates/get_together/teams/show_team.html +++ b/get_together/templates/get_together/teams/show_team.html @@ -37,7 +37,7 @@ {% if can_create_event %} {% endif %} diff --git a/get_together/urls.py b/get_together/urls.py index 4e87651..f665d36 100644 --- a/get_together/urls.py +++ b/get_together/urls.py @@ -100,6 +100,7 @@ urlpatterns = [ path('series///', views.show_series, name='show-series'), path('org//', views.show_org, name='show-org'), + path('org//+edit/', views.edit_org, name='edit-org'), path('org//+create-event/', views.create_common_event, name='create-common-event'), path('common//+create-event/', views.create_common_event_team_select, name='create-common-event-team-select'), path('common///', views.show_common_event, name='show-common-event'), diff --git a/get_together/views/__init__.py b/get_together/views/__init__.py index 529c2e3..0d48919 100644 --- a/get_together/views/__init__.py +++ b/get_together/views/__init__.py @@ -24,6 +24,7 @@ import math import traceback from .teams import * +from .orgs import * from .events import * from .places import * from .user import * diff --git a/get_together/views/events.py b/get_together/views/events.py index 03a960f..d613bbc 100644 --- a/get_together/views/events.py +++ b/get_together/views/events.py @@ -126,7 +126,7 @@ def create_event(request, team_id): if request.method == 'GET': if 'common' in request.GET and request.GET['common'] != '': new_event.parent = CommonEvent.objects.get(id=request.GET['common']) - form = NewTeamEventForm(instance=new_event) + form = NewTeamEventForm(instance=new_event, initial={'name': new_event.parent.name, 'summary': new_event.parent.summary}) context = { 'event': new_event, @@ -832,54 +832,4 @@ def delete_series(request, series_id): else: return redirect('home') -def show_common_event(request, event_id, event_slug): - event = get_object_or_404(CommonEvent, id=event_id) - context = { - 'org': event.organization, - 'common_event': event, - 'can_edit_event': False, - } - return render(request, 'get_together/orgs/show_common_event.html', context) - -@login_required -def create_common_event(request, org_slug): - org = get_object_or_404(Organization, slug=org_slug) - if not request.user.profile.can_create_common_event(org): - messages.add_message(request, messages.WARNING, message=_('You can not create events for this org.')) - return redirect('show-org', org_id=org.pk) - - new_event = CommonEvent(organization=org, created_by=request.user.profile) - if request.method == 'GET': - form = NewCommonEventForm(instance=new_event) - - context = { - 'org': org, - 'event_form': form, - } - return render(request, 'get_together/orgs/create_common_event.html', context) - elif request.method == 'POST': - form = NewCommonEventForm(request.POST, instance=new_event) - if form.is_valid: - new_event = form.save() - return redirect('show-common-event', new_event.id, new_event.slug) - else: - context = { - 'org': org, - 'event_form': form, - } - return render(request, 'get_together/orgs/create_common_event.html', context) - else: - return redirect('home') - -@login_required -def create_common_event_team_select(request, event_id): - teams = request.user.profile.moderating - if len(teams) == 1: - return redirect(reverse('create-event', kwargs={'team_id':teams[0].id}) + '?common=%s'%event_id) - context = { - 'common_event_id': event_id, - 'teams': teams - } - return render(request, 'get_together/orgs/create_common_event_team_select.html', context) - diff --git a/get_together/views/orgs.py b/get_together/views/orgs.py new file mode 100644 index 0000000..1799078 --- /dev/null +++ b/get_together/views/orgs.py @@ -0,0 +1,120 @@ +from django.utils.translation import ugettext_lazy as _ + +from django.contrib import messages +from django.contrib.auth import logout as logout_user +from django.contrib.auth.decorators import login_required +from django.contrib.sites.models import Site +from django.shortcuts import render, redirect, get_object_or_404 +from django.http import HttpResponse, JsonResponse +from django.core.mail import send_mail +from django.template.loader import get_template, render_to_string +from django.conf import settings + + +from events.models.profiles import Organization, Team, UserProfile, Member +from events.models.events import Event, CommonEvent, Place, Attendee +from events.forms import OrganizationForm, NewCommonEventForm +from events import location +from events.utils import slugify + +from accounts.models import EmailRecord + +import datetime +import simplejson + +# Create your views here. +def show_org(request, org_slug): + org = get_object_or_404(Organization, slug=org_slug) + upcoming_events = CommonEvent.objects.filter(organization=org, end_time__gt=datetime.datetime.now()).order_by('start_time') + recent_events = CommonEvent.objects.filter(organization=org, end_time__lte=datetime.datetime.now()).order_by('-start_time')[:5] + context = { + 'org': org, + 'upcoming_events': upcoming_events, + 'recent_events': recent_events, + 'member_list': Team.objects.filter(organization=org).order_by('name'), + 'can_create_event': request.user.profile.can_create_common_event(org), + 'can_edit_org': request.user.profile.can_edit_org(org), + } + return render(request, 'get_together/orgs/show_org.html', context) + + +@login_required +def edit_org(request, org_slug): + org = get_object_or_404(Organization, slug=org_slug) + if not request.user.profile.can_edit_org(org): + messages.add_message(request, messages.WARNING, message=_('You can not make changes to this organization.')) + return redirect('show-org', org_slug=org.slug) + + if request.method == 'GET': + form = OrganizationForm(instance=org) + + context = { + 'org': org, + 'org_form': form, + } + return render(request, 'get_together/orgs/edit_org.html', context) + elif request.method == 'POST': + form = OrganizationForm(request.POST, request.FILES, instance=org) + if form.is_valid(): + form.save() + return redirect('show-org', org_slug=org.slug) + else: + context = { + 'org': org, + 'org_form': form, + } + return render(request, 'get_together/orgs/edit_org.html', context) + else: + return redirect('home') + +def show_common_event(request, event_id, event_slug): + event = get_object_or_404(CommonEvent, id=event_id) + context = { + 'org': event.organization, + 'common_event': event, + 'participating_events': event.participating_events.all().order_by('start_time'), + 'can_edit_event': False, + } + return render(request, 'get_together/orgs/show_common_event.html', context) + +@login_required +def create_common_event(request, org_slug): + org = get_object_or_404(Organization, slug=org_slug) + if not request.user.profile.can_create_common_event(org): + messages.add_message(request, messages.WARNING, message=_('You can not create events for this org.')) + return redirect('show-org', org_id=org.pk) + + new_event = CommonEvent(organization=org, created_by=request.user.profile) + if request.method == 'GET': + form = NewCommonEventForm(instance=new_event) + + context = { + 'org': org, + 'event_form': form, + } + return render(request, 'get_together/orgs/create_common_event.html', context) + elif request.method == 'POST': + form = NewCommonEventForm(request.POST, instance=new_event) + if form.is_valid: + new_event = form.save() + return redirect('show-common-event', new_event.id, new_event.slug) + else: + context = { + 'org': org, + 'event_form': form, + } + return render(request, 'get_together/orgs/create_common_event.html', context) + else: + return redirect('home') + +@login_required +def create_common_event_team_select(request, event_id): + teams = request.user.profile.moderating + if len(teams) == 1: + return redirect(reverse('create-event', kwargs={'team_id':teams[0].id}) + '?common=%s'%event_id) + context = { + 'common_event_id': event_id, + 'teams': teams + } + return render(request, 'get_together/orgs/create_common_event_team_select.html', context) + diff --git a/get_together/views/teams.py b/get_together/views/teams.py index b4a7160..79f27ae 100644 --- a/get_together/views/teams.py +++ b/get_together/views/teams.py @@ -335,17 +335,3 @@ def contact_member(member, body, sender): ok=success ) -def show_org(request, org_slug): - org = get_object_or_404(Organization, slug=org_slug) - upcoming_events = CommonEvent.objects.filter(organization=org, end_time__gt=datetime.datetime.now()).order_by('start_time') - recent_events = CommonEvent.objects.filter(organization=org, end_time__lte=datetime.datetime.now()).order_by('-start_time')[:5] - context = { - 'org': org, - 'upcoming_events': upcoming_events, - 'recent_events': recent_events, - 'member_list': Team.objects.filter(organization=org).order_by('name'), - 'can_create_event': request.user.profile.can_create_common_event(org), - } - return render(request, 'get_together/orgs/show_org.html', context) - -