Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finished lan module.

  • Loading branch information...
commit ba3dbc12f1a03a5403fd3ff0b991deb748ddc946 1 parent c8a49bc
@melwil melwil authored
View
4 studlan/lan/models.py
@@ -12,6 +12,10 @@ class LAN(models.Model):
location = models.CharField("location", max_length=100)
description = models.TextField("description")
+ @property
+ def attendees(self):
+ return map(lambda x: getattr(x, 'user'), Attendee.objects.filter(lan=self))
+
def status(self):
now = datetime.now()
if now < start_date:
View
5 studlan/lan/urls.py
@@ -3,7 +3,10 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('studlan.lan.views',
- url(r'^$', 'list', name='lan_list'),
+ url(r'^$', 'home', name='lan_home'),
+ url(r'^list/$', 'listing', name='lan_listing'),
url(r'^(?P<lan_id>\d+)/$', 'details', name='lan_details'),
+ url(r'^(?P<lan_id>\d+)/attend/$', 'attend', name='lan_attend'),
+ url(r'^(?P<lan_id>\d+)/unattend/$', 'unattend', name='lan_unattend'),
url(r'^(?P<lan_id>\d+)/(?P<user_id>\d+)$', 'history', name='lan_history'),
)
View
55 studlan/lan/views.py
@@ -1,17 +1,64 @@
# -*- coding: utf-8 -*-
+from datetime import datetime
+
+from django.contrib import messages
+from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
-from django.shortcuts import render
+from django.shortcuts import render, redirect, get_object_or_404
+
+from studlan.lan.models import LAN, Attendee
-from studlan.lan.models import LAN
+def home(request):
+ lans = LAN.objects.filter(end_date__gte=datetime.now())
+ if lans:
+ next_lan = lans[0]
+ return details(request, next_lan.id)
+ else:
+ return listing(request)
-def list(request):
+def listing(request):
lans = LAN.objects.all()
return render(request, 'lan/list.html', {'lans': lans})
def details(request, lan_id):
- return HttpResponseRedirect('/')
+ lan = get_object_or_404(LAN, pk=lan_id)
+
+ if request.user in lan.attendees:
+ status = 'attending'
+ else:
+ status = 'open'
+
+ return render(request, 'lan/details.html', {'lan': lan, 'status': status})
def history(request, lan_id, user_id):
return HttpResponseRedirect('/')
+
+@login_required
+def attend(request, lan_id):
+ lan = get_object_or_404(LAN, pk=lan_id)
+
+ if request.user in lan.attendees:
+ messages.error(request, "You are already in the attendee list for %s" % lan)
+ else:
+ attendee = Attendee(lan=lan, user=request.user)
+ attendee.save()
+
+ messages.success(request, "Successfully added you to attendee list for %s" % lan)
+
+ return redirect(lan)
+
+@login_required
+def unattend(request, lan_id):
+ lan = get_object_or_404(LAN, pk=lan_id)
+
+ if request.user not in lan.attendees:
+ messages.error(request, "You are not in the attendee list for %s" % lan)
+ else:
+ attendee = Attendee.objects.get(lan=lan, user=request.user)
+ attendee.delete()
+
+ messages.success(request, "Successfully removed you from attendee list for %s" % lan)
+
+ return redirect(lan)
View
33 studlan/themes/standard/templates/lan/details.html
@@ -0,0 +1,33 @@
+{% extends "base.html" %}
+
+{% block title %}
+studLAN - {{ lan }}
+{% endblock title %}
+
+{% block content %}
+ <div class="content">
+
+ <h2>{{ lan }}</h2>
+
+ <div>
+ <p>Start date: {{ lan.start_date|date:"d. F Y" }} - {{ lan.start_date|time:"H:i" }}</p>
+ <p>End date: {{ lan.end_date|date:"d. F Y" }} - {{ lan.end_date|time:"H:i" }}</p>
+ <p>Location: {{ lan.location }}</p>
+ </div>
+
+ <hr />
+
+ <p>
+ {% if status == 'attending' %}
+ <a class="btn danger" href="{% url lan_unattend lan.id %}">Remove attendance</a>
+ {% else %}
+ <a class="btn success" href="{% url lan_attend lan.id %}">Sign up</a>
+ {% endif %}
+ </p>
+
+ <hr />
+
+ {{ lan.description }}
+
+ </div>
+{% endblock content %}
Please sign in to comment.
Something went wrong with that request. Please try again.