diff options
Diffstat (limited to 'equations/models.py')
-rw-r--r-- | equations/models.py | 115 |
1 files changed, 38 insertions, 77 deletions
diff --git a/equations/models.py b/equations/models.py index ca68ba7..9b8a38d 100644 --- a/equations/models.py +++ b/equations/models.py @@ -1,111 +1,78 @@ -from django.db import models +#from django.db import models from django.utils.translation import gettext_lazy as _ import django.contrib.auth.models as auth from django.conf import settings from django.dispatch import dispatcher -from django.db.models import signals -from signals import update_render +#from django.db.models import signals +#from signals import update_render +from appengine_django.models import BaseModel +from google.appengine.ext import db -class Symbol(models.Model): - name = models.CharField(_("Name")) - latex = models.TextField(_("Raw LaTeX"), unique=True) - unicode = models.TextField(_("Unicode Representation"), blank=True) - renderdir = "symbolrenders/" - render = models.ImageField(_("Rendered Image"), - upload_to=renderdir, editable=False) + +class Symbol(BaseModel): + name = db.StringProperty(_("Name")) + latex = db.TextProperty(_("Raw LaTeX")) + unicode = db.TextProperty(_("Unicode Representation")) + #renderdir = "symbolrenders/" + #render = models.ImageField(_("Rendered Image"), + #upload_to=renderdir, editable=False) class Meta: get_latest_by = 'name' class Admin: ordering = ['name'] - + + def _get_pk_val(self): + return self.key().id() def __str__(self): return self.name def get_absolute_url(self): return "/symbol/%s/" % self.id def get_admin_url(self): return "/admin/symbols/%s/" % self.id - #def save(self): - # super(Symbol, self) - # self.update_generic_variable() - def save(self): - super(Symbol, self).save() - self.render = self.renderdir + "%s.png" % self.id - super(Symbol, self).save() - -#signals.pre_save.connect(update_render, sender=Symbol) -#dispatcher.connect(update_render, signal=signals.pre_save, sender=Symbol) -def update_generic_variable(sender, instance, signal, *args, **kwargs): - """Checks if there is a generic variable associated with this - symbol; create one if there isn't""" - for v in Variable.objects.filter(isgeneric=True): - if v.latex == instance.latex: - return - genericv = Variable(name="Generic %s" % instance.name, - latex=instance.latex, - unicode=instance.unicode, - symbol=instance, - isgeneric=True) - genericv.save() - -#signals.pre_save.connect(update_render, sender=Symbol) -#signals.post_save.connect(update_generic_variable, sender=Symbol) -#dispatcher.connect(update_render, signal=signals.pre_save, sender=Symbol) -#dispatcher.connect(update_generic_variable, signal=signals.post_save, -# sender=Symbol) - -class Variable(models.Model): - name = models.CharField(_("Name")) - latex = models.TextField(_("Raw LaTeX"), unique=True) - unicode = models.TextField(_("Unicode Representation"), blank=True) - description = models.TextField(_("Description"), blank=True) - renderdir = "variablerenders/" - render = models.ImageField(_("Rendered Image"), - upload_to=renderdir, editable=False) - reference = models.URLField(_("Reference URL"), blank=True) - symbol = models.ForeignKey(Symbol, verbose_name=_("Symbol")) - isgeneric = models.BooleanField(_("Is Generic?"), default=False) +class Variable(BaseModel): + name = db.StringProperty(_("Name")) + latex = db.TextProperty(_("Raw LaTeX")) + unicode = db.TextProperty(_("Unicode Representation")) + description = db.TextProperty(_("Description")) + reference = db.TextProperty(_("Reference URL")) + symbol = db.ReferenceProperty(Symbol) + isgeneric = db.BooleanProperty(_("Is Generic?"), default=False) class Meta: get_latest_by = 'name' class Admin: ordering = ['name'] + def _get_pk_val(self): + return self.key().id() def __str__(self): return self.name def get_absolute_url(self): return "/variable/%s/" % self.id def get_admin_url(self): return "/admin/variables/%s/" % self.id - def save(self): - super(Variable, self).save() - self.render = self.renderdir + "%s.png" % self.id - super(Variable, self).save() -#signals.pre_save.connect(update_render, sender=Variable) -#dispatcher.connect(update_render, signal=signals.pre_save, sender=Variable) +class Equation(BaseModel): + name = db.StringProperty(_("Name")) + latex = db.TextProperty(_("Raw LaTeX")) + unicode = db.TextProperty(_("Unicode Representation")) + description = db.TextProperty(_("Description")) + created = db.DateTimeProperty(_("Created"), auto_now_add=True) + updated = db.DateTimeProperty(_("Last Updated"), auto_now_add=True) + #owner = models.ForeignKey(auth.User, verbose_name=_("Owner")) -class Equation(models.Model): - name = models.CharField(_("Name")) - latex = models.TextField(_("Raw LaTeX"), unique=True) - unicode = models.TextField(_("Unicode Representation"), blank=True) - description = models.TextField(_("Description"), blank=True) - created = models.DateField(_("Created"), auto_now_add=True) - updated = models.DateField(_("Last Updated"), auto_now_add=True) - owner = models.ForeignKey(auth.User, verbose_name=_("Owner")) - variables = models.ManyToManyField(Variable, verbose_name="Variables", - editable=True) - renderdir = "equationrenders/" - render = models.ImageField(_("Rendered Image"), - upload_to=renderdir, editable=False) - reference = models.URLField(_("Reference URL"), blank=True) + variables = db.ListProperty(db.Key, verbose_name="Variables") + reference = db.TextProperty(_("Reference URL")) class Meta: get_latest_by = 'created' class Admin: ordering = ['created'] + def _get_pk_val(self): + return self.key().id() def __str__(self): return self.name def get_absolute_url(self): @@ -116,11 +83,6 @@ class Equation(models.Model): """Updates the variables field with all Variable objects found in the LaTeX representation.""" pass # TODO: write - def save(self): - self.update_variables() - super(Equation, self).save() - self.render = self.renderdir + "%s.png" % self.id - super(Equation, self).save() #signals.post_save.connect(update_render, sender=Equation) #dispatcher.connect(update_render, signal=signals.post_save, sender=Equation) @@ -130,4 +92,3 @@ class Equation(models.Model): #admin.site.register(Symbol) #admin.site.register(Variable) #admin.site.register(Equation) - |