Browse files

generic model improvements

  • Loading branch information...
1 parent 2bed385 commit 279e829a8d6604859a37ac38cb27148cb84b51ac @evildmp committed Dec 16, 2011
View
58 arkestra_utilities/generic_models.py
@@ -149,19 +149,38 @@ def clean(self):
class ArkestraGenericPlugin(object):
text_enabled = True
- def __init__(self, model = None, admin_site = None):
- self.render_template = "arkestra/universal_plugin_lister.html"
- self.admin_preview = False
- super(ArkestraGenericPlugin, self).__init__(model, admin_site)
+ admin_preview = False
+ # default render_template - change it in your ArkestraGenericPlugin if required
+ render_template = "arkestra/universal_plugin_lister.html"
+
+ # def __init__(self, model = None, admin_site = None):
+ # super(ArkestraGenericPlugin, self).__init__(model, admin_site)
def set_defaults(self, instance):
- print "**", type(instance)
# set defaults
+ # ** important ** - these are set only when the render() function is called
+ instance.display = getattr(instance, "display", "")
instance.view = getattr(instance, "view", "current")
instance.list_format = getattr(instance, "list_format", "vertical")
instance.layout = getattr(instance, "layout", "")
- instance.limit_to = getattr(instance, "limit_to", 10)
- instance.group_dates = getattr(instance, "group_dates", False)
+ instance.limit_to = getattr(instance, "limit_to", None)
+ instance.group_dates = getattr(instance, "group_dates", True)
+ instance.format = getattr(instance, "format", "details image")
+ instance.type = getattr(instance, "type", "plugin") # assume it's a plugin unless otherwise stated
+ instance.order_by = getattr(instance, "order_by", "")
+ instance.heading_level = getattr(instance, "heading_level", PLUGIN_HEADING_LEVEL_DEFAULT)
+ instance.type = getattr(instance, "type", "plugin")
+
+ print "---- plugin settings ----"
+ print "self.display", instance.display
+ print "self.view", instance.view
+ print "self.group_dates", instance.group_dates
+ print "self.format", instance.format
+ print "self.list_format", instance.list_format
+ print "self.order_by", instance.order_by
+ print "self.limit_to", instance.limit_to
+ print "self.layout", instance.layout
+ print "self.heading_level", instance.heading_level
return
def add_link_to_main_page(self, instance):
@@ -185,11 +204,14 @@ def add_link_to_main_page(self, instance):
def add_links_to_other_items(self, instance):
if instance.type == "main_page" or instance.type == "sub_page" or instance.type == "menu":
for this_list in self.lists:
- this_list["links_to_other_items"](instance, this_list)
+ # does this list have a function specified that will add the links we need to other items?
+ if this_list.get("links_to_other_items"):
+ # call that function
+ this_list["links_to_other_items"](instance, this_list)
def set_limits_and_indexes(self, instance):
- for this_list in self.lists:
+ for this_list in self.lists:
# cut the list down to size if necessary
if this_list["items"] and len(this_list["items"]) > instance.limit_to:
this_list["items"] = this_list["items"][:instance.limit_to]
@@ -204,13 +226,6 @@ def set_limits_and_indexes(self, instance):
# we only show date groups when warranted
this_list["show_when"] = instance.group_dates and not ("horizontal" in instance.list_format or this_list["no_of_get_whens"] < 2)
- # def set_image_format(self, instance):
- # """
- # Sets:
- # image_size
- # """
- # if "image" in instance.format:
- # instance.image_size = (75,75)
def determine_layout_settings(self, instance):
"""
@@ -232,7 +247,7 @@ def determine_layout_settings(self, instance):
this_list["items"][-1].column_class = this_list["items"][-1].column_class + " lastcolumn"
elif "vertical" in instance.list_format:
- instance.list_format = "row columns1"
+ instance.list_format = "vertical"
def set_layout_classes(self, instance):
"""
@@ -260,16 +275,12 @@ def get_items(self, instance):
self.lists = []
def render(self, context, instance, placeholder):
- self.set_defaults(instance)
-
instance.entity = getattr(instance, "entity", None) or work_out_entity(context, None)
- instance.type = getattr(instance, "type", "plugin")
- render_template = getattr(instance, "render_template", "")
+ self.set_defaults(instance)
self.get_items(instance)
self.add_link_to_main_page(instance)
self.add_links_to_other_items(instance)
self.set_limits_and_indexes(instance)
- # self.set_image_format(instance)
self.determine_layout_settings(instance)
self.set_layout_classes(instance)
instance.lists = self.lists
@@ -278,3 +289,6 @@ def render(self, context, instance, placeholder):
'placeholder': placeholder,
})
return context
+
+ def icon_src(self, instance):
+ return "/static/plugin_icons/generic.png"
View
13 arkestra_utilities/menu.py
@@ -87,11 +87,11 @@ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
for menu in arkestra_menus:
self.do_menu(node, menu, node.entity)
- self.create_new_node(
- title = "Publications",
- url = node.entity.get_related_info_page_url("publications"),
- parent = node,
- )
+ # self.create_new_node(
+ # title = "Publications",
+ # url = node.entity.get_related_info_page_url("publications"),
+ # parent = node,
+ # )
print " ++ saving cache", key
cache.set(key, self.nodes, settings.CMS_CACHE_DURATIONS['menus'])
@@ -110,7 +110,6 @@ def do_menu(self, node, menu, entity):
# does this entity have this kind of auto-page in the menu?
if getattr(entity, menu["auto_page_attribute"]):
cms_plugin_model = menu.get("cms_plugin_model")
-
new_nodes = []
if cms_plugin_model:
@@ -121,6 +120,7 @@ def do_menu(self, node, menu, entity):
)
instance.type = "menu"
instance.view = "current"
+
# use the instance to create an instance of the plugin publisher
plugin = cms_plugin_model()
# use its get_items method to place publishable items in plugin.lists
@@ -136,6 +136,7 @@ def do_menu(self, node, menu, entity):
for item in plugin.lists:
# and go through the other_items lists for each, creating a node for each
for other_item in item["other_items"]:
+
self.create_new_node(
title = other_item["title"],
url = other_item["link"],
View
4 arkestra_utilities/mixins.py
@@ -68,7 +68,9 @@ def get_absolute_url(self):
return "/%s/%s/" % (self.url_path, self.slug)
-class LocationModelMixin(object):
+class LocationModelMixin(models.Model):
+ class Meta:
+ abstract = True
# location fields
precise_location = models.CharField(help_text=u"Precise location <em>within</em> the building, for visitors",
max_length=255, null=True, blank=True)
View
2 news_and_events/cms_plugins.py
@@ -20,7 +20,7 @@ class Meta:
model = NewsAndEventsPlugin
-class CMSNewsAndEventsPlugin(ArkestraGenericPlugin, NewsAndEventsPluginMixin, AutocompleteMixin, CMSPluginBase):
+class CMSNewsAndEventsPlugin(NewsAndEventsPluginMixin, ArkestraGenericPlugin, AutocompleteMixin, CMSPluginBase):
model = NewsAndEventsPlugin
name = _("News & events")
form = NewsAndEventsPluginForm
View
2 news_and_events/mixins.py
@@ -46,7 +46,7 @@ def get_items(self, instance):
if "news" in instance.display:
this_list = {"model": NewsArticle,}
this_list["items"] = NewsArticle.objects.get_items(instance)
- this_list["links_to_other_items"] = self.news_style_other_links
+ this_list["links_to_other_items"] = self.news_style_other_links
this_list["heading_text"] = instance.news_heading_text
this_list["item_template"] = "arkestra/universal_plugin_list_item.html"
# the following should *also* check this_list["links_to_other_items"] -
View
1 news_and_events/models.py
@@ -366,6 +366,7 @@ class NewsAndEventsPlugin(CMSPlugin, ArkestraGenericPluginOptions):
show_previous_events = models.BooleanField()
news_heading_text = models.CharField(max_length=25, default="News")
events_heading_text = models.CharField(max_length=25, default="Events")
+ my_placeholder = PlaceholderField('placeholder_name')
try:
mptt.register(Event)
View
4 news_and_events/views.py
@@ -13,10 +13,6 @@
MAIN_NEWS_EVENTS_PAGE_LIST_LENGTH = settings.MAIN_NEWS_EVENTS_PAGE_LIST_LENGTH
IN_BODY_HEADING_LEVEL = settings.IN_BODY_HEADING_LEVEL
-class NewsAndEventsViews(object):
- def test(self):
- pass
-
def common_settings(request, slug):
entity = Entity.objects.get(slug=slug) or default_entity
View
2 vacancies_and_studentships/cms_plugins.py
@@ -19,7 +19,7 @@ class Meta:
model = VacanciesPlugin
-class CMSVacanciesPlugin(ArkestraGenericPlugin, VacancyStudentshipPluginMixin, AutocompleteMixin, CMSPluginBase):
+class CMSVacanciesPlugin(VacancyStudentshipPluginMixin, ArkestraGenericPlugin, AutocompleteMixin, CMSPluginBase):
model = VacanciesPlugin
name = _("Vacancies & Studentships")
form = VacanciesStudentshipsPluginForm

0 comments on commit 279e829

Please sign in to comment.