From 54a3a3407243fed03ee5977eeef2098c5a98b66c Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 12 May 2014 12:23:32 +0530 Subject: [PATCH] Remove custom written form code in favor of Django forms --- modules/installed/lib/forms.py | 151 --------------------------------- plugin_mount.py | 30 ------- 2 files changed, 181 deletions(-) delete mode 100644 modules/installed/lib/forms.py diff --git a/modules/installed/lib/forms.py b/modules/installed/lib/forms.py deleted file mode 100644 index 4980efd37..000000000 --- a/modules/installed/lib/forms.py +++ /dev/null @@ -1,151 +0,0 @@ -""" -The Form class is a helper class that takes parameters and method -calls and can return html for a form with appropriate hooks for css -styling. It should allow you to display a form but have the -formatting and styling added by the class. You can worry less about -how it looks while still getting consistent, decent-looking forms. - -Take a look at the FirstBoot class for an example of forms in action. - -Copyright 2011-2013 James Vasile - -This software is released to you (yes, you) under the terms of the GNU -Affero General Public License, version 3 or later, available at -. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. -""" -class Form(): - def __init__(self, action=None, cls='form', title=None, onsubmit=None, name=None, message='', method="post"): - - action = self.get_form_attrib_text('action', action) - onsubmit = self.get_form_attrib_text('onsubmit', onsubmit) - name = self.get_form_attrib_text('name', name) - - self.pretext = '
\n' % (cls, method, action, onsubmit, name) - if title: - self.pretext += '

%s

\n' % title - - if message: - self.message = "

%s

" % message - else: - self.message = '' - self.text = '' - self.end_text = "
\n" - def get_form_attrib_text(self, field, val): - if val: - return ' %s="%s"' % (field, val) - else: - return '' - def html(self, html): - self.text += html - def dropdown(self, label='', name=None, id=None, vals=None, select=None, onchange=''): - """vals is a list of values. - select is the index in vals of the selected item. None means no item is selected yet.""" - name, id = self.name_or_id(name, id) - self.text += (""" \n""" - - def dotted_quad(self, label='', name=None, id=None, quad=None): - name, id = self.name_or_id(name, id) - if not quad: - quad = [0,0,0,0] - self.text += """ """ % {'label':label, 'name':name, 'id':id, 'q0':quad[0], 'q1':quad[1], 'q2':quad[2], 'q3':quad[3]} - - def text_input(self, label='', name=None, id=None, type='text', value='', size=20): - name, id = self.name_or_id(name, id) - if type=="hidden": - self.text += '' % (type, name, id, value) - else: - self.text += """ """ % (label, type, name, id, value, size) - def hidden(self, name=None, id=None, value=''): - self.text_input(type="hidden", name=name, id=id, value=value) - def text_box(self, label='', name=None, id=None, value=""): - name, id = self.name_or_id(name, id) - self.text += """ - """ % (label, name, id, value) - def submit(self, label='', name=None, id=None): - name, id = self.name_or_id(name, id) - self.text += """ -
-
\n""" % (label, name, id) - def submit_row(self, buttons): - """buttons is a list of tuples, each containing label, name, id. Name and id are optional.""" - self.text += '
' % button_text - def name_or_id(self, name, id): - if not name: name = id - if not id: id = name - if not name: name = '' - if not id: id = '' - return name, id - def checkbox(self, label='', name='', id='', checked=''): - name, id = self.name_or_id(name, id) - if checked: - checked = 'checked="on"' - self.text += """ -
-
\n""" % (label, name, id, checked) - def radiobutton(self, label='', name='', id='', value='', checked=''): - name, id = self.name_or_id(name, id) - if checked: - checked = 'checked="on"' - self.text += """ -
-
\n""" % (label, name, id, value, checked) - def get_checkbox(self, name='', id=''): - return '\n' % self.name_or_id(name, id) - def render(self): - return self.pretext+self.message+self.text+self.end_text diff --git a/plugin_mount.py b/plugin_mount.py index 9b2e1e6e2..e3ef5db41 100644 --- a/plugin_mount.py +++ b/plugin_mount.py @@ -34,27 +34,6 @@ class PluginMountSingular(PluginMount): cls.plugins.append(cls) -def get_parts(obj, parts=None, *args, **kwargs): - if parts == None: - parts={} - - fields = ['sidebar_left', 'sidebar_right', 'main', 'js', 'onload', 'nav', 'css', 'title'] - for v in fields: - if not v in parts: - parts[v] = '' - - try: - method = getattr(obj, v) - if callable(method): - parts[v] = method(*args, **kwargs) - else: - parts[v] = method - except AttributeError: - pass - - return parts - - def _setattr_deep(obj, path, value): """If path is 'x.y.z' or ['x', 'y', 'z'] then perform obj.x.y.z = value""" if isinstance(path, basestring): @@ -87,15 +66,6 @@ class PagePlugin: cfg.log.info("Registering page: %s" % url) _setattr_deep(cfg.html_root, url, self) - def forms(self, url, *args, **kwargs): - for form in cfg.forms: - if url in form.url: - cfg.log('Pulling together form for url %s (which matches %s)' % (url, form.url)) - - parts = get_parts(form, None, *args, **kwargs) - - return parts - class UserStoreModule: """