From: Thierry Parmentelat Date: Mon, 10 Dec 2012 14:09:32 +0000 (+0100) Subject: new engine/ app, the location to where to implement plugin/query and X-Git-Tag: myslice-django-0.1-1~159 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=870308d6f7c55b5f23b82b30713656d629e15e3e;p=unfold.git new engine/ app, the location to where to implement plugin/query and the like first stab at a small plugin class that can render toggable (hide&show) plugins --- diff --git a/engine/__init__.py b/engine/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/engine/models.py b/engine/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/engine/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/engine/plugin.py b/engine/plugin.py new file mode 100644 index 00000000..f3c659f6 --- /dev/null +++ b/engine/plugin.py @@ -0,0 +1,50 @@ +# this is the abstract interface for Plugin instances +# so it should be specialized in real plugin classes +# like e.g. plugins.simplelist.SimpleList + +from django.template.loader import render_to_string + +class Plugin: + + uid=0 + + def __init__ (self, **settings): + self.uuid=Plugin.uid + Plugin.uid += 1 + # we store as a dictionary the arguments passed to constructor + # e.g. SimpleList (visible=True) => _settings = {'visible':True} + self._settings=settings + + def get_class (self): return type(self).__name__ + + # shorthands to inspect _settings + def get_setting (self, setting, default): + if setting not in self._settings: return default + else: return self._settings[setting] + + def is_visible (self): return self.get_setting ('visible',True) + def is_hidable (self): return self.get_setting ('hidable',False) + def is_hidden_by_default (self): return self.get_setting ('hidden_by_default', False) + + # returns the html code for that plugin + # in essence, wraps the results of self.render_content () + def render (self): + uuid = self.uuid + title = self.get_class() + plugin_content = self.render_content () + + # xxx missing from the php version + # compute an 'optionstr' from the set of available settings/options as a json string + # that gets passed to jquery somehow + # see the bottom of + result = render_to_string ('render_plugin.html', + {'uuid':uuid, 'title':title, + 'visible':self.is_visible(), + 'hidable':self.is_hidable(), + 'hidden':self.is_hidden_by_default(), + 'plugin_content' : plugin_content, + 'optionstr' : 'xxx-todo', + }) + + return result + diff --git a/engine/query.py b/engine/query.py new file mode 100644 index 00000000..62b47836 --- /dev/null +++ b/engine/query.py @@ -0,0 +1,23 @@ +# needed imports +# uniqid + +class Query: + + def __init__ (self): + self.action=None + self.method=None + self.ts=None + self.filters=[] + self.params=[] + self.fields=[] + self.unique=False + self.uuid=uniquid() + self.sort=None + self.limit=None + self.offset=None + self.analyzed_query=None + self.subqueries = [] + + def to_json (self): + return "Query.json: todo" + diff --git a/engine/tests.py b/engine/tests.py new file mode 100644 index 00000000..adc92ed4 --- /dev/null +++ b/engine/tests.py @@ -0,0 +1,19 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + +from plugins.simplelist import SimpleList + +class PluginTest(TestCase): + def test_basic(self): + """ + Tests that 1 + 1 always equals 2. + """ + sl = SimpleList (visible=True) + print 'rendering', sl.render() + self.assertEqual(1 + 1, 2) diff --git a/engine/views.py b/engine/views.py new file mode 100644 index 00000000..f7996a27 --- /dev/null +++ b/engine/views.py @@ -0,0 +1,22 @@ +# Create your views here. + +from django.core.context_processors import csrf +from django.template import RequestContext +from django.template.loader import render_to_string +from django.shortcuts import render_to_response + +from plugins.simplelist import SimpleList + +def test_plugin_view (request): + + test_plugin = SimpleList (visible=True, hidable=True) + plugin_content = test_plugin.render () + + print '--------------------' + print plugin_content + print '--------------------' + + return render_to_response ('test-plugin.html', + {'content_main' : plugin_content}, + context_instance=RequestContext(request)) + diff --git a/myslice/settings.py b/myslice/settings.py index 7785f048..d88a3356 100644 --- a/myslice/settings.py +++ b/myslice/settings.py @@ -134,6 +134,8 @@ INSTALLED_APPS = ( 'insert_above', 'myslice', 'auth', + 'engine', + 'plugins', 'slice', # Uncomment the next line to enable the admin: # 'django.contrib.admin', diff --git a/myslice/urls.py b/myslice/urls.py index c6fa979e..ab67f550 100644 --- a/myslice/urls.py +++ b/myslice/urls.py @@ -25,4 +25,5 @@ urlpatterns = patterns( (r'^slice/(?P[\w\.]+)/?$', 'slice.views.fake_slice_view'), (r'^tab/?$', 'slice.views.tab_view'), (r'^scroll/?$', 'slice.views.scroll_view'), + (r'^plugin/?$', 'engine.views.test_plugin_view'), ) diff --git a/plugins/__init__.py b/plugins/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/plugins/simplelist.py b/plugins/simplelist.py new file mode 100644 index 00000000..5a97fcb7 --- /dev/null +++ b/plugins/simplelist.py @@ -0,0 +1,9 @@ +from engine.plugin import Plugin + +class SimpleList (Plugin) : + + def render_content (self): + return """""" diff --git a/static/js/plugin.js b/static/js/plugin.js new file mode 100644 index 00000000..cb04cfc6 --- /dev/null +++ b/static/js/plugin.js @@ -0,0 +1,26 @@ +/* upon document completion, we locate all the hide and show areas, + * and configure their behaviour + */ +/* xxx missing - see plugin.php + * if (typeof jQuery('#$uuid').$title != 'undefined') { + * jQuery('#$uuid').$title('show'); + * }; + */ + +$(document).ready( + function() { + $('.plugin-hide').each(function(p) { + plugin='#'+$(this).attr('id').replace('hide-','plugin-'); + show='#'+$(this).attr('id').replace('hide-','show-'); + type=$(this).attr('plugin-type'); + $(this).click(function () { jQuery(plugin).hide(); jQuery(show).show(); $(this).hide();}) + }) + $('.plugin-show').each(function(p) { + plugin='#'+$(this).attr('id').replace('show-','plugin-'); + hide='#'+$(this).attr('id').replace('show-','hide-'); + type=$(this).attr('plugin-type'); + $(this).click(function () { jQuery(plugin).show(); jQuery(hide).show(); $(this).hide();}) + }) + }) + + diff --git a/templates/myslice-layout.html b/templates/myslice-layout.html index 7e69a517..4fc6e856 100644 --- a/templates/myslice-layout.html +++ b/templates/myslice-layout.html @@ -9,6 +9,7 @@ {% insert_str prelude "jquery/js/jquery.js" %} {% insert_str prelude "bootstrap/js/bootstrap.js" %} {% insert_str prelude "bootstrap/css/bootstrap.css" %} +{% insert_str prelude "js/plugin.js" %}