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 # Copyright 2013, UPMC Sorbonne Universités / LIP6
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.
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
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.
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, the_user
33 from unfold.loginrequired import FreeAccessView
34 from unfold.page import Page
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"
44 def get_context_data(self, **kwargs):
46 page = Page(self.request)
48 plugin = MyPlugin(page = page)
49 context = super(MyPluginView, self).get_context_data(**kwargs)
50 context['unfold_main'] = plugin.render(self.request)
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('myplugin', self.request)
56 # so we can sho who is logged
57 context['username'] = the_user(self.request)
59 prelude_env = page.prelude_env()
60 context.update(prelude_env)
65 class MadDashView(FreeAccessView):
66 template_name = "view-unfold1.html"
68 def get_context_data(self, **kwargs):
69 page = Page(self.request)
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')
76 'hrn': 'random_string',
77 'src_hostname': 'random_string',
78 'dst_hostname': 'random_string',
81 page.generate_records(fake_query, generators, 5)
82 page.generate_records(fake_query_all, generators, 20)
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('maddash', self.request)
89 context['username'] = the_user(self.request)
91 prelude_env = page.prelude_env()
92 context.update(prelude_env)