Add simple for for adding Events to a Team

This commit is contained in:
Michael Hall 2017-12-31 16:54:35 -05:00
parent 8f3e190c19
commit df64e46913
9 changed files with 65 additions and 8 deletions

View file

@ -1,5 +1,6 @@
from django.forms import ModelForm from django.forms import ModelForm
from .models.profiles import Team from .models.profiles import Team
from .models.events import Event
class TeamForm(ModelForm): class TeamForm(ModelForm):
class Meta: class Meta:
@ -10,3 +11,14 @@ class NewTeamForm(ModelForm):
class Meta: class Meta:
model = Team model = Team
fields = ['name', 'country', 'spr', 'city', 'web_url', 'tz'] fields = ['name', 'country', 'spr', 'city', 'web_url', 'tz']
class TeamEventForm(ModelForm):
class Meta:
model = Event
fields = ['name', 'start_time', 'end_time', 'summary', 'place', 'web_url', 'announce_url', 'tags']
class NewTeamEventForm(ModelForm):
class Meta:
model = Event
fields = ['name', 'start_time', 'end_time', 'summary', 'place']

View file

@ -59,7 +59,6 @@ class Event(models.Model):
super().save(*args, **kwargs) # Call the "real" save() method. super().save(*args, **kwargs) # Call the "real" save() method.
update_event_searchable(self) update_event_searchable(self)
def update_event_searchable(event): def update_event_searchable(event):
site = Site.objects.get(id=1) site = Site.objects.get(id=1)
event_url = "https://%s%s" % (site.domain, event.get_absolute_url()) event_url = "https://%s%s" % (site.domain, event.get_absolute_url())
@ -84,8 +83,8 @@ def update_event_searchable(event):
searchable.latitude = event.place.latitude searchable.latitude = event.place.latitude
else: else:
searchable.location_name = "" searchable.location_name = ""
searchable.longitude = null searchable.longitude = None
searchable.latitude = null searchable.latitude = None
searchable.save() searchable.save()
def slugify(s, ok=SLUG_OK, lower=True, spaces=False): def slugify(s, ok=SLUG_OK, lower=True, spaces=False):

View file

@ -0,0 +1,3 @@
<table>
{{ event_form }}
</table>

View file

@ -0,0 +1,12 @@
{% extends "get_together/base.html" %}
{% block content %}
<h2>Have a Get Together</h2>
<form action="{% url "create-event" team.id%}" method="post">
{% csrf_token %}
{% include "events/event_form.html" %}
<br />
<input type="submit" value="Announce your Get Together!" />
</form>
{% endblock %}

View file

@ -1,12 +1,12 @@
{% extends "get_together/base.html" %} {% extends "get_together/base.html" %}
{% block content %} {% block content %}
<h2>Create a new team:</h2> <h2>Get Together with friends</h2>
<form action="{% url "create-team" %}" method="post"> <form action="{% url "create-team" %}" method="post">
{% csrf_token %} {% csrf_token %}
{% include "events/team_form.html" %} {% include "events/team_form.html" %}
<br /> <br />
<input type="submit" value="Start a Get Together!" /> <input type="submit" value="Gather your crew!" />
</form> </form>
{% endblock %} {% endblock %}

View file

@ -3,7 +3,7 @@
{% block content %} {% block content %}
<h2>About {{ event.name }}</h2> <h2>About {{ event.name }}</h2>
<h3>Hosted by {{ team.name }}</h3> <h3>Hosted by <a href="{% url "show-team" team.id %}">{{ team.name }}</a></h3>
{% include "events/event_details.html" %} {% include "events/event_details.html" %}
{% endblock %} {% endblock %}

View file

@ -5,6 +5,9 @@
<h3>Upcoming Events</h3> <h3>Upcoming Events</h3>
{% include "events/event_list.html" %} {% include "events/event_list.html" %}
<br />
<form action="{% url 'create-event' team.id %}" method="get">
<input type="submit" value="Plan a Get Together!" />
</form>
{% endblock %} {% endblock %}

View file

@ -26,6 +26,7 @@ urlpatterns = [
path('events/', views.events_list, name='events'), path('events/', views.events_list, name='events'),
path('create-team/', views.create_team, name='create-team'), path('create-team/', views.create_team, name='create-team'),
path('team/<int:team_id>/', views.show_team, name='show-team'), path('team/<int:team_id>/', views.show_team, name='show-team'),
path('team/<int:team_id>/create-event/', views.create_event, name='create-event'),
path('events/<int:event_id>/<str:event_slug>/', views.show_event, name='show-event'), path('events/<int:event_id>/<str:event_slug>/', views.show_event, name='show-event'),
path('oauth/', include('social_django.urls', namespace='social')), path('oauth/', include('social_django.urls', namespace='social')),

View file

@ -2,10 +2,11 @@ from django.shortcuts import render, redirect
from django.http import HttpResponse, JsonResponse from django.http import HttpResponse, JsonResponse
from events.models.profiles import Team from events.models.profiles import Team
from events.forms import TeamForm, NewTeamForm from events.forms import TeamForm, NewTeamForm, TeamEventForm, NewTeamEventForm
from events.models.events import Event from events.models.events import Event
import datetime
import simplejson import simplejson
# Create your views here. # Create your views here.
@ -59,6 +60,32 @@ def show_team(request, team_id, *args, **kwargs):
} }
return render(request, 'get_together/show_team.html', context) return render(request, 'get_together/show_team.html', context)
def create_event(request, team_id):
team = Team.objects.get(id=team_id)
if request.method == 'GET':
form = NewTeamEventForm()
context = {
'team': team,
'event_form': form,
}
return render(request, 'get_together/create_event.html', context)
elif request.method == 'POST':
form = NewTeamEventForm(request.POST)
if form.is_valid:
form.instance.team = team
form.instance.created_by = request.user.profile
new_event = form.save()
return redirect(new_event.get_absolute_url())
else:
context = {
'team': team,
'event_form': form,
}
return render(request, 'get_together/create_event.html', context)
else:
return redirect('home')
def show_event(request, event_id, event_slug): def show_event(request, event_id, event_slug):
event = Event.objects.get(id=event_id) event = Event.objects.get(id=event_id)
context = { context = {