models.py 1.27 KB
Newer Older
Skia's avatar
Skia committed
1
2
3
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
Skia's avatar
Skia committed
4
from django.core.urlresolvers import reverse
Skia's avatar
Skia committed
5
6
7
8
9
10
11
12
13

from club.models import Club
from accounting.models import Product
from core.models import Group

class Counter(models.Model):
    name = models.CharField(_('name'), max_length=30)
    club = models.ForeignKey(Club, related_name="counters")
    products = models.ManyToManyField(Product, related_name="counters", blank=True)
Skia's avatar
Skia committed
14
15
16
    type = models.CharField(_('subscription type'),
            max_length=255,
            choices=[('BAR',_('Bar')), ('OFFICE',_('Office'))]) # TODO: add _ to translate
Skia's avatar
Skia committed
17
18
19
20
21
22
23
24
25
26
    edit_groups = models.ManyToManyField(Group, related_name="editable_counters", blank=True)
    view_groups = models.ManyToManyField(Group, related_name="viewable_counters", blank=True)

    def __getattribute__(self, name):
        if name == "owner_group":
            return Group(name=self.club.unix_name+"-board")
        return object.__getattribute__(self, name)

    def __str__(self):
        return self.name
Skia's avatar
Skia committed
27
28
29
30
31
32

    def get_absolute_url(self):
        return reverse('counter:details', kwargs={'counter_id': self.id})

    def can_be_viewed_by(self, user):
        return user.is_in_group(settings.AE_GROUPS['board']['name'])