Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
# template tag | |
from mezzanine import template | |
from mezzanine.forms.forms import FormForForm | |
from mezzanine.pages.models import Page | |
register = template.Library() | |
@register.as_tag | |
def form_from_page(slug): |
$ FILE=/some/path/to/file.txt | |
################################### | |
### Remove matching suffix pattern | |
################################### | |
$ echo ${FILE%.*} # remove ext | |
/some/path/to/file | |
$ FILE=/some/path/to/file.txt.jpg.gpg # note various file exts |
from django.template.defaultfilters import slugify | |
from django.contrib.sites.models import Site | |
from django.core.files import File | |
from taggit.models import Tag | |
from .models import Photo | |
import factory | |
import os | |
TEST_MEDIA_PATH = os.path.join(os.path.dirname(__file__), 'tests', 'test_media') | |
TEST_PHOTO_PATH = os.path.join(TEST_MEDIA_PATH, 'test_photo.png') |
""" | |
This generic view displays a list of objects and a simple ModelForm to add a new | |
object to the list. | |
Just subclass this view and override the attributes and methods that you need. You | |
will probably need to override at least 'model', 'form_class' and 'success_url'. | |
See the documentation of the used mixins and ProcessFormView in | |
https://docs.djangoproject.com/en/1.4/ref/class-based-views/ | |
""" | |
from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin | |
from django.views.generic.edit import ModelFormMixin, ProcessFormView |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!