Changeset 4003d9047056faffc3b5064437ecf62888898467


Ignore:
Timestamp:
25.05.2013 17:44:43 (6 years ago)
Author:
Stanislaw Klekot <dozzie@…>
Branches:
b66903eafbcb1d49112014abc82c8bf683413db0
Children:
93ca6ca4c7fe9b546c4f2872146f83116b9f70d1
Parents:
7ae4d231d9963c4e2b6359e56ff8c47272db0583
git-author:
Stanislaw Klekot <dozzie@…> (25.05.2013 17:44:43)
git-committer:
Stanislaw Klekot <dozzie@…> (25.05.2013 17:44:43)
Message:

Added WikiHistoryPage? to models.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dashwiki/wiki/models.py

    ra2f66c r4003d9  
    33from django.db import models 
    44from django.db.models import signals 
     5from django.contrib.auth.models import User 
    56 
    67#----------------------------------------------------------------------------- 
     
    3637      return None 
    3738 
     39  def make_revision(self, author, is_delete = False): 
     40    previous = WikiHistoryPage.objects.filter(name = self.name) 
     41    if previous.exists(): 
     42      prev_rev = previous.order_by('-revision')[0].revision 
     43    else: 
     44      prev_rev = 0 
     45 
     46    new_revision = WikiHistoryPage( 
     47      name     = self.name, 
     48      author   = author, 
     49      revision = prev_rev + 1, 
     50    ) 
     51    if is_delete: 
     52      new_revision.content = None 
     53      new_revision.content_tree = None 
     54    else: 
     55      new_revision.content = self.content 
     56      new_revision.content_tree = self.content_tree 
     57 
     58    return new_revision 
     59 
    3860  def __unicode__(self): 
    3961    return self.name 
    4062 
    4163signals.pre_save.connect(WikiPage.signal_set_content, sender = WikiPage) 
     64 
     65#----------------------------------------------------------------------------- 
     66 
     67class WikiHistoryPage(models.Model): 
     68  # the same as for WikiPage, except for primary key 
     69  # FIXME: shouldn't it be inherited? 
     70  name          = models.CharField(max_length = 256) 
     71  content       = models.TextField(null = True) 
     72  content_tree  = models.TextField(null = True) 
     73 
     74  # history data 
     75  author        = models.ForeignKey(User) 
     76  creation_time = models.DateTimeField(auto_now_add = True) 
     77  revision      = models.IntegerField() 
     78 
     79  def __unicode__(self): 
     80    return "%s@%d" % (self.name, self.revision) 
    4281 
    4382#----------------------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.