Use django-boxes instead
This commit is contained in:
		
							parent
							
								
									6dd80f9ddb
								
							
						
					
					
						commit
						ba0bb84ad7
					
				
					 11 changed files with 0 additions and 196 deletions
				
			
		|  | @ -23,18 +23,3 @@ specifying: | |||
| Page content and title can also be edited directly at the url. The ``cms`` app | ||||
| uses the `django-reversion <http://django-reversion.readthedocs.org>`_ package, | ||||
| thus content is version controlled. | ||||
| 
 | ||||
| Boxes App | ||||
| --------- | ||||
| 
 | ||||
| The ``boxes`` app allows for sections of a page to be edited like a wiki. To use this in a template | ||||
| use the ``boxes_tags`` and specify a box section of a page using the ``boxes`` tag: | ||||
| 
 | ||||
| .. code-block:: django | ||||
| 
 | ||||
|     {% load boxes_tags %} | ||||
|     {% boxes "intro_section" %} | ||||
| 
 | ||||
| This template will render an editable content box. When a staff user visits the | ||||
| page,  they will see an ``Edit this content`` button. The ``boxes`` app also uses the | ||||
| ``django-reversion`` package. | ||||
|  |  | |||
|  | @ -1,3 +0,0 @@ | |||
| # @@@ Reconcile differences with django-boxes [1] and remove from Symposion | ||||
| 
 | ||||
| # [1] http://github.com/eldarion/django-boxes/ | ||||
|  | @ -1,12 +0,0 @@ | |||
| from django.contrib import admin | ||||
| 
 | ||||
| import reversion | ||||
| 
 | ||||
| from symposion.boxes.models import Box | ||||
| 
 | ||||
| 
 | ||||
| class BoxAdmin(reversion.VersionAdmin): | ||||
| 
 | ||||
|     pass | ||||
| 
 | ||||
| admin.site.register(Box, BoxAdmin) | ||||
|  | @ -1,20 +0,0 @@ | |||
| from django.conf import settings | ||||
| 
 | ||||
| from symposion.boxes.utils import load_path_attr | ||||
| 
 | ||||
| 
 | ||||
| def default_can_edit(request, *args, **kwargs): | ||||
|     """ | ||||
|     This is meant to be overridden in your project per domain specific | ||||
|     requirements. | ||||
|     """ | ||||
|     return request.user.is_staff or request.user.is_superuser | ||||
| 
 | ||||
| 
 | ||||
| def load_can_edit(): | ||||
|     import_path = getattr(settings, "BOXES_CAN_EDIT_CALLABLE", None) | ||||
| 
 | ||||
|     if import_path is None: | ||||
|         return default_can_edit | ||||
| 
 | ||||
|     return load_path_attr(import_path) | ||||
|  | @ -1,10 +0,0 @@ | |||
| from django import forms | ||||
| 
 | ||||
| from symposion.boxes.models import Box | ||||
| 
 | ||||
| 
 | ||||
| class BoxForm(forms.ModelForm): | ||||
| 
 | ||||
|     class Meta: | ||||
|         model = Box | ||||
|         fields = ["content"] | ||||
|  | @ -1,28 +0,0 @@ | |||
| from __future__ import unicode_literals | ||||
| from django.db import models | ||||
| from django.contrib.auth.models import User | ||||
| from django.utils.encoding import python_2_unicode_compatible | ||||
| from django.utils.translation import ugettext_lazy as _ | ||||
| 
 | ||||
| import reversion | ||||
| 
 | ||||
| from markitup.fields import MarkupField | ||||
| 
 | ||||
| 
 | ||||
| @python_2_unicode_compatible | ||||
| class Box(models.Model): | ||||
| 
 | ||||
|     label = models.CharField(max_length=100, db_index=True, verbose_name=_("Label")) | ||||
|     content = MarkupField(blank=True) | ||||
| 
 | ||||
|     created_by = models.ForeignKey(User, related_name="boxes", verbose_name=_("Created by")) | ||||
|     last_updated_by = models.ForeignKey(User, related_name="updated_boxes", verbose_name=_("Last updated by")) | ||||
| 
 | ||||
|     def __str__(self): | ||||
|         return self.label | ||||
| 
 | ||||
|     class Meta: | ||||
|         verbose_name = _("Box") | ||||
|         verbose_name_plural = _("Boxes") | ||||
| 
 | ||||
| reversion.register(Box) | ||||
|  | @ -1,36 +0,0 @@ | |||
| from django import template | ||||
| from django.core.urlresolvers import reverse | ||||
| 
 | ||||
