aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/models.py
diff options
context:
space:
mode:
authorJessica Tallon <jessica@megworld.co.uk>2014-10-21 11:57:15 +0100
committerJessica Tallon <jessica@megworld.co.uk>2014-10-21 11:57:15 +0100
commit44c53d3bc41e68f4320b7b80ec059a560557a441 (patch)
tree54025eb08a3611a7da233749caa65f366c55938b /mediagoblin/db/models.py
parent4f1a34b84d53bffaa14a49c03a2d906fcac649e2 (diff)
parent5ddc85e071fd7adec6b922a03c2e8caa4bad3c5c (diff)
downloadmediagoblin-44c53d3bc41e68f4320b7b80ec059a560557a441.tar.lz
mediagoblin-44c53d3bc41e68f4320b7b80ec059a560557a441.tar.xz
mediagoblin-44c53d3bc41e68f4320b7b80ec059a560557a441.zip
Merge branch '984-ai-improvements'
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r--mediagoblin/db/models.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index b1bdba88..294200d8 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -26,7 +26,7 @@ import datetime
from sqlalchemy import Column, Integer, Unicode, UnicodeText, DateTime, \
Boolean, ForeignKey, UniqueConstraint, PrimaryKeyConstraint, \
SmallInteger, Date
-from sqlalchemy.orm import relationship, backref, with_polymorphic
+from sqlalchemy.orm import relationship, backref, with_polymorphic, validates
from sqlalchemy.orm.collections import attribute_mapped_collection
from sqlalchemy.sql.expression import desc
from sqlalchemy.ext.associationproxy import association_proxy
@@ -1240,11 +1240,11 @@ class ActivityIntermediator(Base):
if key is None:
raise ValueError("Invalid type of object given")
- # We need to save so that self.id is populated
self.type = key
- self.save()
- # First set self as activity
+ # We need to populate the self.id so we need to save but, we don't
+ # want to save this AI in the database (yet) so commit=False.
+ self.save(commit=False)
obj.activity = self.id
obj.save()
@@ -1256,10 +1256,11 @@ class ActivityIntermediator(Base):
model = self.TYPES[self.type]
return model.query.filter_by(activity=self.id).first()
- def save(self, *args, **kwargs):
- if self.type not in self.TYPES.keys():
- raise ValueError("Invalid type set")
- Base.save(self, *args, **kwargs)
+ @validates("type")
+ def validate_type(self, key, value):
+ """ Validate that the type set is a valid type """
+ assert value in self.TYPES
+ return value
class Activity(Base, ActivityMixin):
"""