diff --git a/events/forms.py b/events/forms.py index 0d8364d..4f0be34 100644 --- a/events/forms.py +++ b/events/forms.py @@ -1,5 +1,6 @@ from django.forms import ModelForm from .models.profiles import Team +from .models.events import Event class TeamForm(ModelForm): class Meta: @@ -10,3 +11,14 @@ class NewTeamForm(ModelForm): class Meta: model = Team 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'] + diff --git a/events/models/events.py b/events/models/events.py index ec8a677..742e1cf 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -59,7 +59,6 @@ class Event(models.Model): super().save(*args, **kwargs) # Call the "real" save() method. update_event_searchable(self) - def update_event_searchable(event): site = Site.objects.get(id=1) 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 else: searchable.location_name = "" - searchable.longitude = null - searchable.latitude = null + searchable.longitude = None + searchable.latitude = None searchable.save() def slugify(s, ok=SLUG_OK, lower=True, spaces=False): diff --git a/events/templates/events/event_form.html b/events/templates/events/event_form.html new file mode 100644 index 0000000..1da0db9 --- /dev/null +++ b/events/templates/events/event_form.html @@ -0,0 +1,3 @@ + +{{ event_form }} +
diff --git a/get_together/templates/get_together/create_event.html b/get_together/templates/get_together/create_event.html new file mode 100644 index 0000000..43f4c2f --- /dev/null +++ b/get_together/templates/get_together/create_event.html @@ -0,0 +1,12 @@ +{% extends "get_together/base.html" %} + +{% block content %} +

Have a Get Together

+
+{% csrf_token %} +{% include "events/event_form.html" %} +
+ +
+{% endblock %} + diff --git a/get_together/templates/get_together/create_team.html b/get_together/templates/get_together/create_team.html index 3c94c49..3ed19fb 100644 --- a/get_together/templates/get_together/create_team.html +++ b/get_together/templates/get_together/create_team.html @@ -1,12 +1,12 @@ {% extends "get_together/base.html" %} {% block content %} -

Create a new team:

+

Get Together with friends

{% csrf_token %} {% include "events/team_form.html" %}
- +
{% endblock %} diff --git a/get_together/templates/get_together/show_event.html b/get_together/templates/get_together/show_event.html index c0d750c..6322aa8 100644 --- a/get_together/templates/get_together/show_event.html +++ b/get_together/templates/get_together/show_event.html @@ -3,7 +3,7 @@ {% block content %}

About {{ event.name }}

-

Hosted by {{ team.name }}

+

Hosted by {{ team.name }}

{% include "events/event_details.html" %} {% endblock %} diff --git a/get_together/templates/get_together/show_team.html b/get_together/templates/get_together/show_team.html index 9030b58..1662092 100644 --- a/get_together/templates/get_together/show_team.html +++ b/get_together/templates/get_together/show_team.html @@ -5,6 +5,9 @@

Upcoming Events

{% include "events/event_list.html" %} - +
+
+ +
{% endblock %} diff --git a/get_together/urls.py b/get_together/urls.py index 15361a3..7c425a6 100644 --- a/get_together/urls.py +++ b/get_together/urls.py @@ -26,6 +26,7 @@ urlpatterns = [ path('events/', views.events_list, name='events'), path('create-team/', views.create_team, name='create-team'), path('team//', views.show_team, name='show-team'), + path('team//create-event/', views.create_event, name='create-event'), path('events///', views.show_event, name='show-event'), path('oauth/', include('social_django.urls', namespace='social')), diff --git a/get_together/views.py b/get_together/views.py index ba01b53..72e7e59 100644 --- a/get_together/views.py +++ b/get_together/views.py @@ -2,10 +2,11 @@ from django.shortcuts import render, redirect from django.http import HttpResponse, JsonResponse 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 +import datetime import simplejson # 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) +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): event = Event.objects.get(id=event_id) context = {