Starting to defer some business logic to the model classes and out of the views.

This commit is contained in:
Michael DeHaan
2013-03-22 15:36:59 -04:00
parent 6b61381e32
commit d338794ec2
3 changed files with 15 additions and 5 deletions

View File

@@ -31,8 +31,12 @@ class CommonModel(models.Model):
def __unicode__(self):
return unicode(self.name)
def can_user_administrate(self, user):
def can_user_administrate(cls, user):
raise exceptions.NotImplementedError()
def can_user_delete(cls, user, obj):
return user in obj.admins.all()
class Tag(models.Model):
'''
@@ -81,6 +85,9 @@ class Organization(CommonModel):
import lib.urls
return reverse(lib.urls.views_OrganizationsDetail, args=(self.pk,))
def can_user_delete(cls, user, obj):
return user in obj.admins.all()
class Inventory(CommonModel):
'''
an inventory source contains lists and hosts.