Start new user experience, setup a new team and view the team's page. Add event details page too, but not create event page yet
This commit is contained in:
parent
a17a5b7894
commit
8f3e190c19
15 changed files with 181 additions and 21 deletions
12
events/forms.py
Normal file
12
events/forms.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from django.forms import ModelForm
|
||||||
|
from .models.profiles import Team
|
||||||
|
|
||||||
|
class TeamForm(ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Team
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
class NewTeamForm(ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Team
|
||||||
|
fields = ['name', 'country', 'spr', 'city', 'web_url', 'tz']
|
|
@ -2,6 +2,7 @@ from django.db import models
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.shortcuts import reverse
|
||||||
|
|
||||||
from .locale import *
|
from .locale import *
|
||||||
from .profiles import *
|
from .profiles import *
|
||||||
|
@ -49,7 +50,7 @@ class Event(models.Model):
|
||||||
#replies
|
#replies
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return "/events/%s/%s" % (self.id, slugify(self.name))
|
return reverse('show-event', kwargs={'event_id': self.id, 'event_slug': slugify(self.name)})
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'%s by %s at %s' % (self.name, self.team.name, self.start_time)
|
return u'%s by %s at %s' % (self.name, self.team.name, self.start_time)
|
||||||
|
|
|
@ -45,8 +45,12 @@ class UserProfile(models.Model):
|
||||||
local = self.timezone.localize(dt)
|
local = self.timezone.localize(dt)
|
||||||
return local.astimezone(pytz.utc)
|
return local.astimezone(pytz.utc)
|
||||||
|
|
||||||
|
def get_user_timezone(username):
|
||||||
|
# TODO: find a smarter way to get timezone
|
||||||
|
return 'UTC'
|
||||||
|
|
||||||
def _getUserProfile(self):
|
def _getUserProfile(self):
|
||||||
if not self.is_authenticated():
|
if not self.is_authenticated:
|
||||||
return UserProfile()
|
return UserProfile()
|
||||||
|
|
||||||
profile, created = UserProfile.objects.get_or_create(user=self)
|
profile, created = UserProfile.objects.get_or_create(user=self)
|
||||||
|
@ -84,11 +88,11 @@ class Team(models.Model):
|
||||||
created_date = models.DateField(_("Date Created"), null=True, blank=True)
|
created_date = models.DateField(_("Date Created"), null=True, blank=True)
|
||||||
|
|
||||||
owner_profile = models.ForeignKey(UserProfile, related_name='owner', null=True, on_delete=models.CASCADE)
|
owner_profile = models.ForeignKey(UserProfile, related_name='owner', null=True, on_delete=models.CASCADE)
|
||||||
admin_profiles = models.ManyToManyField(UserProfile, related_name='admins')
|
admin_profiles = models.ManyToManyField(UserProfile, related_name='admins', blank=True)
|
||||||
contact_profiles = models.ManyToManyField(UserProfile, related_name='contacts')
|
contact_profiles = models.ManyToManyField(UserProfile, related_name='contacts', blank=True)
|
||||||
|
|
||||||
cover_img = models.URLField(_("Team Photo"), null=True, blank=True)
|
cover_img = models.URLField(_("Team Photo"), null=True, blank=True)
|
||||||
languages = models.ManyToManyField(Language)
|
languages = models.ManyToManyField(Language, blank=True)
|
||||||
active = models.BooleanField(_("Active Team"), default=True)
|
active = models.BooleanField(_("Active Team"), default=True)
|
||||||
tz = models.CharField(max_length=32, verbose_name=_('Default Timezone'), default='UTC', choices=[(tz, tz) for tz in pytz.all_timezones], blank=False, null=False, help_text=_('The most commonly used timezone for this Team.'))
|
tz = models.CharField(max_length=32, verbose_name=_('Default Timezone'), default='UTC', choices=[(tz, tz) for tz in pytz.all_timezones], blank=False, null=False, help_text=_('The most commonly used timezone for this Team.'))
|
||||||
|
|
||||||
|
|
13
events/templates/events/event_details.html
Normal file
13
events/templates/events/event_details.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<p>{{ event.summary }}</p>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><b>Time:</b></td><td>{{ event.start_time }} - {{ event.end_time }}</td>
|
||||||
|
</tr><tr>
|
||||||
|
<td><b>Place:</b></td><td>{{ event.place }}</td>
|
||||||
|
{% if event.web_url %}
|
||||||
|
</tr><tr>
|
||||||
|
<td><b>Website:</b></td><td><a href="{{ event.web_url }}">{{ event.web_url }}</a></td>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
|
@ -1,18 +1,9 @@
|
||||||
{% if request.user.is_authenticated %}
|
|
||||||
Welcome {{ request.user.username }}
|
{% if events_list %}
|
||||||
{% else %}
|
|
||||||
Login:
|
|
||||||
<a href="{% url 'social:begin' 'google-oauth2' %}">Google</a>
|
|
||||||
<a href="{% url 'social:begin' 'facebook' %}">Facebook</a>
|
|
||||||
<a href="{% url 'social:begin' 'twitter' %}">Twitter</a>
|
|
||||||
<a href="{% url 'social:begin' 'github' %}">GitHub</a>
|
|
||||||
<br>
|
|
||||||
{% endif %}
|
|
||||||
<center>{% if events_list %}
|
|
||||||
<table border="0" width="960px">
|
<table border="0" width="960px">
|
||||||
{% for event in events_list %}
|
{% for event in events_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ event.get_absolute_url }}/">{{ event.name }}</a></td>
|
<td><a href="{{ event.get_absolute_url }}">{{ event.name }}</a></td>
|
||||||
<td>{{ event.team }}</td>
|
<td>{{ event.team }}</td>
|
||||||
<td>{{ event.start_time }}</td>
|
<td>{{ event.start_time }}</td>
|
||||||
<td>{{ event.place }}</td>
|
<td>{{ event.place }}</td>
|
||||||
|
@ -22,4 +13,4 @@ Login:
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No events are available.</p>
|
<p>No events are available.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</center>
|
|
||||||
|
|
3
events/templates/events/team_form.html
Normal file
3
events/templates/events/team_form.html
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<table>
|
||||||
|
{{ team_form }}
|
||||||
|
</table>
|
|
@ -49,6 +49,7 @@ INSTALLED_APPS = [
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'social_django',
|
'social_django',
|
||||||
|
|
||||||
|
'get_together',
|
||||||
'events',
|
'events',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
8
get_together/templates/get_together/base.html
Normal file
8
get_together/templates/get_together/base.html
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{% if request.user.is_authenticated %}
|
||||||
|
|
||||||
|
Welcome {{ request.user.username }}
|
||||||
|
{% else %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
|
12
get_together/templates/get_together/create_team.html
Normal file
12
get_together/templates/get_together/create_team.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{% extends "get_together/base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Create a new team:</h2>
|
||||||
|
<form action="{% url "create-team" %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% include "events/team_form.html" %}
|
||||||
|
<br />
|
||||||
|
<input type="submit" value="Start a Get Together!" />
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
6
get_together/templates/get_together/events.html
Normal file
6
get_together/templates/get_together/events.html
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{% extends "get_together/base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% include "events/event_list.html" %}
|
||||||
|
{% endblock %}
|
||||||
|
|
15
get_together/templates/get_together/index.html
Normal file
15
get_together/templates/get_together/index.html
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{% extends "get_together/base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<center>
|
||||||
|
<h2>Welcome to Get Together!</h2>
|
||||||
|
|
||||||
|
<h3>Login with:</h3>
|
||||||
|
<a href="{% url 'social:begin' 'google-oauth2' %}">Google</a><br/>
|
||||||
|
<a href="{% url 'social:begin' 'facebook' %}">Facebook</a><br/>
|
||||||
|
<a href="{% url 'social:begin' 'twitter' %}">Twitter</a><br/>
|
||||||
|
<a href="{% url 'social:begin' 'github' %}">GitHub</a><br/>
|
||||||
|
<br>
|
||||||
|
</center>
|
||||||
|
{% endblock %}
|
||||||
|
|
10
get_together/templates/get_together/show_event.html
Normal file
10
get_together/templates/get_together/show_event.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{% extends "get_together/base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>About {{ event.name }}</h2>
|
||||||
|
|
||||||
|
<h3>Hosted by {{ team.name }}</h3>
|
||||||
|
{% include "events/event_details.html" %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
10
get_together/templates/get_together/show_team.html
Normal file
10
get_together/templates/get_together/show_team.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{% extends "get_together/base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Welcome to {{ team.name }}</h2>
|
||||||
|
|
||||||
|
<h3>Upcoming Events</h3>
|
||||||
|
{% include "events/event_list.html" %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -15,12 +15,18 @@ Including another URLconf
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from events import views
|
from events import views as event_views
|
||||||
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('', views.home, name='home'),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('searchables/', views.searchable_list),
|
path('searchables/', event_views.searchable_list),
|
||||||
path('events/', views.events_list, name='home'),
|
|
||||||
|
path('events/', views.events_list, name='events'),
|
||||||
|
path('create-team/', views.create_team, name='create-team'),
|
||||||
|
path('team/<int:team_id>/', views.show_team, name='show-team'),
|
||||||
|
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')),
|
||||||
]
|
]
|
||||||
|
|
68
get_together/views.py
Normal file
68
get_together/views.py
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
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.models.events import Event
|
||||||
|
|
||||||
|
import simplejson
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
|
||||||
|
def home(request, *args, **kwards):
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
user_teams = Team.objects.filter(owner_profile=request.user.profile)
|
||||||
|
if len(user_teams) > 0:
|
||||||
|
return redirect('events')
|
||||||
|
else:
|
||||||
|
return redirect('create-team')
|
||||||
|
else:
|
||||||
|
return render(request, 'get_together/index.html')
|
||||||
|
|
||||||
|
def events_list(request, *args, **kwargs):
|
||||||
|
events = Event.objects.all()
|
||||||
|
context = {
|
||||||
|
'events_list': events,
|
||||||
|
}
|
||||||
|
return render(request, 'get_together/events.html', context)
|
||||||
|
|
||||||
|
def create_team(request, *args, **kwargs):
|
||||||
|
if request.method == 'GET':
|
||||||
|
form = NewTeamForm()
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'team_form': form,
|
||||||
|
}
|
||||||
|
return render(request, 'get_together/create_team.html', context)
|
||||||
|
elif request.method == 'POST':
|
||||||
|
form = NewTeamForm(request.POST)
|
||||||
|
if form.is_valid:
|
||||||
|
new_team = form.save()
|
||||||
|
new_team.owner_profile = request.user.profile
|
||||||
|
new_team.save()
|
||||||
|
return redirect('show-team', team_id=new_team.pk)
|
||||||
|
else:
|
||||||
|
context = {
|
||||||
|
'team_form': form,
|
||||||
|
}
|
||||||
|
return render(request, 'get_together/create_team.html', context)
|
||||||
|
else:
|
||||||
|
return redirect('home')
|
||||||
|
|
||||||
|
def show_team(request, team_id, *args, **kwargs):
|
||||||
|
team = Team.objects.get(id=team_id)
|
||||||
|
team_events = Event.objects.filter(team=team)
|
||||||
|
context = {
|
||||||
|
'team': team,
|
||||||
|
'events_list': team_events,
|
||||||
|
}
|
||||||
|
return render(request, 'get_together/show_team.html', context)
|
||||||
|
|
||||||
|
def show_event(request, event_id, event_slug):
|
||||||
|
event = Event.objects.get(id=event_id)
|
||||||
|
context = {
|
||||||
|
'team': event.team,
|
||||||
|
'event': event,
|
||||||
|
}
|
||||||
|
return render(request, 'get_together/show_event.html', context)
|
Loading…
Reference in a new issue