changeset 6:37be5ab15cea

Added personas as an app to PersonasBackend. Also unified the RevisionHistory model into Persona.
author Atul Varma <varmaa@toolness.com>
date Thu, 14 Feb 2008 17:58:31 -0600
parents 71e36431fa7c
children 0eed448723cb
files PersonasBackend/personas/models.py PersonasBackend/settings.py
diffstat 2 files changed, 58 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/PersonasBackend/personas/models.py	Thu Feb 14 16:18:41 2008 -0600
+++ b/PersonasBackend/personas/models.py	Thu Feb 14 17:58:31 2008 -0600
@@ -1,36 +1,71 @@
 from django.db import models
 
+def commitRevision( persona, user, changes ):
+    """
+    Commit changes to a persona as a user.
+
+    'persona' is the Persona object being changed.
+
+    'user' is the User object making the changes.
+
+    'changes' is a dictionary whose keys are the names of attributes
+    in 'persona' to change, with their new values.
+    """
+
+    delta = {}
+
+    for attr in changes:
+        origValue = getattr( persona, attr )
+        newValue = changes[attr]
+        if origValue != newValue:
+            delta[attr] = origValue
+    # TODO: Finish this.
+
 class User(models.Model):
     name = models.CharField(
         "Name of the user",
-        help_text="This is the user's Mozilla ID."
+        maxlength=100,
+        help_text="This is the user's Mozilla ID.",
         )
 
 class Category(models.Model):
     name = models.CharField(
         "Category name",
-        maxlength=50
+        maxlength=50,
         )
 
 class Persona(models.Model):
     name = models.CharField(
-        "Title of the Persona"
+        "Title of the Persona",
         maxlength=50,
+        null=True,
+        )
+
+    revision_of = models.ForeignKey(
+        "self",
+        verbose_name="The Persona that this record is an old revision of",
+        null=True,
+        related_name="revisions",
         )
 
     category = models.ForeignKey(
         Category,
-        verbose_name="Category that the Persona will be filed under",
+        verbose_name="Category that the Persona is filed under",
+        null=True,
+        related_name="personas",
         )
 
     creator = models.ForeignKey(
         User,
-        verbose_name="Creator of the Persona"
+        verbose_name="Creator of the Persona",
+        null=True,
+        related_name="created_personas",
         )
 
     description = models.TextField(
         "Description of the Persona",
         help_text = "HTML is allowed.",
+        null=True,
         )
 
     header_img = models.URLField(
@@ -39,7 +74,7 @@
                    "the browser's top chrome.  Only needs to be "
                    "provided if no URL for the Persona is supplied."),
         verify_exists=True,
-        blank=True,
+        null=True,
         )
 
     footer_img = models.URLField(
@@ -48,7 +83,7 @@
                    "the browser's bottom chrome.  Only needs to be "
                    "provided if no URL for the Persona is supplied."),
         verify_exists=True,
-        blank=True,
+        null=True,
         )
 
     url = models.URLField(
@@ -57,16 +92,16 @@
                    "if no header/footer image for the Persona is "
                    "supplied."),
         verify_exists=True,
-        blank=True,
+        null=True,
         )
 
     update_interval = models.TimeField(
-        "Update interval for the Persona's URL"
+        "Update interval for the Persona's URL",
         help_text=("The time interval between which the Persona's "
                     "URL will be refreshed.  This field only needs to "
                     "be provided if the URL for the Persona is "
                     "supplied."),
-        blank=True,
+        null=True,
         )
 
     color_scheme = models.CharField(
@@ -74,59 +109,36 @@
         help_text=("If 'light', any text displayed over the "
                    "Persona will be dark.  If 'dark', any text "
                    "displayed over the Persona will be light."),
+        maxlength=5,
         choices=(("light", "Light"),
                  ("dark", "Dark")),
-        )
-
-    date_created = models.DateTimeField(
-        "Creation timestamp",
-        auto_now_add=True,
+        null=True,
         )
 
     date_updated = models.DateTimeField(
-        "Last-update timestamp",
+        "Update date for this revision",
         auto_now=True,
+        null=True,
         )
 
     updater = models.ForeignKey(
         User,
-        verbose_name="User who made the most recent revision"
+        verbose_name="User who made this revision",
+        null=True,
+        related_name="updated_personas",
         )
 
     revision = models.PositiveIntegerField(
-        "Latest revision of the Persona",
+        "Revision number for the Persona",
         help_text=("This number is incremented whenever the Persona "
                    "is changed."),
+        null=True,
         )
 
     status = models.CharField(
         "Current status of the Persona",
+        maxlength=10,
         choices=(("published", "Published"),
-                 ("deleted", "Deleted"))
-        )
-
-class RevisionHistory(models.Model):
-    persona = models.ForeignKey(
-        Persona,
-        verbose_name="Persona that the revision describes",
-        )
-
-    number = models.PositiveIntegerField(
-        ("The revision number of the Persona that this revision "
-         "describes"),
+                 ("deleted", "Deleted")),
+        null=True,
         )
-
-    user = models.ForeignKey(
-        User,
-        verbose_name="User who made the change",
-        )
-
-    date = models.DateTimeField(
-        "Timestamp of the revision's creation"
-        )
-
-    delta = models.TextField(
-        "Delta from next revision",
-        help_text=("Textual representation of the changes in "
-                   "this revision from the revision succeeding it.")
-        )
--- a/PersonasBackend/settings.py	Thu Feb 14 16:18:41 2008 -0600
+++ b/PersonasBackend/settings.py	Thu Feb 14 17:58:31 2008 -0600
@@ -79,4 +79,5 @@
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.sites',
+    'PersonasBackend.personas',
 )