| from symposion.boxes.models import Box | ||||
| from symposion.boxes.forms import BoxForm | ||||
| from symposion.boxes.authorization import load_can_edit | ||||
| 
 | ||||
| 
 | ||||
| register = template.Library() | ||||
| 
 | ||||
| 
 | ||||
| @register.inclusion_tag("boxes/box.html", takes_context=True) | ||||
| def box(context, label, show_edit=True, *args, **kwargs): | ||||
| 
 | ||||
|     request = context["request"] | ||||
|     can_edit = load_can_edit()(request, *args, **kwargs) | ||||
| 
 | ||||
|     try: | ||||
|         box = Box.objects.get(label=label) | ||||
|     except Box.DoesNotExist: | ||||
|         box = None | ||||
| 
 | ||||
|     if can_edit and show_edit: | ||||
|         form = BoxForm(instance=box, prefix=label) | ||||
|         form_action = reverse("box_edit", args=[label]) | ||||
|     else: | ||||
|         form = None | ||||
|         form_action = None | ||||
| 
 | ||||
|     return { | ||||
|         "request": request, | ||||
|         "label": label, | ||||
|         "box": box, | ||||
|         "form": form, | ||||
|         "form_action": form_action, | ||||
|     } | ||||
|  | @ -1,7 +0,0 @@ | |||
| from django.conf.urls import patterns, url | ||||
| 
 | ||||
| 
 | ||||
| urlpatterns = patterns( | ||||
|     "symposion.boxes.views", | ||||
|     url(r"^([-\w]+)/edit/$", "box_edit", name="box_edit"), | ||||
| ) | ||||
|  | @ -1,19 +0,0 @@ | |||
| from django.core.exceptions import ImproperlyConfigured | ||||
| try: | ||||
|     from django.utils.importlib import import_module | ||||
| except ImportError: | ||||
|     from importlib import import_module | ||||
| 
 | ||||
| 
 | ||||
| def load_path_attr(path): | ||||
|     i = path.rfind(".") | ||||
|     module, attr = path[:i], path[i + 1:] | ||||
|     try: | ||||
|         mod = import_module(module) | ||||
|     except ImportError, e: | ||||
|         raise ImproperlyConfigured("Error importing %s: '%s'" % (module, e)) | ||||
|     try: | ||||
|         attr = getattr(mod, attr) | ||||
|     except AttributeError: | ||||
|         raise ImproperlyConfigured("Module '%s' does not define a '%s'" % (module, attr)) | ||||
|     return attr | ||||
|  | @ -1,46 +0,0 @@ | |||
| from django.http import HttpResponseForbidden | ||||
| from django.shortcuts import redirect | ||||
| from django.views.decorators.http import require_POST | ||||
| 
 | ||||
| from symposion.boxes.authorization import load_can_edit | ||||
| from symposion.boxes.forms import BoxForm | ||||
| from symposion.boxes.models import Box | ||||
| 
 | ||||
| 
 | ||||
| # @@@ problem with this is that the box_edit.html and box_create.html won't have domain objects in | ||||
| # context | ||||
| def get_auth_vars(request): | ||||
|     auth_vars = {} | ||||
|     if request.method == "POST": | ||||
|         keys = [k for k in request.POST.keys() if k.startswith("boxes_auth_")] | ||||
|         for key in keys: | ||||
|             auth_vars[key.replace("boxes_auth_", "")] = request.POST.get(key) | ||||
|         auth_vars["user"] = request.user | ||||
|     return auth_vars | ||||
| 
 | ||||
| 
 | ||||
| @require_POST | ||||
| def box_edit(request, label): | ||||
| 
 | ||||
|     if not load_can_edit()(request, **get_auth_vars(request)): | ||||
|         return HttpResponseForbidden() | ||||
| 
 | ||||
|     next = request.GET.get("next") | ||||
| 
 | ||||
|     try: | ||||
|         box = Box.objects.get(label=label) | ||||
|     except Box.DoesNotExist: | ||||
|         box = None | ||||
| 
 | ||||
|     form = BoxForm(request.POST, instance=box, prefix=label) | ||||
| 
 | ||||
|     if form.is_valid(): | ||||
|         if box is None: | ||||
|             box = form.save(commit=False) | ||||
|             box.label = label | ||||
|             box.created_by = request.user | ||||
|             box.last_updated_by = request.user | ||||
|             box.save() | ||||
|         else: | ||||
|             form.save() | ||||
|         return redirect(next) | ||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Patrick Altman
						Patrick Altman