Event list

This commit is contained in:
Raphael Michel
2014-09-12 21:32:14 +02:00
parent 9f3fb52cce
commit b2b653e57e
6 changed files with 67 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ from django.db import models
from django.conf import settings
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import date as _date
class UserManager(BaseUserManager):
@@ -244,6 +245,20 @@ class Event(models.Model):
verbose_name=_("Last date of payments")
)
def get_date_from_display(self):
return _date(
self.date_from,
"DATETIME_FORMAT" if self.show_times else "DATE_FORMAT"
)
def get_date_to_display(self):
if not self.show_date_to:
return ""
return _date(
self.date_to,
"DATETIME_FORMAT" if self.show_times else "DATE_FORMAT"
)
def __str__(self):
return self.name

View File

@@ -1,7 +1,9 @@
from django.conf import settings
from django.core.urlresolvers import resolve
def contextprocessor(request):
return {
'url_name': resolve(request.path_info).url_name,
'settings': settings,
}

View File

@@ -4,7 +4,7 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ settings.TIXL_INSTANCE_NAME }}</title>
<title>{% block title %}{% endblock %}{% if url_name != "index" %} :: {% endif %}{{ settings.TIXL_INSTANCE_NAME }}</title>
{% compress css %}
<link rel="stylesheet" type="text/less" href="{% static "tixlcontrol/less/main.less" %}" />
{% endcompress %}
@@ -23,7 +23,10 @@
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="{% url 'control:index' %}">{% trans "Dashboard" %}</a></li>
{% block nav %}
<li {% if url_name == "index" %}class="active"{% endif %}><a href="{% url 'control:index' %}">{% trans "Dashboard" %}</a></li>
<li {% if "events" in url_name %}class="active"{% endif %}><a href="{% url 'control:events' %}">{% trans "Events" %}</a></li>
{% endblock %}
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><i class="fa fa-user"></i> {{ request.user.get_full_name }}</a></li>

View File

@@ -0,0 +1,27 @@
{% extends "tixlcontrol/base.html" %}
{% load i18n %}
{% block title %}{% trans "Events" %}{% endblock %}
{% block content %}
<h1>{% trans "Events" %}</h1>
<p>{% trans "The list below shows all events you have administrative access to. Click on the event name to access event details." %}</p>
<table class="table table-condensed table-hover">
<thead>
<tr>
<th>{% trans "Event name" %}</th>
<th>{% trans "Organizer" %}</th>
<th>{% trans "Start date" %}</th>
<th>{% trans "End date" %}</th>
</tr>
</thead>
<tbody>
{% for e in events %}
<tr>
<td><strong><a href="">{{ e.name }}</a></strong></td>
<td>{{ e.organizer }}</td>
<td>{{ e.get_date_from_display }}</td>
<td>{{ e.get_date_to_display }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@@ -1,7 +1,9 @@
from django.conf.urls import patterns, url
from tixlcontrol.views import main
urlpatterns = patterns('',
url(r'^$', 'tixlcontrol.views.main.index', name='index'),
url(r'^events/$', main.EventList.as_view(), name='events'),
url(r'^logout$', 'tixlcontrol.views.auth.logout', name='auth.logout'),
url(r'^login$', 'tixlcontrol.views.auth.login', name='auth.login'),
)

View File

@@ -1,5 +1,20 @@
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic import ListView
from tixlbase.models import Event
class EventList(ListView):
model = Event
context_object_name = 'events'
template_name = 'tixlcontrol/events/index.html'
def get_queryset(self):
return Event.objects.filter(
permitted__id__exact=self.request.user.pk
).prefetch_related(
"organizer",
)
def index(request):