Changeset b700a542579c454e95ffd5ad0ee72eaeb8df7f77


Ignore:
Timestamp:
14.05.2013 22:21:25 (6 years ago)
Author:
Stanislaw Klekot <dozzie@…>
Branches:
b66903eafbcb1d49112014abc82c8bf683413db0
Children:
c30ccdb2652da65b328253916e36c499ffdef963
Parents:
1d2904b4ec5ff4b9cf8602f686852509140097e0
git-author:
Stanislaw Klekot <dozzie@…> (14.05.2013 22:21:25)
git-committer:
Stanislaw Klekot <dozzie@…> (14.05.2013 22:21:25)
Message:

Added WikiPage?.content_tree attribute.

The attribute gets defined on save.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dashwiki/wiki/models.py

    rf0f020 rb700a5  
    22 
    33from django.db import models 
     4from django.db.models import signals 
    45 
    56#----------------------------------------------------------------------------- 
     
    89  name = models.CharField(max_length = 256, primary_key = True) 
    910  content = models.TextField() 
     11  content_tree = models.TextField() 
     12 
     13  @staticmethod 
     14  def signal_set_content(sender, instance, *args, **kwargs): 
     15    instance.set_content() 
     16 
     17  # XXX: might throw dashwiki.markup.ParseError 
     18  def set_content(self, content = None): 
     19    if content != None: 
     20      self.content = content 
     21 
     22    from dashwiki.markup import Lexer, Parser 
     23    lexer  = Lexer(self.content.replace('\r', '')) 
     24    parser = Parser() 
     25    syntax_tree = parser.parse(lexer) 
     26 
     27    import json 
     28    from django.conf import settings 
     29    self.content_tree = json.dumps(syntax_tree) 
    1030 
    1131  def __unicode__(self): 
    1232    return self.name 
     33 
     34signals.pre_save.connect(WikiPage.signal_set_content, sender = WikiPage) 
    1335 
    1436#----------------------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.