Scott Baker | 307e06f | 2013-05-21 17:25:56 -0700 | [diff] [blame] | 1 | import os |
| 2 | from django.db import models |
| 3 | from core.models import PlCoreBase |
| 4 | from core.models import Slice |
| 5 | |
| 6 | class SliceTag(PlCoreBase): |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 7 | slice = models.ForeignKey(Slice, related_name='slicetags') |
Scott Baker | 307e06f | 2013-05-21 17:25:56 -0700 | [diff] [blame] | 8 | |
| 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 Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 13 | def can_update(self, user): |
| 14 | return self.slice.can_update(user) |
Scott Baker | 307e06f | 2013-05-21 17:25:56 -0700 | [diff] [blame] | 15 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 16 | @staticmethod |
| 17 | def select_by_user(user): |
| 18 | if user.is_admin: |
| 19 | qs = SliceTag.objects.all() |
| 20 | else: |
| 21 | st_ids = [st.id for st in SliceTag.objects.filter(user=user)] |
| 22 | qs = SliceTag.objects.filter(id__in=st_ids) |
| 23 | return qs |