X-Git-Url: https://git.mdrn.pl/cas.git/blobdiff_plain/5c901ee485c3abdf11dec71bdb7534f1f6a9eaa9..21765da5d86c0c20f785523ac5839c14e89f1237:/src/services/models.py?ds=inline diff --git a/src/services/models.py b/src/services/models.py index 6e945ce..c7a5d97 100644 --- a/src/services/models.py +++ b/src/services/models.py @@ -1,22 +1,31 @@ +import secrets from django.conf import settings from django.contrib.auth.models import User from django.db import models +from django.utils.translation import ugettext_lazy as _ class Service(models.Model): - name = models.CharField(max_length=255) - url = models.URLField(blank=True) - key = models.CharField(max_length=255, blank=True) - uses_ssh = models.BooleanField(default=False) - groups = models.ManyToManyField('auth.Group', blank=True) - users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True) + name = models.CharField(_('name'), max_length=255) + url = models.URLField(_('URL'), blank=True) + key = models.CharField(_('key'), max_length=255, blank=True) + uses_ssh = models.BooleanField(_('uses SSH'), default=False) + groups = models.ManyToManyField('auth.Group', verbose_name=_('groups'), blank=True) + users = models.ManyToManyField(settings.AUTH_USER_MODEL, verbose_name=_('users'), blank=True) class Meta: ordering = ('name', ) + verbose_name = _('service') + verbose_name_plural = _('services') def __str__(self): return self.name + def save(self, *args, **kwargs): + if not self.key: + self.key = secrets.token_urlsafe() + return super().save(*args, **kwargs) + def all_users(self): return User.objects.filter( models.Q(service=self) |