1# Copyright (c) 2012-2016 Seafile Ltd.
2from django.db import models
3from django.utils import timezone
4
5from seahub.base.fields import LowerCaseCharField
6
7class InstitutionManager(models.Manager):
8    def add_institution(self, name):
9        institution = super(InstitutionManager, self).create(name=name)
10        institution.save()
11
12        return institution
13
14class Institution(models.Model):
15    name = models.CharField(max_length=200)
16    create_time = models.DateTimeField(default=timezone.now)
17    objects = InstitutionManager()
18
19class InstitutionAdmin(models.Model):
20    institution = models.ForeignKey(Institution, on_delete=models.CASCADE)
21    user = LowerCaseCharField(max_length=255, db_index=True)
22
23
24class InstitutionQuotaManager(models.Manager):
25    def get_or_none(self, *args, **kwargs):
26        try:
27            return self.get(*args, **kwargs).quota
28        except self.model.DoesNotExist:
29            return None
30
31
32class InstitutionQuota(models.Model):
33    institution = models.ForeignKey(Institution, on_delete=models.CASCADE)
34    quota = models.BigIntegerField()
35    objects = InstitutionQuotaManager()
36