Example of how to disassociate an object from a collection, to be generalized later!

This commit is contained in:
Michael DeHaan
2013-03-22 14:48:18 -04:00
parent d179c91537
commit ed6096216f
3 changed files with 40 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ from django.db import models
from django.db.models import CASCADE, SET_NULL, PROTECT
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
import exceptions
# TODO: jobs and events model TBD
# TODO: reporting model TBD
@@ -29,6 +30,9 @@ class CommonModel(models.Model):
def __unicode__(self):
return unicode(self.name)
def can_user_administrate(self, user):
raise exceptions.NotImplementedError()
class Tag(models.Model):
'''
@@ -173,6 +177,14 @@ class Project(CommonModel):
import lib.urls
return reverse(lib.urls.views_ProjectsDetail, args=(self.pk,))
def can_user_administrate(self, user):
organizations = Organization.filter(admins__in = [ user ])
organizations = self.organizations()
for org in organizations:
if org in project.organizations():
return True
return True
class Permission(CommonModel):
'''
A permission allows a user, project, or team to be able to use an inventory source.