diff --git a/events/models/profiles.py b/events/models/profiles.py index 33cee39..3afc3a7 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -71,6 +71,14 @@ class UserProfile(models.Model): local = self.timezone.localize(dt) return local.astimezone(pytz.utc) + @property + def administering(self): + return [member.team for member in Member.objects.filter(user=self, role=Member.ADMIN)] + + @property + def moderating(self): + return [member.team for member in Member.objects.filter(user=self, role__in=(Member.ADMIN, Member.MODERATOR))] + def can_create_event(self, team): try: if self.user.is_superuser: @@ -81,9 +89,7 @@ class UserProfile(models.Model): return False if team.owner_profile == self: return True - if self in team.admin_profiles.all(): - return True - if self in team.contact_profiles.all(): + if self in team.moderators: return True return False @@ -97,7 +103,7 @@ class UserProfile(models.Model): return True if event.team.owner_profile == self: return True - if self in event.team.admin_profiles.all(): + if self in event.team.moderators: return True return False @@ -109,7 +115,7 @@ class UserProfile(models.Model): return False if team.owner_profile == self: return True - if self in team.admin_profiles.all(): + if self in team.moderators: return True return False @@ -193,6 +199,14 @@ class Team(models.Model): else: return '' + @property + def administrators(self): + return [member.user for member in Member.objects.filter(team=self, role=Member.ADMIN)] + + @property + def moderators(self): + return [member.user for member in Member.objects.filter(team=self, role__in=(Member.ADMIN, Member.MODERATOR))] + def __str__(self): return u'%s' % (self.name) diff --git a/get_together/templates/get_together/events/create_event.html b/get_together/templates/get_together/events/create_event.html index e5fdf22..228754e 100644 --- a/get_together/templates/get_together/events/create_event.html +++ b/get_together/templates/get_together/events/create_event.html @@ -5,7 +5,7 @@ {% endblock %} {% block content %} -

Plan a Get Together

+

Plan a {{team.name}} get together

{% csrf_token %}
diff --git a/get_together/templates/get_together/events/create_event_team_select.html b/get_together/templates/get_together/events/create_event_team_select.html new file mode 100644 index 0000000..15c5876 --- /dev/null +++ b/get_together/templates/get_together/events/create_event_team_select.html @@ -0,0 +1,41 @@ +{% extends "get_together/base.html" %} +{% load static %} + +{% block styles %} + + +{% endblock %} + +{% block content %} +

Select which team:

+
+
+{% for team in teams %} +
+
+ +
+

{{team.city}}

+
+ {{ team.members.count }} members + +
+
+
+
+{% endfor %} +
+
+{% endblock %} + diff --git a/get_together/templates/get_together/index.html b/get_together/templates/get_together/index.html index d3983af..f1fbf7d 100644 --- a/get_together/templates/get_together/index.html +++ b/get_together/templates/get_together/index.html @@ -47,8 +47,11 @@
{% endfor %} {% else %} -
-
There are no events near you.
+
+
+ There are no events near you. + Create one now +
{% endif %}
@@ -86,8 +89,10 @@ {% endfor %} {% else %}
-
There are no teams near you.
- Create one now +
+ There are no teams near you. + Create one now +
{% endif %} diff --git a/get_together/urls.py b/get_together/urls.py index 4fc6d63..ff4ed55 100644 --- a/get_together/urls.py +++ b/get_together/urls.py @@ -56,6 +56,7 @@ urlpatterns = [ path('team//+leave/', event_views.leave_team, name='leave-team'), path('team//+delete/', views.delete_team, name='delete-team'), + path('team/+create-event/', views.create_event_team_select, name='create-event-team-select'), path('team//+create-event/', views.create_event, name='create-event'), path('events//+edit/', views.edit_event, name='edit-event'), path('events//+attend/', event_views.attend_event, name='attend-event'), diff --git a/get_together/views/events.py b/get_together/views/events.py index 3104d1d..ecbb26b 100644 --- a/get_together/views/events.py +++ b/get_together/views/events.py @@ -2,6 +2,7 @@ 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.shortcuts import render, redirect from django.http import HttpResponse, JsonResponse @@ -32,6 +33,15 @@ def show_event(request, event_id, event_slug): } return render(request, 'get_together/events/show_event.html', context) +@login_required +def create_event_team_select(request): + teams = request.user.profile.moderating + if len(teams) == 1: + return redirect('create-event', team_id=teams[0].id) + + return render(request, 'get_together/events/create_event_team_select.html', {'teams': teams}) + +@login_required def create_event(request, team_id): team = Team.objects.get(id=team_id) if not request.user.profile.can_create_event(team): diff --git a/get_together/views/teams.py b/get_together/views/teams.py index e658882..b6c6a97 100644 --- a/get_together/views/teams.py +++ b/get_together/views/teams.py @@ -32,7 +32,7 @@ def show_team(request, team_id, *args, **kwargs): 'upcoming_events': upcoming_events, 'recent_events': recent_events, 'is_member': request.user.profile in team.members.all(), - 'member_list': Member.objects.filter(team=team), + 'member_list': Member.objects.filter(team=team).order_by('-role', 'joined_date'), 'can_create_event': request.user.profile.can_create_event(team), 'can_edit_team': request.user.profile.can_edit_team(team), }