blob: e81572111d39a88fe177fd6ec863163730c35141 [file] [log] [blame]
Scott Baker307e06f2013-05-21 17:25:56 -07001import os
2from django.db import models
3from core.models import PlCoreBase
4from core.models import Slice
5
6class SliceTag(PlCoreBase):
Siobhan Tullyde5450d2013-06-21 11:35:33 -04007 slice = models.ForeignKey(Slice, related_name='slicetags')
Scott Baker307e06f2013-05-21 17:25:56 -07008
9 NAME_CHOICES = (('privatekey', 'Private Key'), ('publickey', 'Public Key'))
10 name = models.CharField(help_text="The name of this tag", max_length=30, choices=NAME_CHOICES)
11 value = models.CharField(help_text="The value of this tag", max_length=1024)
12
Tony Mack5b061472014-02-04 07:57:10 -050013 def can_update(self, user):
14 return self.slice.can_update(user)
Scott Baker307e06f2013-05-21 17:25:56 -070015
Tony Mack5b061472014-02-04 07:57:10 -050016 def save_by_user(self, user, *args, **kwds):
17 if self.can_update(user):
18 super(SliceTag, self).save(*args, **kwds)
Scott Baker307e06f2013-05-21 17:25:56 -070019
Tony Mack5b061472014-02-04 07:57:10 -050020 @staticmethod
21 def select_by_user(user):
22 if user.is_admin:
23 qs = SliceTag.objects.all()
24 else:
25 st_ids = [st.id for st in SliceTag.objects.filter(user=user)]
26 qs = SliceTag.objects.filter(id__in=st_ids)
27 return qs