From 18710ca42c0eb6c72ab5ce2449a9676dd6d491bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jordan=20Aug=C3=A9?= Date: Sun, 7 Jul 2013 04:09:37 +0200 Subject: [PATCH] portal.dashboard: working --- myslice/settings.py | 15 +++++-- myslice/viewutils.py | 2 +- plugins/lists/simplelist.js | 81 ++++++++++++++++++++++++------------ portal/tests/models.py | 20 +++++---- portal/urls.py | 3 +- portal/views.py | 61 +++++++++++++++++++++++---- unfold/plugin.py | 9 ++-- unfold/templates/plugin.html | 2 + 8 files changed, 140 insertions(+), 53 deletions(-) diff --git a/myslice/settings.py b/myslice/settings.py index 7ac0f1b6..c9b30058 100644 --- a/myslice/settings.py +++ b/myslice/settings.py @@ -24,15 +24,22 @@ if not ROOT: #################### ADMINS = ( - # ('Your Name', 'your_email@example.com'), + # ('your_name', 'your_email@test.com'), ) MANAGERS = ADMINS # Mail configuration -#EMAIL_HOST = 'tibre.lip6.fr' -#EMAIL_PORT = 465 -DEFAULT_FROM_EMAIL = "support@myslice.info" +#DEFAULT_FROM_EMAIL = "root@theseus.ipv6.lip6.fr" +#EMAIL_HOST_PASSWORD = "mypassword" + +EMAIL_HOST = "localhost" +EMAIL_PORT = 25 +EMAIL_USE_TLS = False + + + + DATABASES = { 'default': { diff --git a/myslice/viewutils.py b/myslice/viewutils.py index 37a7d636..2b5ab862 100644 --- a/myslice/viewutils.py +++ b/myslice/viewutils.py @@ -6,7 +6,7 @@ standard_topmenu_items = [ # { 'label':'Tab', 'href': '/tab/'}, # { 'label':'Scroll', 'href': '/scroll/'}, { 'label':'One Plugin', 'href': '/plugin/'}, - { 'label':'Dashboard', 'href': '/dashboard/'}, + { 'label':'Dashboard', 'href': '/portal/dashboard/'}, { 'label':'Slice', 'href': '/slice/'}, ] diff --git a/plugins/lists/simplelist.js b/plugins/lists/simplelist.js index 11f812b9..9cd51297 100644 --- a/plugins/lists/simplelist.js +++ b/plugins/lists/simplelist.js @@ -50,41 +50,50 @@ // complexity here is mostly because a datatables-enabled table cannot // be updated in a "normal" way using .html() function update_plugin(e, rows) { - // e.data is what we passed in second argument to subscribe - // so here it is the jquery object attached to the plugin
- var $plugindiv=e.data; - // locate the element; with datatables in the way, - // this might not be a direct son of the div-plugin - var $table=$plugindiv.find("table.simplelist").first(); - // also we may or may not have a header - var $tbody=$table.find("tbody.simplelist").first(); - var use_datatables = $table.hasClass("with-datatables"); - if (debug) messages.debug($plugindiv.attr('id') + " udt= " + use_datatables); + // e.data is what we passed in second argument to subscribe + // so here it is the jquery object attached to the plugin
+ var $plugindiv = e.data; + // locate the
element; with datatables in the way, + // this might not be a direct son of the div-plugin + var $table = $plugindiv.find("table.simplelist").first(); + // also we may or may not have a header + var $tbody = $table.find("tbody.simplelist").first(); + var use_datatables = $table.hasClass("with-datatables"); + if (debug) + messages.debug($plugindiv.attr('id') + " udt= " + use_datatables); // clear the spinning wheel: look up an ancestor that has the need-spin class // do this before we might return - $plugindiv.closest('.need-spin').spin(false); + $plugindiv.closest('.need-spin').spin(false); if (rows.length == 0) { - if (use_datatables) datatables_set_message ($table, $tbody, unfold.warning("No result")); - else regular_set_message ($table, $tbody, unfold.warning("No result")); + if (use_datatables) + datatables_set_message ($table, $tbody, unfold.warning("No result")); + else + regular_set_message ($table, $tbody, unfold.warning("No result")); return; } + if (typeof rows[0].error != 'undefined') { - var error="ERROR: " + rows[0].error; - if (use_datatables) datatables_set_message ($table, $tbody, unfold.error(error)); - else regular_set_message ($table, $tbody, unfold.error(error)); + var error="ERROR: " + rows[0].error; + if (use_datatables) + datatables_set_message ($table, $tbody, unfold.error(error)); + else + regular_set_message ($table, $tbody, unfold.error(error)); return; } + var options = $plugindiv.data().SimpleList; - if (use_datatables) datatables_update_table ($table,$tbody,rows,options.key); - else regular_update_table ($table,$tbody,rows,options.key); + if (use_datatables) + datatables_update_table($table, $tbody, rows, options.key); + else + regular_update_table($table, $tbody, rows, options.key); - } + } // hard-wire a separate presentation depending on the key being used.... function cell(key, value) { - if (key == 'slice_hrn') { + if (key == 'slice.slice_hrn') { return "" + value + ""; } else if (key == 'network_hrn') { return "" + value ; @@ -98,15 +107,31 @@ } function regular_update_table ($table, $tbody, rows, key) { - if (debug) messages.debug('regular_update_table ' + rows.length + " rows"); - var html=$.map(rows, function (row) { return html_row ( cell (key, row[key])); }).join(); - $tbody.html(html); + if (debug) + messages.debug('regular_update_table ' + rows.length + " rows"); + var html=$.map(rows, function (row) { + value = row; + $.each(key.split('.'), function(i, k) { + if ($.isArray(value)) { + value = $.map(value, function(val, i) { return val[k]}); + } else { + value = value[k]; + } + }); + if ($.isArray(value)) { + x = $.map(value, function(val, i) { return html_row ( cell (key, val)); }); + return x; + } else { + return html_row ( cell (key, value)); + } + }).join(); + $tbody.html(html); } function datatables_set_message ($table, $tbody, message) { - $table.dataTable().fnClearTable(); - $table.dataTable().fnAddData( [ message ] ); - $table.dataTable().fnDraw(); + $table.dataTable().fnClearTable(); + $table.dataTable().fnAddData( [ message ] ); + $table.dataTable().fnDraw(); } function datatables_update_table ($table, $tbody, rows, key) { @@ -119,6 +144,8 @@ $table.dataTable().fnDraw(); } - function html_row (cell) { return ""; } + function html_row (cell) { + return ""; + } })( jQuery ); diff --git a/portal/tests/models.py b/portal/tests/models.py index 3b08f2d5..bac20f25 100755 --- a/portal/tests/models.py +++ b/portal/tests/models.py @@ -1,16 +1,20 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# DJANGO_SETTINGS_MODULE="myslice.settings" ./test-send-email.py +#DJANGO_SETTINGS_MODULE="repos.myslice-django.myslice.settings" ./test-send-email.py # -from django.core import mail +#from django.core import mail from django.test import TestCase +from django.conf import settings +from django.core.mail import EmailMessage +import myslice.settings class EmailTest(TestCase): def test_send_email(self): - mail.send_mail('Subject here', 'Here is the message.', - 'support@myslice.info', ['jordan.auge@lip6.fr', 'jordan.auge@free.fr'], - fail_silently=False) - print mail.outbox - self.assertEquals(len(mail.outbox), 1) - self.assertEquals(mail.outbox[0].subject, 'Subject here') + email = EmailMessage('Hello', 'World', to=['jordan.auge@lip6.fr']) + email.send() + + + + + diff --git a/portal/urls.py b/portal/urls.py index cd789b9a..53d4b7c2 100644 --- a/portal/urls.py +++ b/portal/urls.py @@ -22,7 +22,7 @@ from django.conf.urls import patterns, include, url from portal import views -from portal.views import UserRegisterView, UserValidateView +from portal.views import UserRegisterView, UserValidateView, DashboardView from portal.util import TemplateView # DEPRECATED #named_register_forms = ( @@ -41,6 +41,7 @@ urlpatterns = patterns('', name='user_register_complete'), # User validation url(r'^user/validate/?$', UserValidateView.as_view(), name='user_validate'), + url(r'^dashboard/?$', DashboardView.as_view(), name='dashboard'), # Slice request #url(r'^slice/request/?$', views.slice_request, name='slice_request'), # Slice confirmation diff --git a/portal/views.py b/portal/views.py index 09741d20..f213986b 100644 --- a/portal/views.py +++ b/portal/views.py @@ -20,15 +20,58 @@ # this program; see the file COPYING. If not, write to the Free Software # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -from django.conf import settings -from django.contrib.sites.models import RequestSite -from django.contrib.sites.models import Site - -from django.shortcuts import render -from portal.forms import UserRegisterForm, SliceRequestForm -from portal.util import RegistrationView, ActivationView -from portal.models import PendingUser, PendingSlice -from portal import signals +from django.conf import settings +from django.contrib.sites.models import Site, RequestSite +from django.views.generic import View +from django.views.generic.base import TemplateView +from django.shortcuts import render +from plugins.lists.simplelist import SimpleList +from portal import signals +from portal.forms import UserRegisterForm, SliceRequestForm +from portal.util import RegistrationView, ActivationView +from portal.models import PendingUser, PendingSlice +from manifold.core.query import Query +from unfold.page import Page + +class DashboardView(TemplateView): + template_name = "dashboard.html" + + def get_context_data(self, **kwargs): + user_hrn = 'ple.upmc.jordan_auge' + + page = Page(self.request) + + # Slow... + #slice_query = Query().get('slice').filter_by('user.user_hrn', 'contains', user_hrn).select('slice_hrn') + slice_query = Query().get('user').filter_by('user_hrn', '==', user_hrn).select('slice.slice_hrn') + auth_query = Query().get('network').select('network_hrn') + page.enqueue_query(slice_query) + page.enqueue_query(auth_query) + + page.expose_queries() + + slicelist = SimpleList( + title = None, + page = page, + key = 'slice.slice_hrn', + query = slice_query, + ) + + authlist = SimpleList( + title = None, + page = page, + key = 'network_hrn', + query = auth_query, + ) + + context = super(DashboardView, self).get_context_data(**kwargs) + context['person'] = self.request.user + context['networks'] = authlist.render(self.request) + context['slices'] = slicelist.render(self.request) + + context.update(page.prelude_env()) + + return context class UserRegisterView(RegistrationView): """ diff --git a/unfold/plugin.py b/unfold/plugin.py index 4e97d678..e15736de 100644 --- a/unfold/plugin.py +++ b/unfold/plugin.py @@ -22,6 +22,8 @@ DEBUG= False # decorator to deflect calls on Plugin to its Prelude through self.page.prelude def to_prelude (method): def actual (self, *args, **kwds): + if not self.page: # jordan + return None prelude_method=Prelude.__dict__[method.__name__] return prelude_method(self.page.prelude,*args, **kwds) return actual @@ -76,7 +78,7 @@ class Plugin: if not domid: domid=self.newdomid() self.domid=domid # title is shown when togglable - if not title: title="Plugin title for %s"%domid + #if not title: title="Plugin title for %s"%domid self.title=title self.classname=self._py_classname() self.plugin_classname=self._js_classname() @@ -95,7 +97,8 @@ class Plugin: for (k,v) in self.__dict__.items(): print "dbg %s:%s"%(k,v) print "%s init dbg .... END"%self.classname # do this only once the structure is fine - self.page.record_plugin(self) + if self.page: # I assume we can have a None page (Jordan) + self.page.record_plugin(self) def __repr__ (self): return "[%s]:%s"%(self.classname,self.domid) @@ -258,7 +261,7 @@ class Plugin: def template_file (self): return "undefined_template" def template_env (self, request): return {} - def default_togglable (self): return True + def default_togglable (self): return False def default_toggled (self): return 'persistent' # # tell the framework about requirements (for the document
) diff --git a/unfold/templates/plugin.html b/unfold/templates/plugin.html index ee0cbecb..88a56d92 100644 --- a/unfold/templates/plugin.html +++ b/unfold/templates/plugin.html @@ -4,7 +4,9 @@ +{% endif %} {% endif %}{# togglable #} {% endif %}{# visible #} -- 2.43.0
"+cell+"
"+cell+"