Skip to content

Commit

Permalink
Had to add a content_md field so the uses could access the markdown
Browse files Browse the repository at this point in the history
Removed the the template_tag implementation as the image stuff is
no longer necessary.
I will be adding a include tag for metadata
  • Loading branch information
chrisdev committed Jul 2, 2012
1 parent 5d33ff0 commit 10aab41
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 61 deletions.
45 changes: 37 additions & 8 deletions flatpages_x/admin.py
Expand Up @@ -3,12 +3,12 @@
from django.contrib.flatpages.models import FlatPage
from django import forms
from django.utils.translation import ugettext_lazy as _
from flatpages_x.models import FlatPageImage,FlatPageMeta
from flatpages_x.models import FlatPageImage,FlatPageMeta,Revision
from flatpages_x.settings import FPX_TEMPLATE_CHOICES
from django.utils.functional import curry
from flatpages_x.settings import PARSER
from flatpages_x.utils import load_path_attr

from datetime import datetime


class CustomFlatPageForm(FlatpageForm):
Expand All @@ -17,14 +17,42 @@ class CustomFlatPageForm(FlatpageForm):
help_text=_("Sepcify a template for displaying your content")
)

content_md = forms.CharField(label="My Content", widget = forms.Textarea())
content = forms.CharField(
widget = forms.Textarea(
),
required=False,
)

def __init__(self,*args,**kwargs):

super(CustomFlatPageForm, self).__init__(*args, **kwargs)
fp = self.instance

try:
latest_revision=fp.revisions.order_by("-updated")[0]
except IndexError:
latest_revision= None

if latest_revision:
print "wtf", latest_revision.content_source
self.fields["content_md"].initial= latest_revision.content_source


def save(self):
fp= super(CustomFlatPageForm, self).save(commit=False)
render_func = curry(load_path_attr(PARSER[0],**PARSER[1]))
fp.content= render_func(self.cleaned_data["content"])
fp.content= render_func(self.cleaned_data["content_md"])
fp.save()
return fp



r=Revision()
r.flatpage=fp
r.title=fp.title
r.content_source=self.cleaned_data["content_md"]
r.updated=datetime.now()
r.save()
return fp

class FlatPageMetaAdmin(admin.ModelAdmin):
list_display = ('flatpage','created',)
list_filter = ('flatpage',)
Expand All @@ -43,7 +71,7 @@ class ImageInline(admin.TabularInline):

class FlatPageAdmin(StockFlatPageAdmin):
fieldsets= (
(None, {'fields': ('url', 'title', 'content', 'template_name',)}),
(None, {'fields': ('url', 'title', 'content_md', 'content','template_name',)}),
(_('Advanced options'), {'classes': ('collapse',),
'fields': ('enable_comments', 'registration_required','sites' )}),
)
Expand All @@ -58,4 +86,5 @@ def save_form(self, request, form, change):

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)
admin.site.register(FlatPageImage)
admin.site.register(FlatPageImage)
admin.site.register(Revision)
1 change: 0 additions & 1 deletion flatpages_x/models.py
Expand Up @@ -47,7 +47,6 @@ class Revision(models.Model):
content_source= models.TextField()

updated = models.DateTimeField(default=datetime.now)
published = models.DateTimeField(null=True, blank=True)

view_count = models.IntegerField(default=0, editable=False)

Expand Down
4 changes: 3 additions & 1 deletion flatpages_x/settings.py
@@ -1,7 +1,9 @@
from django.conf import settings

PARSER = getattr(settings, "FLATPAGES_X_PARSER", ["flatpages_x.markdown_parser.parse", {}])
DEFAULT_TEMPLATE_CHOICES=[
('flatpages/default.html','Text Only',),
]
FPX_TEMPLATE_CHOICES=getattr(settings,'FLATPAGE_X_TEMPLATE_CHOICES',DEFAULT_TEMPLATE_CHOICES)
FPX_TEMPLATE_CHOICES=getattr(settings,'FLATPAGES_X_TEMPLATE_CHOICES',DEFAULT_TEMPLATE_CHOICES)


6 changes: 6 additions & 0 deletions flatpages_x/templatetags/flatpagesx_tags.py
@@ -0,0 +1,6 @@
from django import template
from django.contrib.flatpages.models import FlatPage
from flatpages_x.models import FlatPageMeta,FlatPageImage

register = template.Library()

51 changes: 0 additions & 51 deletions flatpages_x/templatetags/flatpagex_tags.py

This file was deleted.

0 comments on commit 10aab41

Please sign in to comment.