1 # -*- coding: utf-8 -*-
3 # portal/views.py: views for the portal application
4 # This file is part of the Manifold project.
7 # Jordan Augé <jordan.auge@lip6.fr>
8 # Mohammed Yasin Rahman <mohammed-yasin.rahman@lip6.fr>
9 # Loic Baron <loic.baron@lip6.fr>
10 # Copyright 2013, UPMC Sorbonne Universités / LIP6
12 # This program is free software; you can redistribute it and/or modify it under
13 # the terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 3, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful, but WITHOUT
17 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 # You should have received a copy of the GNU General Public License along with
22 # this program; see the file COPYING. If not, write to the Free Software
23 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 from django.http import HttpResponseRedirect, HttpResponse
28 from django.shortcuts import render
29 from django.template.loader import render_to_string
31 from unfold.loginrequired import FreeAccessView
32 from ui.topmenu import topmenu_items_live, the_user
34 from portal.event import Event
35 # presview is put in observation for now
36 #from plugins.pres_view import PresView
37 from plugins.raw import Raw
39 # these seem totally unused for now
40 #from portal.util import RegistrationView, ActivationView
42 from portal.models import PendingUser, PendingSlice
43 from portal.actions import get_requests
44 from manifoldapi.manifoldapi import execute_query
45 from manifold.core.query import Query
46 from unfold.page import Page
49 # initially all the portal views were defined in this single file
50 # all the other ones have now migrated into separate classes/files for more convenience
51 # I'm leaving these ones here for now as I could not exactly figure what the purpose was
52 # (i.e. what the correct name should be, as presviewview was a bit cryptic)
53 class PresViewView(FreeAccessView):
54 template_name = "view-unfold1.html"
56 def get_context_data(self, **kwargs):
58 page = Page(self.request)
60 # pres_view = PresView(page = page)
61 pres_view = Raw(page = page,html="<h1>PresView needs to be integrated</h1>")
63 context = super(PresViewView, self).get_context_data(**kwargs)
65 #context['ALL_STATIC'] = "all_static"
66 context['unfold_main'] = pres_view.render(self.request)
68 # XXX This is repeated in all pages
69 # more general variables expected in the template
70 context['title'] = 'Test view that combines various plugins'
71 # the menu items on the top
72 context['topmenu_items'] = topmenu_items_live('PresView', page)
73 # so we can sho who is logged
74 context['username'] = the_user(self.request)
76 prelude_env = page.prelude_env()
77 context.update(prelude_env)
81 def json_me(config_file,type):
83 for ligne in config_file:
84 if not ligne.startswith('#'):
85 args = ligne.split(';')
86 json_answer += str('{ "name": "' + args[0] + '" ,"id":"' + args[1] + '" ,"descriptif":"' + args[2]+'"')
88 json_answer += str(',"contraints":')
90 json_answer += str('""')
92 json_answer += str(args[3])
93 json_answer += str('},')
94 return json_answer[:-1]
98 STATIC = '%s/config_method_static' % DIR
99 DYNAMIC = '%s/config_method_dynamic' % DIR
100 ANIMATION = '%s/config_method_animation' % DIR
102 def pres_view_methods(request, type):
106 elif type =="static":
107 config = open(STATIC, "r")
108 json_answer = str('{ "options": [')
109 json_answer += str(json_me(config,"static"))
110 json_answer += str('] }')
112 elif type =="dynamic":
113 config = open(DYNAMIC, "r")
114 json_answer = str('{ "options": [')
115 json_answer += str(json_me(config,"dynamic"))
116 json_answer += str('] }')
118 elif type =="animation":
119 config = open(ANIMATION, "r")
120 json_answer = str('{ "options": [')
121 json_answer += str(json_me(config,"animation"))
122 json_answer += str('] }')
125 config = open(STATIC, "r")
126 json_answer = str('{ "static": [')
127 json_answer += str(json_me(config,"static"))
128 json_answer += str('],')
129 json_answer += str('"dynamic": [')
131 config = open(DYNAMIC, "r")
132 json_answer += str(json_me(config,"dynamic"))
133 json_answer += str('],')
134 json_answer += str('"animation": [')
136 config = open(ANIMATION, "r")
137 json_answer += str(json_me(config,"animation"))
138 json_answer += str('] }')
142 return HttpResponse (json_answer, mimetype="application/json")
144 def pres_view_animation(request, constraints, id):
146 # sites crees depuis 2008
147 # static.py?contraints=']date_created':1262325600&id='name_id"'
149 # method = request.getvalue('method') #ex : GetSites
150 #constraints = "']date_created':1262325600"
156 # method = 'GetSites'#request.getvalue('method') #ex : GetSites
157 # constraints = {}#request.getvalue('constraints') // nul = {}
158 # response_field = "'site_id','name','date_created'"#request.getvalue('response_field')
160 config_file = open(ANIMATION, "r")
161 for ligne in config_file:
162 if not ligne.startswith('#'):
163 ligne = ligne.split('\n')
164 first = ligne[0].split(';')
165 if (str(first[1]) == str(id)):
169 #Les print_method, print_option sont definis par le client (js)
170 #Les animations acceptent que les connexions anonymous
171 # args = "postmsg;animation;;;anonymous;https://www.planet-lab.eu/PLCAPI/;"
172 args = ";;"+str(save[8])+";"+str(save[9])+";anonymous;"+str(save[5])+";"+str(save[6])+";{"+str(constraints)+"};"+str(save[7])+";"
175 #Creation d'un objet event
179 "print_options": event.print_options,
180 "print_method": event.print_method,
181 "message": event.data
186 json_answer = json.dumps(cmd)
187 return HttpResponse (json_answer, mimetype="application/json")
189 def pres_view_static(request, constraints, id):
190 #constraints = "']date_created':1262325600"
193 # method = 'GetSites'#request.getvalue('method') #ex : GetSites
194 # constraints = {}#request.getvalue('constraints') // nul = {}
195 # response_field = "'site_id','name','date_created'"#request.getvalue('response_field')
197 config_file = open(STATIC, "r")
198 for ligne in config_file:
199 if not ligne.startswith('#'):
200 ligne = ligne.split('\n')
201 first = ligne[0].split(';')
202 if (str(first[1]) == str(id)):
206 #Les print_method, print_option sont definis par le client (js)
207 #Les animations acceptent que les connexions anonymous
208 # args = "postmsg;animation;;;anonymous;https://www.planet-lab.eu/PLCAPI/;"
209 args = ";;"+str(save[8])+";"+str(save[9])+";anonymous;"+str(save[5])+";"+str(save[6])+";{"+str(constraints)+"};"+str(save[7])+";"
212 #Creation d'un objet event
216 "print_options": event.print_options,
217 "print_method": event.print_method,
218 "message": event.data
223 json_answer = json.dumps(cmd)
224 return HttpResponse (json_answer, mimetype="application/json")