Permalink
Browse files

Multiple detail views and added a a method to add the views to bake i…

…nto the mgmt command
  • Loading branch information...
1 parent 5ce424e commit efe4285d070b33e31a05f836a959c95848f69267 @Schwanksta Schwanksta committed Feb 4, 2012
Showing with 19 additions and 14 deletions.
  1. +7 −5 management/build.py
  2. +12 −9 models.py
View
@@ -38,11 +38,13 @@ def handle(self, *args, **options):
)
shutil.copytree(settings.STATIC_ROOT, static_path)
- # CURRENT IDEA:
- # Here we should parse through a list of views passed in
- # from the command line, and then run .build_objects()
- # over them. That way we can use the built-in queryset.
- #
+ try:
+ settings.BAKERY_VIEWS
+ except AttributeError:
+ raise AttributeError("No views in settings.BAKERY_VIEWS")
+
+ for view in settings.BAKERY_VIEWS:
+ view.build_objects()
# Build 404 page
self.stdout.write("Building 404 page\n")
View
@@ -13,11 +13,12 @@ class BuildableModel(models.Model):
An abstract base model for an object that builds out
its own detail pages.
- Set the detail_view to the string representing your class-based
- view (which should inherit from BuildableDetailView), then fill
- out _build_related and _build_extra if need be.
+ Set `detail_views` to an iterable containing
+ strings which represent your class-based
+ view (which should inherit from BuildableDetailView),
+ then fill out _build_related and _build_extra if need be.
"""
- detail_view = None
+ detail_views = []
def _view_from_string(name):
"""
@@ -47,12 +48,14 @@ def _build_extra(self):
def build(self):
"""
- Takes the view pointed to by self.detail_view,
- runs build_object with `self`, and calls
- _build_extra() and _build_related()
+ Iterates through the views pointed to by
+ self.detail_views, runs build_object
+ with `self`, and calls_build_extra() and
+ _build_related()
"""
- view = self._view_from_string(self.detail_view)
- view().build_object(self)
+ for detail_view in self.detail_views:
+ view = self._view_from_string(detail_view)
+ view().build_object(self)
self._build_extra()
self._build_related()

0 comments on commit efe4285

Please sign in to comment.