summaryrefslogtreecommitdiffstats
path: root/agenda/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'agenda/models.py')
-rwxr-xr-xagenda/models.py142
1 files changed, 108 insertions, 34 deletions
diff --git a/agenda/models.py b/agenda/models.py
index 634f583..0574098 100755
--- a/agenda/models.py
+++ b/agenda/models.py
@@ -1,6 +1,3 @@
-#!/usr/bin/python
-# -*- coding: utf -*-
-
from django.db import models
from django.conf import settings
from infopoint.agenda import *
@@ -15,11 +12,24 @@ from django import forms
from django.forms import ModelForm
from django.template.loader import render_to_string
from datetime import datetime
+from django.utils.translation import ugettext as _
+from calendar import HTMLCalendar
+from datetime import date
+from itertools import groupby
+
+from django.utils.html import conditional_escape as esc
from django.contrib import admin
# Create your models here.
+RECURRENCE_CHOICES = (
+ ('0', 'No recurrence'),
+ ('1', 'Everyday'),
+ ('2', 'Each week'),
+ ('3', 'Monthly'),
+)
+
TIMESPAN_CHOICES = (
('1', 'Future events'),
('2', 'Past events'),
@@ -28,17 +38,42 @@ TIMESPAN_CHOICES = (
)
-EVENT_STATUS_CHOICES = (
- ('1', 'TENTATIVE'),
- ('2', 'CONFIRMED'),
- ('3', 'NEEDS ACTION'),
- ('4', 'CANCELLED'),
-)
-EVENT_CLASS_CHOICES = (
- ('1', 'PUBLIC'),
- ('2', 'PRIVATE'),
- ('3', 'CONFIDENTIAL'),
-)
+class EventShapeCalendar(HTMLCalendar):
+ def __init__(self, events):
+ super(EventShapeCalendar, self).__init__()
+ self.events = self.group_by_day(events)
+ def formatday(self, day, weekday):
+ if day != 0:
+ cssclass = self.cssclasses[weekday]
+ if date.today() == date(self.year, self.month, day):
+ cssclass += ' today'
+ if day in self.events:
+ cssclass += ' filled'
+ body = ['<ul>']
+ for event in self.events[day]:
+ body.append('<li>')
+ body.append(esc(event.start_date.hour))
+ if event.start_date.minute != 0:
+ body.append(':%s' % event.start_date.minute)
+ body.append(' hs. <a href="%s">' % event.get_absolute_url())
+ body.append(esc(event.title))
+ body.append('</a></li>')
+ body.append('</ul>')
+ return self.day_cell(cssclass, '%d %s' % (day, ''.join(body)))
+ return self.day_cell(cssclass, day)
+ return self.day_cell('noday', '&nbsp;')
+
+ def formatmonth(self, year, month):
+ self.year, self.month = year, month
+ return super(EventShapeCalendar, self).formatmonth(year, month)
+
+ def group_by_day(self, events):
+ field = lambda event: event.start_date.day
+ return dict(
+ [(day, list(items)) for day, items in groupby(events, field)] )
+
+ def day_cell(self, cssclass, body):
+ return '<td class="%s">%s</td>' % (cssclass, body)
class Location(models.Model):
"""
@@ -48,7 +83,7 @@ class Location(models.Model):
"""
title = models.CharField(max_length=50)
description = models.TextField()
- size = models.IntegerField(help_text='how many people fits here?')
+ size = models.IntegerField(help_text=_('how many people fits here?'))
color = models.CharField(max_length=6, null=True, blank=True)
picture = models.FileField(upload_to='locations/', null=True,blank=True)
gallery = models.URLField(null=True,blank=True)
@@ -61,6 +96,10 @@ class Location(models.Model):
def colored_location(self):
return '<span style="color: #%s;">%s</span>' % (self.color, self.title)
colored_location.allow_tags = True
+ @models.permalink
+ def get_absolute_url(self):
+ return ('infopoint.agenda.views.location', [str(self.id)])
+
class EventManager(models.Manager):
@@ -89,36 +128,43 @@ class Event(models.Model):
"""
title = models.CharField(max_length=100)
public = models.BooleanField(null=True,blank=True,default=True)
+ confirmed = models.BooleanField(null=True,blank=True,default=True)
description = models.TextField(null=True,blank=True)
- start_date = models.DateTimeField(help_text='event start')
- end_date = models.DateTimeField(help_text='event end')
+ start_date = models.DateTimeField(help_text=_('event start'))
+ end_date = models.DateTimeField(help_text=_('event end'))
location = models.ForeignKey(Location,blank=True)
link = models.URLField(blank=True)
site = models.ManyToManyField(Site,blank=True)
calendar = models.Manager()
events = EventManager()
- status = models.CharField(max_length=1, choices=EVENT_STATUS_CHOICES,default=2)
- event_class = models.CharField(max_length=1, choices=EVENT_CLASS_CHOICES,default=1)
- pixie = models.ManyToManyField(User,blank=True,null=True,related_name='events')
+ pixie = models.ManyToManyField(User,verbose_name=_('mentor'),related_name='mentor',blank=True)
picture = models.FileField(upload_to='events/', null=True,blank=True)
- redes = models.ManyToManyField(Group, through='Network',null=True,blank=True, related_name='events')
+ redes = models.ManyToManyField(Group, through='Network',null=True,blank=True, related_name='masredes')
atendees = models.ManyToManyField(User, through='Attendance', null=True,blank=True)
+ save_as = True
+ recurrence = models.CharField(max_length=1, choices=RECURRENCE_CHOICES,default='0')
+ start_period = models.DateTimeField(null=True,blank=True,help_text=_('start period for the recurrence of the event'))
+ end_period = models.DateTimeField(null=True,blank=True,help_text=_('event period'))
def __unicode__(self):
return self.title
-
+ class Meta:
+ ordering = ['start_date']
+ @models.permalink
+ def get_absolute_url(self):
+ return ('infopoint.agenda.views.event', [str(self.id)])
class Network(models.Model):
"""
Relation between Groups and events
"""
- event = models.ForeignKey(Event,related_name='group')
+ event = models.ForeignKey(Event,related_name='groupevent')
group = models.ForeignKey(Group,related_name='networkevent')
creator = models.ForeignKey(User)
last_update = models.DateTimeField(auto_now=True)
def __unicode__(self):
- return self.group
- class META:
- unique_together = (("event", "group"),)
+ return self.group.name
+ class Meta:
+ unique_together = (('event', 'group'),)
class PendingTodoManager(models.Manager):
@@ -129,6 +175,25 @@ class PendingTodoManager(models.Manager):
return self.filter(done=False).order_by('due_date')
+
+class Wish(models.Model):
+ """
+ This is the list of things we need.
+ """
+ title = models.CharField(max_length=100)
+ public = models.BooleanField(null=True,blank=True,default=True,help_text=_('Is this todo public?'))
+ description = models.TextField(null=True,blank=True)
+ due_date = models.DateField(help_text=_('When do we need it'),null=True,blank=True)
+ done = models.BooleanField(blank=True,null=True)
+ network = models.ManyToManyField(Group, null=True,blank=True)
+ event = models.ManyToManyField(Event, null=True,blank=True, related_name='wishlist')
+ location = models.ManyToManyField(Location, null=True,blank=True, related_name='wishlistlocation')
+ creator = models.ForeignKey(User, related_name='wish_creator')
+ def __unicode__(self):
+ return self.title
+ class Meta:
+ verbose_name_plural = 'wishlist'
+
class Todo(models.Model):
"""
All the tasks that have to be done in the house, even if you dont know how to do them
@@ -136,7 +201,7 @@ class Todo(models.Model):
title = models.CharField(max_length=100)
public = models.BooleanField(null=True,blank=True,default=True)
description = models.TextField(null=True,blank=True)
- due_date = models.DateField(help_text='due date',null=True,blank=True)
+ due_date = models.DateField(help_text=_('Limit date'),null=True,blank=True)
done = models.BooleanField(blank=True,null=True)
todos = PendingTodoManager()
network = models.ManyToManyField(Group, null=True,blank=True)
@@ -155,9 +220,9 @@ class Attendance(models.Model):
"""
person = models.ForeignKey(User)
event = models.ForeignKey(Event)
- attendance = models.BooleanField(help_text="Confirm your assistance to the event",blank=True,null=True)
- update = models.DateTimeField(auto_now=True, verbose_name="Last update")
- reject_reason = models.CharField(max_length=64,blank=True,null=True, help_text="Let others know why you can't come to the event (optional)")
+ attendance = models.BooleanField(help_text=_('Confirm your assistance to the event'),blank=True,null=True)
+ update = models.DateTimeField(auto_now=True, verbose_name=_('Last update'))
+ reject_reason = models.CharField(max_length=64,blank=True,null=True, help_text=_("Let others know why you can't come to the event (optional)"))
class Meta:
unique_together = (('person', 'event'),)
@@ -187,7 +252,7 @@ class NetworkInline(admin.TabularInline):
model = Network
class AttendanceAdmin(admin.ModelAdmin):
- pass
+ list_display = ('event', 'person', 'attendance' )
admin.site.register(Attendance,AttendanceAdmin)
class LocationAdmin(admin.ModelAdmin):
@@ -201,19 +266,26 @@ class TodoAdmin(admin.ModelAdmin):
admin.site.register(Todo,TodoAdmin)
+class WishAdmin(admin.ModelAdmin):
+ list_display = ('title', 'public','due_date','creator', 'done')
+ date_hierarchy = 'due_date'
+
+admin.site.register(Wish,WishAdmin)
class EventAdmin(admin.ModelAdmin):
- list_display = ('title', 'description', 'location', 'start_date', 'public')
+ list_display = ('title', 'confirmed','description', 'location', 'start_date', 'public')
+ list_filter = ('location', 'public')
+ save_as = True
admin.site.register(Event,EventAdmin)
class NetworkAdmin(admin.ModelAdmin):
- pass
+ list_display = ('event', 'group')
admin.site.register(Network,NetworkAdmin)
class Billboard(models.Model):
title = models.CharField(max_length=100)
groups = models.ManyToManyField(Group, null=True,blank=True,related_name='cartel')
- refresh = models.IntegerField(help_text='In seconds',max_length=3)
+ refresh = models.IntegerField(help_text=_('In seconds'),max_length=3)
published = models.BooleanField(null=True,blank=True)
location = models.ManyToManyField(Location, null=True,blank=True, related_name='cartel')
timespan = models.CharField(max_length=1, choices=TIMESPAN_CHOICES)
@@ -261,6 +333,8 @@ databrowse.site.register(Comment)
databrowse.site.register(Billboard)
databrowse.site.register(ContentType)
databrowse.site.register(Group)
+databrowse.site.register(Network)
databrowse.site.register(Todo)
+databrowse.site.register(Wish)
databrowse.site.register(User)