blob: 1cd0e401a4ebfc1a79ad73d5cb9941b274f830d2 [file] [log] [blame]
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001import os
2from django.db import models
Siobhan Tully30fd4292013-05-10 08:59:56 -04003from core.models import PlCoreBase
Tony Mackd893dfb2015-02-05 06:13:04 -05004from core.models import Site, SiteDeployment, SitePrivilege
Siobhan Tullyde5450d2013-06-21 11:35:33 -04005from core.models import Tag
6from django.contrib.contenttypes import generic
Siobhan Tully4bc09f22013-04-10 21:15:21 -04007
8# Create your models here.
9
10class Node(PlCoreBase):
11 name = models.CharField(max_length=200, unique=True, help_text="Name of the Node")
Tony Macka7dbd422015-01-05 22:48:11 -050012 site_deployment = models.ForeignKey(SiteDeployment, related_name='nodes')
Tony Mack82df1d02015-01-14 20:58:38 -050013 site = models.ForeignKey(Site, null=True, blank=True, related_name='nodes')
Siobhan Tullyde5450d2013-06-21 11:35:33 -040014 tags = generic.GenericRelation(Tag)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040015
16 def __unicode__(self): return u'%s' % (self.name)
Sapan Bhatia690f8032014-06-13 12:50:36 -040017
Tony Mack82df1d02015-01-14 20:58:38 -050018 def save(self, *args, **kwds):
19 if self.site is None and self.site_deployment is not None:
20 self.site = self.site_deployment.site
21
22 super(Node, self).save(*args, **kwds)
Tony Mackd893dfb2015-02-05 06:13:04 -050023
24 def can_update(self, user):
25 if user.is_readonly:
26 return False
27 if user.is_admin:
28 return True
29 if SitePrivilege.objects.filter(
30 user=user, site=self.site, role__role__in=['admin','tech']):
31 return True
32
33 return False