summaryrefslogtreecommitdiffstats
path: root/agenda/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'agenda/models.py')
-rwxr-xr-xagenda/models.py266
1 files changed, 266 insertions, 0 deletions
diff --git a/agenda/models.py b/agenda/models.py
new file mode 100755
index 0000000..634f583
--- /dev/null
+++ b/agenda/models.py
@@ -0,0 +1,266 @@
+#!/usr/bin/python
+# -*- coding: utf -*-
+
+from django.db import models
+from django.conf import settings
+from infopoint.agenda import *
+from infopoint.sites.models import Site
+import datetime
+from time import gmtime, strftime
+from django.contrib.contenttypes import generic
+from django.contrib import databrowse
+from django.contrib.auth.models import User,Group
+from django.contrib.comments.models import Comment,ContentType,User
+from django import forms
+from django.forms import ModelForm
+from django.template.loader import render_to_string
+from datetime import datetime
+
+from django.contrib import admin
+
+# Create your models here.
+
+TIMESPAN_CHOICES = (
+ ('1', 'Future events'),
+ ('2', 'Past events'),
+ ('3', 'All events'),
+ ('4', 'Today'),
+)
+
+
+EVENT_STATUS_CHOICES = (
+ ('1', 'TENTATIVE'),
+ ('2', 'CONFIRMED'),
+ ('3', 'NEEDS ACTION'),
+ ('4', 'CANCELLED'),
+)
+EVENT_CLASS_CHOICES = (
+ ('1', 'PUBLIC'),
+ ('2', 'PRIVATE'),
+ ('3', 'CONFIDENTIAL'),
+)
+
+class Location(models.Model):
+ """
+ This is the class for the different spaces we will handle.
+ the more information we get here, the less we will have to answer
+ later
+ """
+ title = models.CharField(max_length=50)
+ description = models.TextField()
+ 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)
+ is_in = models.ForeignKey('self',null=True,blank=True)
+ places = models.Manager()
+ # inlines = ('AgendaInline',)
+ def __unicode__(self):
+ return self.title
+
+ def colored_location(self):
+ return '<span style="color: #%s;">%s</span>' % (self.color, self.title)
+ colored_location.allow_tags = True
+
+
+class EventManager(models.Manager):
+ def past_events(self):
+ return self.exclude(start_date__gte=datetime.now())
+
+ def next_events(self):
+ return self.filter(start_date__gte=datetime.now())
+
+ def missing_pixies(self):
+ return self.filter(start_date__gte=datetime.now()).filter(pixie__isnull=True)
+ def today_events(self):
+ today_start = strftime("%Y-%m-%d 0:0:0", gmtime())
+ today_end = strftime("%Y-%m-%d 23:59:59", gmtime())
+ return self.exclude(start_date__gte=today_end).filter(end_date__gte=today_start)
+
+
+
+class Event(models.Model):
+ """
+ The Main Organizers class, where all the data reunites again.
+ it has some dificulties, anyway. But is a pretty table!
+ Fields:
+ Event(id, title, start_date, end_date, priority, location_id, link)
+
+ """
+ title = models.CharField(max_length=100)
+ public = 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')
+ 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')
+ picture = models.FileField(upload_to='events/', null=True,blank=True)
+ redes = models.ManyToManyField(Group, through='Network',null=True,blank=True, related_name='events')
+ atendees = models.ManyToManyField(User, through='Attendance', null=True,blank=True)
+ def __unicode__(self):
+ return self.title
+
+
+class Network(models.Model):
+ """
+ Relation between Groups and events
+ """
+ event = models.ForeignKey(Event,related_name='group')
+ 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"),)
+
+
+class PendingTodoManager(models.Manager):
+ def completed_todos(self):
+ return self.filter(done=True)
+
+ def pending_todos(self):
+ return self.filter(done=False).order_by('due_date')
+
+
+class Todo(models.Model):
+ """
+ All the tasks that have to be done in the house, even if you dont know how to do them
+ """
+ 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)
+ done = models.BooleanField(blank=True,null=True)
+ todos = PendingTodoManager()
+ network = models.ManyToManyField(Group, null=True,blank=True)
+ event = models.ManyToManyField(Event, null=True,blank=True, related_name='todo')
+ location = models.ManyToManyField(Location, null=True,blank=True, related_name='todolocation')
+ creator = models.ForeignKey(User, related_name='todocreator')
+ def __unicode__(self):
+ return self.title
+
+
+class Attendance(models.Model):
+ """
+ This object links the user table and the events table,
+ to check assistance to events
+ Attendance(id, person_id, event_id, attendance, update, reject_reason)
+ """
+ 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)")
+ class Meta:
+ unique_together = (('person', 'event'),)
+
+
+ def __unicode__(self):
+ return self.person
+
+
+
+class LocationInline(admin.TabularInline):
+ model = Location
+
+class TodoInline(admin.TabularInline):
+ model = Todo
+
+class EventInline(admin.TabularInline):
+ model = Event
+ extra = 1
+
+class GroupInline(admin.TabularInline):
+ model = Group
+
+class AttendanceInline(admin.TabularInline):
+ model = Attendance
+
+class NetworkInline(admin.TabularInline):
+ model = Network
+
+class AttendanceAdmin(admin.ModelAdmin):
+ pass
+admin.site.register(Attendance,AttendanceAdmin)
+
+class LocationAdmin(admin.ModelAdmin):
+ list_display = ('title', 'description', 'size' , 'picture')
+ inlines = [EventInline]
+admin.site.register(Location,LocationAdmin)
+
+class TodoAdmin(admin.ModelAdmin):
+ list_display = ('title', 'public','due_date','creator', 'done')
+ date_hierarchy = 'due_date'
+
+admin.site.register(Todo,TodoAdmin)
+
+
+class EventAdmin(admin.ModelAdmin):
+ list_display = ('title', 'description', 'location', 'start_date', 'public')
+admin.site.register(Event,EventAdmin)
+
+class NetworkAdmin(admin.ModelAdmin):
+ pass
+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)
+ 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)
+ color1 = models.CharField(max_length=6)
+ color2 = models.CharField(max_length=6)
+ color3 = models.CharField(max_length=6)
+ color4 = models.CharField(max_length=6)
+ csstitle = models.TextField(max_length=500, help_text="decide the style of the title here",blank=True,default="padding: 30px;font-family: verdana, arial, sans-serif;text-transform: capitalize;BORder: 10px dotted;")
+ cssdate = models.TextField(max_length=500, help_text="decide the style of the date here",blank=True,default="padding: 30px;")
+ csslocation = models.TextField(max_length=500, help_text="decide the style of the location here",blank=True,default="padding: 30px;text-transform: capitalize;")
+ cssdescription = models.TextField(max_length=500, help_text="decide the style of the description here",blank=True)
+
+ def __unicode__(self):
+ return self.title
+
+class BillboardInline(admin.TabularInline):
+ model = Billboard
+
+class BillboardAdmin(admin.ModelAdmin):
+ list_display = ('title', 'refresh','timespan','published')
+ fieldsets = (
+ (None, {
+ 'fields': (('title', 'refresh'), ('published'))
+ }),
+ ('content', {
+ 'fields': (('groups', 'location'), ('timespan'))
+ }),
+ ('css', {
+ 'classes': ('collapse','small'),
+ 'fields': (('csstitle', 'cssdescription'),('cssdate', 'csslocation'))
+ }),
+ ('colors', {
+ 'fields': (('color1', 'color2'), ('color3', 'color4'))
+ }),
+
+ )
+
+admin.site.register(Billboard,BillboardAdmin)
+
+
+
+databrowse.site.register(Event)
+databrowse.site.register(Location)
+databrowse.site.register(Comment)
+databrowse.site.register(Billboard)
+databrowse.site.register(ContentType)
+databrowse.site.register(Group)
+databrowse.site.register(Todo)
+databrowse.site.register(User)
+