From f15dc66dc9deba8388456bded0b2692ad9fa0352 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sun, 29 Jul 2018 16:21:46 -0400 Subject: [PATCH] Add ability to create new teams for an organization --- events/models/profiles.py | 2 ++ .../get_together/new_team/start_new_team.html | 3 ++- .../orgs/create_common_event_team_select.html | 6 +---- .../get_together/orgs/show_common_event.html | 8 +++---- .../templates/get_together/orgs/show_org.html | 6 +++++ .../get_together/teams/team_page_base.html | 5 ++++ get_together/views/events.py | 5 +++- get_together/views/new_team.py | 23 ++++++++++++++----- get_together/views/orgs.py | 4 ++++ 9 files changed, 44 insertions(+), 18 deletions(-) diff --git a/events/models/profiles.py b/events/models/profiles.py index b7e5e76..c8dd59e 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -320,6 +320,8 @@ class Team(models.Model): def card_img_url(self): if self.tile_img is not None and self.tile_img.name is not None: return self.tile_img.url + elif self.organization and self.organization.tile_img and self.organization.tile_img.url is not None: + return self.organization.tile_img.url elif self.category is not None: return self.category.img_url else: diff --git a/get_together/templates/get_together/new_team/start_new_team.html b/get_together/templates/get_together/new_team/start_new_team.html index 6a0313d..87da5cb 100644 --- a/get_together/templates/get_together/new_team/start_new_team.html +++ b/get_together/templates/get_together/new_team/start_new_team.html @@ -8,8 +8,9 @@

Pick a name and location for your new team

-
+ {% csrf_token %} + {% if team.organization %}{% endif %}

{% include "events/new_team_form.html" %}

diff --git a/get_together/templates/get_together/orgs/create_common_event_team_select.html b/get_together/templates/get_together/orgs/create_common_event_team_select.html index 315730f..9800a55 100644 --- a/get_together/templates/get_together/orgs/create_common_event_team_select.html +++ b/get_together/templates/get_together/orgs/create_common_event_team_select.html @@ -15,11 +15,7 @@
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 a5b43cb..ec7d6d0 100644 --- a/get_together/templates/get_together/orgs/show_common_event.html +++ b/get_together/templates/get_together/orgs/show_common_event.html @@ -147,12 +147,10 @@
- {% if event.team.category %} - {{event.name}} - {% else %} - {{event.name}} - {% endif %} + + {{event.name}}

{{event.team.name}}

+

{{event.name}}

diff --git a/get_together/templates/get_together/orgs/show_org.html b/get_together/templates/get_together/orgs/show_org.html index 3cf93cc..c78272b 100644 --- a/get_together/templates/get_together/orgs/show_org.html +++ b/get_together/templates/get_together/orgs/show_org.html @@ -86,10 +86,16 @@
{{member.name}}
+ {{member.member_set.count}} Members, {{member.event_set.count}} Events
{% endfor %} +
+
+
Add Team
+
+
diff --git a/get_together/templates/get_together/teams/team_page_base.html b/get_together/templates/get_together/teams/team_page_base.html index 39745fa..d6ac4e1 100644 --- a/get_together/templates/get_together/teams/team_page_base.html +++ b/get_together/templates/get_together/teams/team_page_base.html @@ -32,6 +32,11 @@ {{team.name}}'s cover image

Welcome to {{ team.name }}

+ {% elif team.organization and team.organization.banner_img %} +
+ {{team.organization.name}}'s cover image +

Welcome to {{ team.name }}

+
{% else %}

Welcome to {{ team.name }}

{% endif %} diff --git a/get_together/views/events.py b/get_together/views/events.py index d613bbc..5e66c2a 100644 --- a/get_together/views/events.py +++ b/get_together/views/events.py @@ -124,9 +124,12 @@ def create_event(request, team_id): if request.method == 'GET': + initial = {} if 'common' in request.GET and request.GET['common'] != '': new_event.parent = CommonEvent.objects.get(id=request.GET['common']) - form = NewTeamEventForm(instance=new_event, initial={'name': new_event.parent.name, 'summary': new_event.parent.summary}) + initial['name'] = new_event.parent.name + initial['summary'] = new_event.parent.summary + form = NewTeamEventForm(instance=new_event, initial=initial) context = { 'event': new_event, diff --git a/get_together/views/new_team.py b/get_together/views/new_team.py index bf50983..e908d76 100644 --- a/get_together/views/new_team.py +++ b/get_together/views/new_team.py @@ -17,9 +17,13 @@ import datetime import simplejson @login_required -def start_new_team(request, *args, **kwargs): +def start_new_team(request): + new_team = Team(owner_profile=request.user.profile) + new_team.owner_profile = request.user.profile if request.method == 'GET': - form = NewTeamForm() + if 'organization' in request.GET and request.GET['organization'] != '': + new_team.organization = Organization.objects.get(id=request.GET['organization']) + form = NewTeamForm(instance=new_team) g = location.get_geoip(request) if g.latlng is not None and g.latlng[0] is not None and g.latlng[1] is not None: city = location.get_nearest_city(g.latlng) @@ -27,20 +31,23 @@ def start_new_team(request, *args, **kwargs): form.initial={'city': city, 'tz': city.tz} context = { + 'team': new_team, 'team_form': form, } return render(request, 'get_together/new_team/start_new_team.html', context) elif request.method == 'POST': - form = NewTeamForm(request.POST) + if 'organization' in request.POST and request.POST['organization'] != '': + new_team.organization = Organization.objects.get(id=request.POST['organization']) + form = NewTeamForm(request.POST, request.FILES, instance=new_team) if form.is_valid(): new_team = form.save() - new_team.owner_profile = request.user.profile new_team.save() Member.objects.create(team=new_team, user=request.user.profile, role=Member.ADMIN) ga.add_event(request, action='new_team', category='growth', label=new_team.name) return redirect('define-team', team_id=new_team.pk) else: context = { + 'team': new_team, 'team_form': form, } return render(request, 'get_together/new_team/start_new_team.html', context) @@ -61,8 +68,12 @@ def define_new_team(request, team_id): form = TeamDefinitionForm(request.POST, instance=team) if form.is_valid(): form.save() - messages.add_message(request, messages.SUCCESS, message=_('Your new team is ready to go! Now it\'s time to plan your first event.')) - return redirect('create-event', team_id=team.id) + if team.organization: + messages.add_message(request, messages.SUCCESS, message=_('Your new member team is ready to go!')) + return redirect('show-org', org_slug=team.organization.slug) + else: + messages.add_message(request, messages.SUCCESS, message=_('Your new team is ready to go! Now it\'s time to plan your first event.')) + return redirect('create-event', team_id=team.id) else: context = { 'team': team, diff --git a/get_together/views/orgs.py b/get_together/views/orgs.py index 1799078..b17f544 100644 --- a/get_together/views/orgs.py +++ b/get_together/views/orgs.py @@ -22,6 +22,7 @@ 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) @@ -67,6 +68,7 @@ def edit_org(request, org_slug): else: return redirect('home') + def show_common_event(request, event_id, event_slug): event = get_object_or_404(CommonEvent, id=event_id) context = { @@ -77,6 +79,7 @@ def show_common_event(request, event_id, event_slug): } 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) @@ -107,6 +110,7 @@ def create_common_event(request, org_slug): else: return redirect('home') + @login_required def create_common_event_team_select(request, event_id): teams = request.user.profile.moderating