Permalink
Browse files

universal plugin system

  • Loading branch information...
1 parent e4eb9f9 commit af1a7b528f5d6ae0d7d2ebb049a349fcd95233cf @evildmp committed Jul 15, 2011
@@ -1,39 +1,5 @@
-from django.db.models import ForeignKey
-from widgetry import fk_lookup
-
-from django.contrib import admin
-from django import forms
-
from models import Insert
-
-class AutocompleteMixin(object):
- class Media:
- js = (
- '/static/jquery/jquery.js', # we already load jquery for the tabs
- '/static/jquery/ui/ui.core.js',
- '/static/jquery/ui/ui.tabs.js',
- )
- css = {
- 'all': ('/static/jquery/themes/base/ui.all.css',)
- }
-
- def formfield_for_dbfield(self, db_field, **kwargs):
- """
- Overrides the default widget for Foreignkey fields if they are
- specified in the related_search_fields class attribute.
- """
- if (isinstance(db_field, ForeignKey) and
- db_field.name in self.related_search_fields):
- kwargs['widget'] = fk_lookup.FkLookup(db_field.rel.to)
- return super(AutocompleteMixin, self).formfield_for_dbfield(db_field, **kwargs)
-
-class SupplyRequestMixin(object):
- def get_form(self, request, obj=None, **kwargs):
- form_class = super(SupplyRequestMixin, self).get_form(request, obj, **kwargs)
- form_class.request = request
- return form_class
-
-
+from django import forms
class InsertForm(forms.ModelForm):
class Meta:
model = Insert
@@ -44,6 +10,9 @@ class Meta:
from cms.admin.placeholderadmin import PlaceholderAdmin # if it's at the start of the file, it breaks imports somehow
+from django.contrib import admin
+
+
class InsertAdmin(PlaceholderAdmin):
pass
@@ -11,18 +11,12 @@ def edits(self):
return LogEntry.objects.filter(user = self).order_by('-id')
def last_10_edits(self):
- try:
- last_edit = self.edits()[10]
- except IndexError:
- last_edit = "Never"
+ last_edit = self.edits()[10]
return last_edit
def last_edit(self):
- try:
- last_edit = self.edits()[0].action_time
- except IndexError:
- last_edit = "Never"
+ last_edit = self.edits()[0].action_time
return last_edit
@@ -2,16 +2,14 @@
from django.utils.importlib import import_module
class WidthAdjuster(object):
- def mark(self):
+ def mark():
return
-
- def modify(self):
+ def modify():
return
class AdjusterPool(object):
"""
- Contains the set of adjusters that can provide Arkestra with hints about
- the widths (or other attributes) of placeholders and their contents
+ Contains the set of adjusters that can provide Arkestra with hints about the widths (or other attributes) of placeholders and their contents
"""
def __init__(self):
self.adjusters = {}
@@ -1,129 +0,0 @@
-class UniversalPlugin(object):
- def __init__(self, model = None, admin_site = None):
- self.lists = []
- super(UniversalPlugin, self).__init__(model, admin_site)
-
- def set_defaults(self, instance):
- # set defaults
- instance.view = getattr(instance, "view", "current")
- return
-
- def add_link_to_main_page(self, instance):
- if instance.type == "plugin" or instance.type == "sub_page":
- if (any(d['items'] for d in self.lists)) and getattr(instance.entity, self.auto_page_attribute, False):
- instance.link_to_main_page = instance.entity.get_related_info_page_url(self.auto_page_slug)
- instance.main_page_name = getattr(instance.entity, self.auto_page_menu_title, "")
-
- def print_settings(self):
- print "---- plugin settings ----"
- print "self.display", self.display
- print "self.view", self.view
- print "self.order_by", self.order_by
- print "self.group_dates", self.group_dates
- print "self.format", self.format
- print "self.list_format", self.list_format
- print "self.limit_to", self.limit_to
- print "self.layout", self.layout
-
- def add_links_to_other_items(self, instance):
- if instance.type == "main_page" or instance.type == "sub_page":
- for this_list in self.lists:
- this_list["links_to_other_items"](instance, this_list)
-
- def news_style_other_links(self, instance, this_list):
- if this_list["items"] and instance.view == "current":
- all_items_count = len(this_list["items"])
- if instance.limit_to and all_items_count > instance.limit_to:
- this_list["other_items"] = [{
- "link":instance.entity.get_related_info_page_url("news-archive"),
- "title":"news archive",
- "count": all_items_count,}]
- return this_list
-
- def events_style_other_links(self, instance, this_list):
- this_list["other_items"] = []
- if instance.view == "current":
-
- if instance.previous_events or instance.forthcoming_events:
- if instance.limit_to and len(instance.events) > instance.limit_to:
- if instance.forthcoming_events.count() > instance.limit_to:
- this_list["other_items"].append({
- "link":instance.entity.get_related_info_page_url("forthcoming-events"),
- "title":"all forthcoming events",
- "count": instance.forthcoming_events.count(),}
- )
- if instance.previous_events:
- this_list["other_items"].append({
- "link":instance.entity.get_related_info_page_url("previous-events"),
- "title":"previous events",
- "count": instance.previous_events.count(),}
- )
-
- elif instance.view == "archive":
-
- if instance.forthcoming_events:
- this_list["other_items"] = [{
- "link":instance.entity.get_related_info_page_url("forthcoming-events"),
- "title":"all forthcoming events",
- "count": instance.forthcoming_events.count(),}]
- return this_list
-
- def set_limits_and_indexes(self, instance):
- for this_list in self.lists:
-
- if this_list["items"] and len(this_list["items"]) > instance.limit_to:
- this_list["items"] = this_list["items"][:instance.limit_to]
-
- this_list["index_items"] = [item for item in this_list["items"] if not getattr(item, 'sticky', False)] # put non-top items in it
- this_list["no_of_get_whens"] = len(set(item.get_when() for item in this_list["index_items"]))
- if instance.type == "sub_page" and this_list["no_of_get_whens"] > 1: # more than 1 get_when()?
- this_list["index"] = True # show an index
- this_list["show_when"] = instance.group_dates and not ("horizontal" in instance.list_format or this_list["no_of_get_whens"] < 2)
-
- def determine_layout_settings(self, instance):
- """
- Sets:
- image_size
- list_format
-
-
- """
- if "image" in instance.format:
- instance.image_size = (75,75)
-
- # set columns for horizontal lists
- if "horizontal" in instance.list_format:
- instance.list_format = "row columns" + str(instance.limit_to) + " " + instance.list_format
-
- for this_list in self.lists:
- if this_list["items"]:
- for item in this_list["items"]:
- item.column_class = "column"
- this_list["items"][0].column_class = this_list["items"][0].column_class + " firstcolumn"
- this_list["items"][-1].column_class = this_list["items"][-1].column_class + " lastcolumn"
-
- elif "vertical" in instance.format:
- instance.list_format = "row columns1"
-
- def set_layout_classes(self, instance):
- """
- Lays out the plugin's news and events divs
- """
- instance.row_class="row"
- # if news and events will be side-by-side
- if instance.layout == "sidebyside":
- if len(self.lists) > 1:
- instance.row_class=instance.row_class+" columns" + str(len(self.lists))
- self.lists[0]["div_class"] = "column firstcolumn"
- self.lists[-1]["div_class"] = "column lastcolumn"
- # if just news or events, and it needs an index
- else:
- for this_list in self.lists:
- if this_list.get("index"):
- instance.row_class=instance.row_class+" columns3"
- instance.index_div_class = "column lastcolumn"
- this_list["div_class"] = "column firstcolumn doublecolumn"
- # and if it doesn't need an index
- else:
- instance.row_class=instance.row_class+" columns1"
-
@@ -1,39 +0,0 @@
-# from django.db import models
-# from django.conf import settings
-#
-# PLUGIN_HEADING_LEVELS = settings.PLUGIN_HEADING_LEVELS
-# PLUGIN_HEADING_LEVEL_DEFAULT = settings.PLUGIN_HEADING_LEVEL_DEFAULT
-#
-# class UniversalPluginOptions(models.Model):
-# class Meta:
-# abstract = True
-# LAYOUTS = (
-# ("sidebyside", u"Side-by-side"),
-# ("stacked", u"Stacked"),
-# )
-# layout = models.CharField("Plugin layout", max_length=25, choices = LAYOUTS, default = "sidebyside")
-# FORMATS = (
-# ("title", u"Title only"),
-# ("details image", u"Details"),
-# )
-# format = models.CharField("Item format", max_length=25,choices = FORMATS, default = "details image")
-# heading_level = models.PositiveSmallIntegerField(choices = PLUGIN_HEADING_LEVELS, default = PLUGIN_HEADING_LEVEL_DEFAULT)
-# ORDERING = (
-# ("date", u"Date alone"),
-# ("importance/date", u"Importance & date"),
-# )
-# order_by = models.CharField(max_length = 25, choices=ORDERING, default="importance/date")
-# LIST_FORMATS = (
-# ("vertical", u"Vertical"),
-# ("horizontal", u"Horizontal"),
-# )
-# list_format = models.CharField("List format", max_length = 25, choices=LIST_FORMATS, default="vertical")
-# group_dates = models.BooleanField("Show date groups", default = True)
-# limit_to = models.PositiveSmallIntegerField("Maximum number of items", default = 5, null = True, blank = True,
-# help_text = u"Leave blank for no limit")
-#
-# def sub_heading_level(self): # requires that we change 0 to None in the database
-# if self.heading_level == None: # this means the user has chosen "No heading"
-# return 6 # we need to give sub_heading_level a value
-# else:
-# return self.heading_level + 1 # so if headings are h3, sub-headings are h4

0 comments on commit af1a7b5

Please sign in to comment.