summaryrefslogtreecommitdiffstats
path: root/agenda/models.py
blob: 634f5833e8ea3319e033b20c82acf8d7aff75c58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
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)