Commits

Jacob Smullyan  committed 7ff38e3

use a proxy object to add as the help_text attribute of registered
models, so that changes are reflected immediately even in multiprocess
environments.

  • Participants
  • Parent commits 558f65a

Comments (0)

Files changed (1)

File helptext/models.py

                                         field_name=field.name)
             if fh:
                 fh=fh[0]
-                field.help_text=fh.help_text
+                field.help_text=FieldHelpProxy(fh)
             else:
                 fh=FieldHelp(content_type=content_type,
                              field_name=field.name,
                 fh.save()
 
 
+class FieldHelpProxy(object):
+    def __init__(self, fh):
+        self.content_type_id=fh.content_type_id
+        self.field_name=fh.field_name
+
+    def __unicode__(self):
+        try:
+            fh=FieldHelp.get(content_type_id=self.content_type_id,
+                             field_name=self.field_name)
+        except FieldHelp.DoesNotExist:
+            # shouldn't happen
+            return ''
+        else:
+            return fh.help_text 
+
 class FieldHelp(models.Model):
     content_type=models.ForeignKey(ContentType)
     field_name=models.CharField(max_length=120)