summaryrefslogtreecommitdiffstats
path: root/agenda/billboardviews.py
blob: 50139ee9e0dbd6c68b993dc1b2d80d15749194a6 (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
# Create your views here.
from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
from infopoint.agenda.models import *
from datetime import date
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import Group,User
from django.contrib.comments.models import Comment
from infopoint.agenda.templatetags import *
from infopoint.agenda.models import Event, Attendance,Todo, Billboard
from infopoint.agenda.forms import TodoCreateForm, TodoForm
from django.contrib.formtools.preview import FormPreview
from django.views.generic import create_update
from django.template import RequestContext
from django.forms import ModelForm
import pydot

today = date.today()

def event_galaxy(request,object_id):
	event = Event.calendar.select_related().get(pk=object_id)
	event_redes = event.redes.all()
	event_attending =  event.atendees.all()
	comments = Comment.objects.filter(content_type=13,object_pk=object_id,is_public=True)
	other_events_on_this_location = event.location.event_set.all().filter(public=True,start_date__gte=today,end_date__gte=today)[:3]
	other_events_attended_by_atendees = Event.events.next_events().filter(public=True,start_date__gte=today,atendees__in=event.atendees.all()).distinct()
	other_events_with_this_event_groups = Event.events.next_events().filter(public=True,redes__in=event.redes.all()).distinct()

	map = pydot.Dot("ev"+str(event.id), graph_type="digraph",strict="True", suppress_disconnected="False",  fontname="Arial",ratio="compress",size="8,8",overlap="False", bgcolor="#ffffff6d", packmode="clust",URL="/",remincross="True" ) 
	map.add_node(pydot.Node("ev"+str(event.id),label=str(event.title)+" "+str(event.start_date.strftime('%d %b')),color='purple',fontname='Arial',style='filled',fontsize='30',shape='record' ,URL="/agenda/map/"+str(object_id)))
	map.add_node(pydot.Node("lo"+str(event.location.id),label=str(event.location.title),fontname='Arial',style='filled',fontsize='20',shape='record', fillcolor='#00ff005d',URL='/agenda/location/'+str(event.location.id)))
	map.add_edge(pydot.Edge("ev"+str(event.id),"lo"+str(event.location.id),style='rounded',len='1'))

	cluster_Groups = pydot.Subgraph(graph_name='cluster_Groups',label='Groups',fontname='Arial',style='rounded')
	todos = pydot.Subgraph(graph_name='cluster_Todos',label='Tasks',fontname='Arial',style='rounded')
	events = pydot.Subgraph(label='Events',shape='note',fillcolor='lightgrey',fontname='Arial',style='rounded')
	comments_graph = pydot.Subgraph(graph_name='Comments',label='Comments',style='rounded',fontname='Arial')
	for todo in event.todo.all()[:3]:
		todos.add_node(pydot.Node("td"+str(todo.id),label=todo.title,color='lightpink',fontname='Arial',style='filled',fontsize='10',shape='box'))
		events.add_edge(pydot.Edge("ev"+str(event.id),"td"+str(todo.id)))
	for todo in event.location.todolocation.all()[:3]:
		todos.add_node(pydot.Node("td"+str(todo.id),label=todo.title,color='lightpink',fontname='Arial',style='filled',fontsize='10',shape='box'))
		events.add_edge(pydot.Edge("lo"+str(event.location.id),"td"+str(todo.id)))
	for location_event in event.location.event_set.all().filter(public=True,end_date__gte=today).exclude(id=object_id,end_date__lte=today)[:3]:
		if (location_event.id != event.id):
			events.add_edge(pydot.Edge("lo"+str(event.location.id),"ev"+str(location_event.id)))
			events.add_node(pydot.Node("ev"+str(location_event.id),label=str(location_event.title)+"\\n"+str(location_event.start_date.strftime('%b %d')),color='green',fontname='Arial',style='filled',fontsize='10',shape='record',URL='/agenda/'+str(location_event.id)))
	for pixie in event.pixie.iterator():
		comments_graph.add_edge(pydot.Edge(pixie.username,"ev"+str(event.id),style='dotted'))
		comments_graph.add_node(pydot.Node(pixie.username,color='lightpink',fontname='Arial',style='filled',fontsize='10',shape='record'))
	for comment in comments:
		comments_graph.add_node(pydot.Node(unicode(comment.comment).encode('ascii'),color="lightpink",fontname='Arial',style='filled',fontsize='10',shape='note' ,URL="/agenda/"+object_id,rank="min"))
		comments_graph.add_edge(pydot.Edge(comment.user.username,comment.comment.encode('ascii', 'ignore'),style='dotted'))
		comments_graph.add_edge(pydot.Edge("ev"+str(event.id),comment.comment.encode('ascii', 'ignore'),style='rounded',rank='same'))

	for group in event_redes:
		cluster_Groups.add_node(pydot.Node("gr"+str(group.id),label=group.name,color='yellow',style="filled",fillcolor="#ff33cc5f" ,shape='record',group='groups',URL="/agenda/group/"+str(group.id), rank="5"))
		events.add_edge(pydot.Edge("gr"+str(group.id),"ev"+str(event.id),fontname='Arial',fontsize='8',rank="sink"))

	for related_event in other_events_with_this_event_groups.exclude(pk=object_id,public=False,end_date__lte=today)[:3]:
		if (related_event.id != event.id):
			events.add_node(pydot.Node("ev"+str(related_event.id),label=related_event.title+"\\n"+str(related_event.start_date.strftime('%b %d')),color='green',fontsize='12',style="filled",fillcolor="#00ff005f",fontname='Arial',shape='box',URL="/agenda/map/"+str(related_event.id),rank="same"))

		for group in related_event.redes.all():
			events.add_edge(pydot.Edge("gr"+str(group.id),"ev"+str(related_event.id),shape='point',fontsize='8',rank="sink"))
			cluster_Groups.add_node(pydot.Node("gr"+str(group.id),label=group.name,color='yellow',style="filled",fillcolor="#ff33cc5f" ,shape='record',group='groups',URL="/agenda/group/"+str(group.id), rank="5",fontname='Arial'))
		if (related_event.id != event.id):
			events.add_node(pydot.Node("ev"+str(related_event.id),label=related_event.title+"\\n"+str(related_event.start_date.strftime('%b %d')),color='green',fontsize='12',style="filled",fillcolor="#00ff005f",fontname='Arial',shape='box',URL="/agenda/map/"+str(related_event.id),rank="same"))
			events.add_edge(pydot.Edge("ev"+str(event.id),"ev"+str(related_event.id),fontname='Arial',fontsize='8',style='dotted'))
		for user in related_event.atendees.all().distinct():
			events.add_edge(pydot.Edge(user.username,"ev"+str(related_event.id),fontname='Arial',fontsize='8',rank="sink"))


	map.add_subgraph(comments_graph)
	map.add_subgraph(cluster_Groups)
	map.add_subgraph(todos)
	map.add_subgraph(events)
	map.write_png('/var/www/media/maps/event_'+object_id+'.png', prog='dot')
	map.write_dot('/var/www/media/maps/event_'+object_id+'.dot', prog='dot')
	map.write_cmap('/var/www/media/maps/event_'+object_id+'.map', prog='dot')
	map_coordinates = map.create_cmap( prog='dot')
	#return render_to_response('agenda/map_view.html', {'event': event,'map_coordinates':map_coordinates },context_instance=RequestContext(request))
	return HttpResponseRedirect('/agenda/'+object_id)

def event_galaxy_for_map(request,object_id):
	event = Event.calendar.select_related().get(pk=object_id)
	event_redes = event.redes.all()
	event_attending =  event.atendees.all()
	comments = Comment.objects.filter(content_type=14,object_pk=object_id)
	other_events_on_this_location = event.location.event_set.all().filter(public=True,end_date__gte=today)[:3]
	other_events_attended_by_atendees = Event.events.next_events().filter(atendees__in=event.atendees.all()).distinct()[:3]
	other_events_with_this_event_groups = Event.events.next_events().filter(public=True,end_date__gte=today,redes__in=event.redes.all()).distinct().exclude(id=object_id)


	map = pydot.Dot(event.id, graph_type="digraph",strict="True", suppress_disconnected="True",  fontname="Arial",size="10,6",overlap="True", ranksep="1",ratio="auto",bgcolor="#dddddd5d", packmode="group",URL="/" ) 
	map.add_node(pydot.Node(event.title,color='purple',fontname='Arial',style='filled',fontsize='20',shape='record' ,URL="/agenda/"+object_id))
	map.add_node(pydot.Node(event.location.title,color='purple',fontname='Arial',style='filled',fontsize='20',shape='record',URL='/agenda/location/'+str(event.location.id)))
	map.add_edge(pydot.Edge(event.title,event.location.title,fontname='Arial',label='location',len='1'))

	groups = pydot.Subgraph(graph_name='Groups', label='Groups',suppress_disconnected=False,style='filled',fillcolor='#00ff005d',fontname='Arial')
	events = pydot.Subgraph(graph_name='Events',label='Events',style='filled',shape='note',fillcolor='lightgrey',fontname='Arial')
	comments_graph = pydot.Subgraph(graph_name='Comments',label='Comments',fillcolor='lightgrey',fontname='Arial')
	for todo in event.location.todolocation.all()[:3]:
		events.add_node(pydot.Node("td"+str(todo.id),label=todo.title,color='#00ff005d',fontname='Arial',style='filled',fontsize='10',shape='box'))
		events.add_edge(pydot.Edge("lo"+str(event.location.location.id),"td"+str(todo.id),rank="sink"))
	for location_event in event.location.todolocation.all()[:3]:
		events.add_node(pydot.Node(location_event.title,color='lightpink',fontname='Arial',style='filled',fontsize='10',shape='record',URL='/agenda/map/'+str(location_event.id)))
		events.add_edge(pydot.Edge(event.location.title,location_event.title,fontname='Arial',fontsize='8',rank="sink"))
		
	for location_event in event.location.event_set.all().exclude(id=object_id,end_date__gte=today)[:3]:
		events.add_node(pydot.Node(location_event.title,color='green',fontname='Arial',style='filled',fontsize='10',shape='record',URL='/agenda/map/'+str(location_event.id)))
		events.add_edge(pydot.Edge(event.location.title,location_event.title,fontname='Arial',fontsize='8',rank="sink"))
	for pixie in event.pixie.iterator():
		comments_graph.add_edge(pydot.Edge(pixie.username,event.title.encode('ascii', 'ignore'),style='dotted',fontname='Arial',len='2'))
		comments_graph.add_node(pydot.Node(pixie.username,color='lightpink',fontname='Arial',style='filled',fontsize='10',shape='record'))
	for comment in comments:
		comments_graph.add_node(pydot.Node(unicode(comment.comment).encode('ascii'),color="lightpink",fontname='Arial',style='filled',fontsize='10',shape='note' ,URL="/agenda/map/"+object_id,rank="min"))
		comments_graph.add_edge(pydot.Edge(comment.user.username,comment.comment.encode('ascii', 'ignore'),style='dotted',fontname='Arial',label='is_author',len='3'))
		comments_graph.add_edge(pydot.Edge(event.title,comment.comment.encode('ascii', 'ignore'),fontname='Arial',label='location',len='1',rank='same'))

	for person in event_attending:
		events.add_node(pydot.Node(person.username,color='purple',fontsize='12',style="filled",fillcolor="#00ff005f",fontname='Arial',shape='note',URL="/agenda/map/user/"+str(person.id),rank="same"))
		events.add_edge(pydot.Edge(person.username,event.title,fontname='Arial',fontsize='8',rank="sink"))
	for group in event_redes:
		groups.add_node(pydot.Node(group.name,color='yellow',style="filled",fillcolor="#ff33cc5f" ,shape='record',group='groups',URL="/agenda/map/group/"+str(group.id), rank="5",fontname='Arial'))
		events.add_edge(pydot.Edge(event.title,group.name,fontname='Arial',fontsize='8',rank="sink"))

	for related_event in other_events_with_this_event_groups.exclude(pk=object_id,start_date__gte=datetime.now())[:3]:

		events.add_node(pydot.Node(related_event.title,color='green',fontsize='12',style="filled",fillcolor="#00ff005f",fontname='Arial',shape='box',URL="/agenda/map/"+str(related_event.id),rank="same"))

		for group in related_event.redes.all():
			events.add_edge(pydot.Edge(group.name,related_event.title,fontname='Arial',shape='point',fontsize='8',rank="sink"))
			groups.add_node(pydot.Node(group.name,color='yellow',style="filled",fillcolor="#ff33cc5f" ,shape='record',group='groups',URL="/agenda/map/group/"+str(group.id), rank="5",fontname='Arial'))

		events.add_node(pydot.Node(related_event.title,color='green',fontsize='12',style="filled",fillcolor="#00ff005f",fontname='Arial',shape='box',URL="/agenda/map/"+str(related_event.id),rank="same"))
		events.add_edge(pydot.Edge(event.title,related_event.title,fontname='Arial',fontsize='8',style='dotted'))
		for user in related_event.atendees.all().distinct():
			events.add_edge(pydot.Edge(user.username,related_event.title,fontname='Arial',label='goes to',fontsize='8',rank="sink"))


	map.add_subgraph(comments_graph)
	map.add_subgraph(groups)
	map.add_subgraph(events)
	map.write_png('/var/www/media/maps/event_'+object_id+'.png', prog='dot')
	map.write_cmap('/var/www/media/maps/event_'+object_id+'.map', prog='dot')
	map.write_dot('/var/www/media/maps/event_'+object_id+'.dot', prog='dot')
	map_coordinates = map.create_cmap( prog='dot')
	#return render_to_response('agenda/event_map_view.html', {'event': event,'map_coordinates':map_coordinates },context_instance=RequestContext(request))
	return HttpResponseRedirect('/agenda/'+object_id)

def event_galaxy2(request,object_id):
	event = Event.calendar.get(pk=object_id)
	event_redes = event.redes.all()
	event_attending =  event.atendees.all()
	other_events_attended_by_atendees = Event.events.next_events().filter(atendees__in=event.atendees.all()).distinct()
	other_events_with_this_event_groups = Event.events.next_events().filter(redes__in=event.redes.all()).distinct()

	map = pydot.Dot(event.title, graph_type='digraph',strict=True, suppress_disconnected=False,  fontname='Arial',size="14,17",overlap="False", ranksep='2',ratio='auto',bgcolor="#dddddd5d", packmode="clust",URL='http://infopoint/' ) 
	map.add_node(pydot.Node(event.title,color='purple',fontname='Arial',style='filled',fontsize='20',shape='record' ,URL="http://infopoint/agenda/map/"+str(object_id)))
	map.add_node(pydot.Node(event.location.title,color='purple',fontname='Arial',style='filled',fontsize='20',shape='record',URL="http://infopoint/agenda/map/location/"+str(event.location.id)))
	map.add_edge(pydot.Edge(event.title,event.location.title))

	groups = pydot.Subgraph(graph_name='Groups', suppress_disconnected=False,style='filled',fillcolor='#00ff005d',fontname='Arial')
	events = pydot.Subgraph(graph_name='Events',style='filled',shape='note',fillcolor='lightgrey',fontname='Arial')


	for related_event in other_events_with_this_event_groups:
		for group in related_event.redes.all():
			events.add_edge(pydot.Edge(group.name,related_event.title,fontname='Arial',shape='point',fontsize='8',rank="sink"))

	for a in event_redes.distinct():
		groups.add_node(pydot.Node(a.name,color='yellow',style="filled",fillcolor="#ff33cc5f" ,shape='record',group='groups',URL="http://infopoint/agenda/map/group/"+str(a.id), rank="2",fontname='Arial'))
		groups.add_edge(pydot.Edge(event.title,a.name,style='dotted',fontname='Arial'))
		for group in event_redes.iterator():
			for related_event in group.networkevent.all().distinct():
				events.add_node(pydot.Node(str(related_event.event),color='green',fontsize='8',style="filled",fillcolor="#00ff005f",fontname='Arial',shape='record',URL='/agenda/map/'+str(related_event.event_id),rank="min"))
	
	for a in event_attending:
		events.add_node(pydot.Node(a.username,color='yellow',style="filled",fillcolor="#00ffff5f" ,shape='note',group='users',rank="sink",fontname='Arial'))
		events.add_edge(pydot.Edge(event.title,a.username,fontname='Arial',shape='point',fontsize='8',rank="sink"))	

	map.add_subgraph(groups)
	map.add_subgraph(events)
	map.write_png('/var/www/media/maps/event_'+object_id+'.png', prog='dot')
	map.write_dot('/var/www/media/maps/event_'+str(object_id)+'.dot', prog='dot')
	map_coordinates = map.create_cmap( prog='dot')
	map.write_imap('/var/www/media/maps/event_'+str(object_id)+'.map', prog='dot')
	return render_to_response('agenda/billboard_still.html', {'event': event,'map_coordinates':map_coordinates },context_instance=RequestContext(request))

def one_still_event(request,object_id,billboard_id):
	event = Event.calendar.get(pk=object_id)
	style = Billboard.objects.get(pk=billboard_id)
	return render_to_response('agenda/billboard_still.html', {'event': event, 'style': style },context_instance=RequestContext(request))


def billboard(request,billboard_id):
	style = Billboard.objects.get(pk=billboard_id)
	list = Event.events.filter(location__in=style.location.all())|Event.calendar.filter(redes__in=style.groups.all())
	if style.timespan=='1':
		list = Event.events.next_events().filter(location__in=style.location.all()).distinct()|Event.events.next_events().filter(redes__in=style.groups.all()).distinct()
	if style.timespan=='2':
		list = Event.events.past_events().filter(location__in=style.location.all()).distinct()|Event.events.past_events().filter(redes__in=style.groups.all()).distinct()
	if style.timespan=='3':
		list = Event.events.all().filter(location__in=style.location.all()).distinct()|Event.events.all().filter(redes__in=style.groups.all()).distinct()
	if style.timespan=='4':
		list = Event.events.today_events().filter(location__in=style.location.all()).distinct()|Event.events.today_events().filter(redes__in=style.groups.all()).distinct()
	event = list.order_by('?')[:1]
	return render_to_response('agenda/billboard.html', { 'event': event,'list': list, 'style': style },context_instance=RequestContext(request))