ManageUser: Display OK. Edit- ToDo
[myslice.git] / sandbox / views.py
1 # -*- coding: utf-8 -*-
2 #
3 # portal/views.py: views for the portal application
4 # This file is part of the Manifold project.
5 #
6 # Authors:
7 #   Jordan AugĂ© <jordan.auge@lip6.fr>
8 #   Mohammed Yasin Rahman <mohammed-yasin.rahman@lip6.fr>
9 # Copyright 2013, UPMC Sorbonne UniversitĂ©s / LIP6
10 #
11 # This program is free software; you can redistribute it and/or modify it under
12 # the terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 3, or (at your option) any later version.
14
15 # This program is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18 # details.
19
20 # You should have received a copy of the GNU General Public License along with
21 # this program; see the file COPYING.  If not, write to the Free Software
22 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 import json
25
26 from django.http                import HttpResponseRedirect, HttpResponse
27 from django.shortcuts           import render
28 from django.template.loader     import render_to_string
29 from manifold.core.query        import Query
30 from plugins.myplugin           import MyPlugin
31 from plugins.maddash            import MadDash
32 from ui.topmenu                 import topmenu_items_live, the_user
33 from unfold.loginrequired       import FreeAccessView
34 from unfold.page                import Page
35
36 # NOTE
37 # initially all the portal views were defined in this single file
38 # all the other ones have now migrated into separate classes/files for more convenience
39 # I'm leaving these ones here for now as I could not exactly figure what the purpose was 
40 # (i.e. what the correct name should be, as presviewview was a bit cryptic)
41 class MyPluginView(FreeAccessView):
42     template_name = "view-unfold1.html"
43
44     def get_context_data(self, **kwargs):
45
46         page = Page(self.request)
47
48         plugin = MyPlugin(page = page)
49         context = super(MyPluginView, self).get_context_data(**kwargs)
50         context['unfold_main'] = plugin.render(self.request)
51
52         # more general variables expected in the template
53         context['title'] = 'Sandbox for MyPlugin plugin'
54         # the menu items on the top
55         context['topmenu_items'] = topmenu_items_live('myplugin', page)
56         # so we can sho who is logged
57         context['username'] = the_user(self.request)
58
59         prelude_env = page.prelude_env()
60         context.update(prelude_env)
61
62         return context
63
64
65 class MadDashView(FreeAccessView):
66     template_name = "view-unfold1.html"
67
68     def get_context_data(self, **kwargs):
69         page = Page(self.request)
70
71         # This will simulate fake records in order to test the plugin
72         fake_query = Query.get('ping').select('hrn', 'src_hostname', 'dst_hostname', 'delay')
73         fake_query_all = Query.get('ping').select('hrn', 'src_hostname', 'dst_hostname', 'delay')
74
75         generators = {
76             'hrn': 'random_string',
77             'src_hostname': 'random_string',
78             'dst_hostname': 'random_string',
79             'delay': 'random_int'
80         }
81         page.generate_records(fake_query, generators, 5)
82         page.generate_records(fake_query_all, generators, 20)
83
84         plugin = MadDash(query = fake_query, query_all = fake_query_all, page = page)
85         context = super(MadDashView, self).get_context_data(**kwargs)
86         context['unfold_main'] = plugin.render(self.request)
87         context['title'] = 'Sandbox for MadDash plugin'
88         context['topmenu_items'] = topmenu_items_live ('maddash', page)
89         context['username'] = the_user(self.request)
90
91         prelude_env = page.prelude_env()
92         context.update(prelude_env)
93
94         return context
95