Make it easier to start creating event without having to navigate to a team page first

This commit is contained in:
Michael Hall 2018-03-20 18:35:02 -04:00
parent cb968ac81e
commit 96a087f8d6
7 changed files with 82 additions and 11 deletions

View file

@ -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)

View file

@ -5,7 +5,7 @@
{% endblock %}
{% block content %}
<h2>Plan a Get Together</h2>
<h2>Plan a <strong>{{team.name}}</strong> get together</h2>
<form action="{% url "create-event" team.id%}" method="post">
{% csrf_token %}
<div class="form-group">

View file

@ -0,0 +1,41 @@
{% extends "get_together/base.html" %}
{% load static %}
{% block styles %}
<link href="{% static 'css/bootstrap-album.css' %}" rel="stylesheet"/>
{% endblock %}
{% block content %}
<h2>Select which team:</h2>
<div class="container">
<div class="row">
{% for team in teams %}
<div class="col-md-4">
<div class="card mb-4 box-shadow">
<div class="card-banner">
<a href="{% url 'show-team' team.id %}">
{% if team.category %}
<img class="card-img-top" src="{{team.category.img_url}}" alt="{{team.name}}">
{% else %}
<img class="card-img-top" src="{% static 'img/team_placeholder.png' %}" alt="{{team.name}}">
{% endif %}
</a>
<p class="card-title">{{team.name}}</p>
</div>
<div class="card-body">
<p class="card-text"><strong>{{team.city}}</strong></p>
<div class="d-flex justify-content-between align-items-center">
<small class="text-muted">{{ team.members.count }} members</small>
<div class="btn-group">
<a class="btn btn-success" href="{% url 'create-event' team.id %}">Create Event</a></span>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}

View file

@ -47,8 +47,11 @@
</div>
{% endfor %}
{% else %}
<div class="col-12">
<div class="alert alert-info">There are no events near you.</div>
<div class="col-12 mb-3">
<div class="alert alert-info">
There are no events near you.
<a class="btn btn-success" href="{% url 'create-event-team-select' %}">Create one now</a>
</div>
</div>
{% endif %}
</div>
@ -86,8 +89,10 @@
{% endfor %}
{% else %}
<div class="col-12">
<div class="alert alert-info">There are no teams near you.</div>
<a class="btn btn-success" href="{% url 'create-team' %}">Create one now</a>
<div class="alert alert-info">
There are no teams near you.
<a class="btn btn-success" href="{% url 'create-team' %}">Create one now</a>
</div>
</div>
{% endif %}
</div>

View file

@ -56,6 +56,7 @@ urlpatterns = [
path('team/<int:team_id>/+leave/', event_views.leave_team, name='leave-team'),
path('team/<int:team_id>/+delete/', views.delete_team, name='delete-team'),
path('team/+create-event/', views.create_event_team_select, name='create-event-team-select'),
path('team/<int:team_id>/+create-event/', views.create_event, name='create-event'),
path('events/<int:event_id>/+edit/', views.edit_event, name='edit-event'),
path('events/<int:event_id>/+attend/', event_views.attend_event, name='attend-event'),

View file

@ -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):

View file

@ -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),
}