Add ability to create new teams for an organization

This commit is contained in:
Michael Hall 2018-07-29 16:21:46 -04:00
parent 82a696261a
commit f15dc66dc9
9 changed files with 44 additions and 18 deletions

View file

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

View file

@ -8,8 +8,9 @@
<center>
<h3>Pick a name and location for your new team</h3>
<form action="{% url "create-team" %}" method="post" class="form">
<form action="{% url "create-team" %}" method="post" enctype="multipart/form-data" class="form">
{% csrf_token %}
{% if team.organization %}<input type="hidden" name="organization" value="{{team.organization.id}}" />{% endif %}
<p>{% include "events/new_team_form.html" %}</p>
<p><button type="submit" class="btn btn-primary">Continue</button></p>
</form>

View file

@ -15,11 +15,7 @@
<div class="card mb-4 box-shadow">
<div class="card-banner">
<a href="{% url 'show-team-by-slug' team.slug %}">
{% 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 %}
<img class="card-img-top" src="{{team.card_img_url}}" alt="{{team.name}}">
</a>
<p class="card-title">{{team.name}}</p>
</div>

View file

@ -147,12 +147,10 @@
<div class="col-md-4">
<div class="card mb-4 box-shadow">
<div class="card-banner">
{% if event.team.category %}
<img class="card-img-top" src="{{event.team.category.img_url}}" alt="{{event.name}}">
{% else %}
<img class="card-img-top" src="{% static 'img/team_placeholder.png' %}" alt="{{event.name}}">
{% endif %}
<a href="{{ event.get_absolute_url }}">
<img class="card-img-top" src="{{event.team.card_img_url}}" alt="{{event.name}}">
<p class="card-title">{{event.team.name}}</p>
</a>
</div>
<div class="card-body">
<p class="card-text"><strong><a class="card-link" href="{{event.get_absolute_url}}">{{event.name}}</a></strong></p>

View file

@ -86,10 +86,16 @@
<div class="col media gt-profile">
<div class="media-body">
<h6 class="mt-0 mb-0"><a href="{% url 'show-team-by-slug' member.slug %}" title="{{member.name}}">{{member.name}}</a></h6>
<small class="text-muted">{{member.member_set.count}} Members, {{member.event_set.count}} Events</small>
</div>
</div>
</div>
{% endfor %}
<div class="row mb-3">
<div class="col">
<center><a class="btn btn-success btn-sm" href="{% url 'create-team' %}?organization={{org.id}}">Add Team</a></center>
</div>
</div>
</div>
</div>
</div>

View file

@ -32,6 +32,11 @@
<img class="card-img-top" src="{{ team.banner_img.url }}" alt="{{team.name}}'s cover image" height="200px" width="825px">
<h2 class="team-title">Welcome to {{ team.name }}</h2>
</div>
{% elif team.organization and team.organization.banner_img %}
<div class="team-banner">
<img class="card-img-top" src="{{ team.organization.banner_img.url }}" alt="{{team.organization.name}}'s cover image" height="200px" width="825px">
<h2 class="team-title">Welcome to {{ team.name }}</h2>
</div>
{% else %}
<h2>Welcome to {{ team.name }}</h2>
{% endif %}

View file

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

View file

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

View file

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