Commits

Osiloke Emoekpere committed 6f7f3e3

Modified models to subclass Mezzanines SiteRelated class, to make sure widgets are assigned to sites properly, also some aesthetic changes

Comments (0)

Files changed (9)

 from os.path import join
 
 from django import forms
- 
+from mezzanine.core.models import CONTENT_STATUS_CHOICES, CONTENT_STATUS_DRAFT
+
 from widget.widget_pool import get_widget_options, WidgetHasNoOptions
 from widget.models import WidgetOptionEntry, Widget
 
     """
 
     hasOptions = False
+    status = forms.ChoiceField(choices=CONTENT_STATUS_CHOICES, initial=CONTENT_STATUS_DRAFT)
 
     def __init__(self, widget_class, *args, **kwargs):
         """
         """
         Save all option ``WidgetOptionEntry`` with reference to the passed widget.
         """
+        widget.status = self.cleaned_data['status']
+        widget.save()
 
         if self.hasOptions:
             for field in self.form_fields:

widget/migrations/0020_auto__del_widgetslot__chg_field_widget_display_title__add_field_widget.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Deleting model 'WidgetSlot'
+        db.delete_table('widget_widgetslot')
+
+
+        # Changing field 'Widget.display_title'
+        db.alter_column('widget_widget', 'display_title', self.gf('django.db.models.fields.CharField')(default='title', max_length=255))
+        # Adding field 'WidgetOptionGroup.site'
+        db.add_column('widget_widgetoptiongroup', 'site',
+                      self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['sites.Site']),
+                      keep_default=False)
+
+        # Adding field 'WidgetOptionEntry.site'
+        db.add_column('widget_widgetoptionentry', 'site',
+                      self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['sites.Site']),
+                      keep_default=False)
+
+        # Adding field 'WidgetModel.site'
+        db.add_column('widget_widgetmodel', 'site',
+                      self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['sites.Site']),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Adding model 'WidgetSlot'
+        db.create_table('widget_widgetslot', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=255)),
+        ))
+        db.send_create_signal('widget', ['WidgetSlot'])
+
+
+        # Changing field 'Widget.display_title'
+        db.alter_column('widget_widget', 'display_title', self.gf('django.db.models.fields.CharField')(max_length=255, null=True))
+        # Deleting field 'WidgetOptionGroup.site'
+        db.delete_column('widget_widgetoptiongroup', 'site_id')
+
+        # Deleting field 'WidgetOptionEntry.site'
+        db.delete_column('widget_widgetoptionentry', 'site_id')
+
+        # Deleting field 'WidgetModel.site'
+        db.delete_column('widget_widgetmodel', 'site_id')
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'generic.assignedkeyword': {
+            'Meta': {'ordering': "('_order',)", 'object_name': 'AssignedKeyword'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'keyword': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'assignments'", 'to': "orm['generic.Keyword']"}),
+            'object_pk': ('django.db.models.fields.IntegerField', [], {})
+        },
+        'generic.keyword': {
+            'Meta': {'object_name': 'Keyword'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+            'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+        },
+        'pages.page': {
+            'Meta': {'ordering': "('titles',)", 'object_name': 'Page'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+            'content_model': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'expiry_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'gen_description': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'in_footer': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'in_navigation': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'keywords': ('mezzanine.generic.fields.KeywordsField', [], {'object_id_field': "'object_pk'", 'to': "orm['generic.AssignedKeyword']", 'frozen_by_south': 'True'}),
+            'keywords_string': ('django.db.models.fields.CharField', [], {'max_length': '500', 'blank': 'True'}),
+            'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['pages.Page']"}),
+            'publish_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'short_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+            'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
+            'status': ('django.db.models.fields.IntegerField', [], {'default': '2'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+            'titles': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True'})
+        },
+        'sites.site': {
+            'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
+            'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'widget.widget': {
+            'Meta': {'ordering': "('display_title',)", 'object_name': 'Widget'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'acts_on': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'display_title': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255'}),
+            'expiry_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'page': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['pages.Page']", 'null': 'True', 'blank': 'True'}),
+            'page_less': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'publish_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+            'status': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'widgets'", 'to': "orm['auth.User']"}),
+            'widget_class': ('widget.fields.PageWidgetClass', [], {'default': "''", 'max_length': '255'}),
+            'widget_file_title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'widgetslot': ('django.db.models.fields.CharField', [], {'default': "'none'", 'max_length': '255'})
+        },
+        'widget.widgetmodel': {
+            'Meta': {'object_name': 'WidgetModel'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+            'widget': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['widget.Widget']"})
+        },
+        'widget.widgetoptionentry': {
+            'Meta': {'object_name': 'WidgetOptionEntry'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+            'value': ('django.db.models.fields.CharField', [], {'max_length': '2000'}),
+            'widget': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'options'", 'to': "orm['widget.Widget']"})
+        },
+        'widget.widgetoptiongroup': {
+            'Meta': {'object_name': 'WidgetOptionGroup'},
+            'entry_time': ('django.db.models.fields.DateTimeField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+            'widget': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'option_group'", 'unique': 'True', 'to': "orm['widget.Widget']"})
+        }
+    }
+
+    complete_apps = ['widget']
 from mezzanine.conf import settings
 from mezzanine.core.managers import PublishedManager, SearchableManager
 from mezzanine.core.models import Orderable, Displayable, \
-    CONTENT_STATUS_CHOICES, CONTENT_STATUS_DRAFT, Ownable
+    CONTENT_STATUS_CHOICES, CONTENT_STATUS_DRAFT, Ownable, SiteRelated
 from mezzanine.forms.fields import TEXT
 from mezzanine.pages.models import Page
 
         raise NotImplementedError("Render function needs to be implemented")
 
 
-class WidgetModel(models.Model):
+class WidgetModel(SiteRelated):
     widget = models.ForeignKey('widget.Widget')
 
     def __unicode__(self):
     pass
 
 
-class Widget(Orderable, Ownable):
+class Widget(Orderable, Ownable, SiteRelated):
     display_title = models.CharField(default=None, verbose_name="Title", max_length=255, \
         null=False)
     widget_class = PageWidgetClass(default="", verbose_name="Widget Type")
     widgetslot = models.CharField(max_length=255, default="none")
     page_less = models.BooleanField(default=False)
     page = models.ForeignKey(Page, null=True, blank=True)
-    status = models.IntegerField(_("Status"),
+    status = models.IntegerField(_("Publish Status"),
         choices=CONTENT_STATUS_CHOICES, default=CONTENT_STATUS_DRAFT)
     publish_date = models.DateTimeField(_("Published from"),
         help_text=_("With published checked, won't be shown until this time"),
     expiry_date = models.DateTimeField(_("Expires on"),
         help_text=_("With published checked, won't be shown after this time"),
         blank=True, null=True)
-    site = models.ForeignKey(Site, editable=False)
+#    site = models.ForeignKey(Site, editable=False)
 
     objects = WidgetManager()
     search_fields = {"keywords": 10, "display_title": 5}
         ordering = ("display_title",) 
 
 
-class WidgetOptionGroup(models.Model):
+class WidgetOptionGroup(SiteRelated):
     """
     A group of option entries for a widget
     """
         verbose_name_plural = _("Widget Option Group's")
 
 
-class WidgetOptionEntry(models.Model):
+class WidgetOptionEntry(SiteRelated):
 
     """
     A single option value for a form entry submitted via a user-built form.

widget/static/widget/css/widget.css

 .widget-toolbar{margin-bottom: 5px;}
-.widget_holder{border-bottom: #2D2D2D solid thick;}
+/*.widget_holder{border-bottom: #2D2D2D solid thick;}*/
 /* FORM consistent with mezzanine editable form, Should really be a general frontend admin form layout */
 
 .frontend-admin-form {padding:20px; background:#fffcc3; border:1px solid #000;

widget/static/widget/js/widget.coffee

     $("#edit-widget-form").adminForm({resultParsed: @onEditData})
     $('.widget-edit-link').click((e) =>
         widget_id = e.currentTarget.id.split("-")[1]
-        @onEditForm(e.currentTarget, widget_id)
+        widget_title = e.currentTarget.value
+        @onEditForm(e.currentTarget, widget_id, widget_title)
     )
     @
 
-  onEditForm: (link, widget_id) ->
+  onEditForm: (link, widget_id, widget_title) ->
     widget = this
     editUrl = "/widget/edit/" + widget_id + "/"
     options = {
       success: (data) ->
         expose = {color: "#333", loadSpeed: 200, opacity: 0.9}
         overlay = {load: true, closeOnEsc: true, expose: expose, closeOnClick: true, close: ':button'}
-        widget.onEditData(null, data) 
+        widget.onEditData(null, data, widget_title)
         $("#edit-widget-form")
           # .adminForm({data: {id: widget_id}})
           .get(0)
     $.ajax(options)
     @
 
-  onEditData: (e, params) ->
+  onEditData: (e, params, widget_title) ->
     if params.status == true
       location.reload()
     else

widget/static/widget/js/widget.js

         resultParsed: this.onEditData
       });
       $('.widget-edit-link').click(function(e) {
-        var widget_id;
+        var widget_id, widget_title;
         widget_id = e.currentTarget.id.split("-")[1];
-        return _this.onEditForm(e.currentTarget, widget_id);
+        widget_title = e.currentTarget.value;
+        return _this.onEditForm(e.currentTarget, widget_id, widget_title);
       });
       return this;
     };
 
-    WidgetAdmin.prototype.onEditForm = function(link, widget_id) {
+    WidgetAdmin.prototype.onEditForm = function(link, widget_id, widget_title) {
       var editUrl, options, widget;
       widget = this;
       editUrl = "/widget/edit/" + widget_id + "/";
             closeOnClick: true,
             close: ':button'
           };
-          widget.onEditData(null, data);
+          widget.onEditData(null, data, widget_title);
           $("#edit-widget-form").get(0).setAttribute("action", editUrl);
           $(link).overlay(overlay);
           return $(link).overlay(overlay).load();
       return this;
     };
 
-    WidgetAdmin.prototype.onEditData = function(e, params) {
+    WidgetAdmin.prototype.onEditData = function(e, params, widget_title) {
       var optHolder;
       if (params.status === true) {
         location.reload();

widget/templates/widget/edit_widget_form.html

     action="#" id="edit-widget-form"
     {% if form.is_multipart %} enctype="multipart/form-data"{% endif %}>
     <fieldset id="widget-options" style="display:none;border:none;" >
-    <legend>Configure this bitch</legend>
+    <legend></legend>
     {{ options }}
     </fieldset>
     <input type="button" name="close" value="{% trans "Close" %}" class="button" />

widget/templates/widget/holder.html

     {% for w in widgets %}
     <div id="{{ w.meta.name|cut:" "|force_escape|lower}}-widget-holder" class="ui-state-default widget_holder" style="position:relative;">
         {% if request.user.is_staff %}
-            {% if w.widget.hasOptions %}
+            {# if w.widget.hasOptions #}
             <div class="btn-toolbar">
             <span class="widget-item-toolbar btn-group">
                 
-                <a id="ew-{{ w.widget.id }}" class="widget-edit-link btn btn-small" rel="#edit-widget-form" href="#edit-widget" ><i class="icon-edit"></i>{% trans "Configure Widget" %}</a>
+                <a id="ew-{{ w.widget.id }}" class="widget-edit-link label-info label" rel="#edit-widget-form" href="#edit-widget" ><i class="icon-edit"></i>{% trans "Configure " %}{{ w.meta.name|cut:" "|force_escape|capfirst}}</a>
                   
             </span>
             </div>
-            {% endif %} 
+            {# endif #}
         <a style="position: absolute;top: 0;right: 0;" id="dw-{{ w.widget.id }}" class="widget-delete-link"  href="{% url delete_widget w.widget.id %}?next={{request.path}}"><i class="icon-remove"></i></a>
         {% endif %}
         <div id="{{ w.meta.name|cut:" "|force_escape|lower}}-widget-content">
             "This is a request to get a form for widget"
             ctx = RequestContext(request)
             "get widget form populated with widget options" 
-            widget = Widget.objects.get(id=kwargs.get("id")) 
+            widget = Widget.objects.get(id=kwargs.get("id"))
+            initial = {'status': widget.status}
             if widget.hasOptions:
-                initial = dict(("option_%s" % option.name, option.value) \
-                             for option in widget.options.all())
-                options_form = WidgetOptionsForm(widget.widget_class, \
-                                data=initial)
+                initial.update(dict(("option_%s" % option.name, option.value) \
+                             for option in widget.options.all()))
+            options_form = WidgetOptionsForm(widget.widget_class, \
+                            data=initial)
 
-                o = get_template("widget/options.html")
-                ctx.update({'options_form': options_form})
+            o = get_template("widget/options.html")
+            ctx.update({'options_form': options_form})
 
-                options = o.render(ctx)
-                data = {'valid': False, 'type': 'ef', 'data': options}
-            else:
-                data = {'valid': True, 'type': 'nf'}
+            options = o.render(ctx)
+            data = {'valid': False, 'type': 'ef', 'data': options}
+#            else:
+#                data = {'valid': True, 'type': 'nf'}
 
         return HttpResponse(json_serializer.encode(data), \
                             mimetype='application/json')