Revision 3d4cef9e
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
812 | 812 |
quotas = copy.deepcopy(initial) |
813 | 813 |
|
814 | 814 |
objs = ProjectMembership.objects.select_related('application', 'person') |
815 |
memberships = objs.filter(person__in=users, is_active=True)
|
|
815 |
memberships = objs.filter(person__in=users) |
|
816 | 816 |
|
817 | 817 |
apps = set(m.application for m in memberships if m.application is not None) |
818 | 818 |
objs = ProjectResourceGrant.objects.select_related() |
... | ... | |
824 | 824 |
|
825 | 825 |
application = membership.application |
826 | 826 |
if application is None: |
827 |
m = _("missing application for active membership %s" |
|
828 |
% (membership,)) |
|
829 |
raise AssertionError(m) |
|
827 |
continue |
|
830 | 828 |
|
831 | 829 |
for grant in grants: |
832 | 830 |
if grant.project_application_id != application.id: |
... | ... | |
1849 | 1847 |
q = ~self.model.Q_TERMINATED |
1850 | 1848 |
return self.filter(q) |
1851 | 1849 |
|
1852 |
def terminating_projects(self): |
|
1853 |
q = self.model.Q_TERMINATED & Q(is_active=True) |
|
1854 |
return self.filter(q) |
|
1855 |
|
|
1856 | 1850 |
def deactivated_projects(self): |
1857 | 1851 |
q = self.model.Q_DEACTIVATED |
1858 | 1852 |
return self.filter(q) |
1859 | 1853 |
|
1860 |
def deactivating_projects(self): |
|
1861 |
q = self.model.Q_DEACTIVATED & Q(is_active=True) |
|
1862 |
return self.filter(q) |
|
1863 |
|
|
1864 | 1854 |
def modified_projects(self): |
1865 | 1855 |
return self.filter(is_modified=True) |
1866 | 1856 |
|
1867 |
def reactivating_projects(self): |
|
1868 |
return self.filter(state=Project.APPROVED, is_active=False) |
|
1869 |
|
|
1870 | 1857 |
def expired_projects(self): |
1871 | 1858 |
q = (~Q(state=Project.TERMINATED) & |
1872 | 1859 |
Q(application__end_date__lt=datetime.now())) |
... | ... | |
1941 | 1928 |
def state_display(self): |
1942 | 1929 |
return self.STATE_DISPLAY.get(self.state, _('Unknown')) |
1943 | 1930 |
|
1944 |
def admin_state_display(self): |
|
1945 |
s = self.state_display() |
|
1946 |
if self.sync_pending(): |
|
1947 |
s += ' (sync pending)' |
|
1948 |
return s |
|
1949 |
|
|
1950 |
def sync_pending(self): |
|
1951 |
if self.state != self.APPROVED: |
|
1952 |
return self.is_active |
|
1953 |
return not self.is_active or self.is_modified |
|
1954 |
|
|
1955 | 1931 |
def expiration_info(self): |
1956 | 1932 |
return (str(self.id), self.name, self.state_display(), |
1957 | 1933 |
str(self.application.end_date)) |
... | ... | |
1962 | 1938 |
|
1963 | 1939 |
return self.state != self.APPROVED |
1964 | 1940 |
|
1965 |
def is_deactivating(self, reason=None): |
|
1966 |
if not self.is_active: |
|
1967 |
return False |
|
1968 |
|
|
1969 |
return self.is_deactivated(reason) |
|
1970 |
|
|
1971 |
def is_deactivated_strict(self, reason=None): |
|
1972 |
if self.is_active: |
|
1973 |
return False |
|
1974 |
|
|
1975 |
return self.is_deactivated(reason) |
|
1976 |
|
|
1977 | 1941 |
### Deactivation calls |
1978 | 1942 |
|
1979 |
def unset_modified(self): |
|
1980 |
self.is_modified = False |
|
1981 |
self.save() |
|
1982 |
|
|
1983 |
def deactivate(self): |
|
1984 |
self.deactivation_date = datetime.now() |
|
1985 |
self.is_active = False |
|
1986 |
self.save() |
|
1987 |
|
|
1988 |
def reactivate(self): |
|
1989 |
self.deactivation_date = None |
|
1990 |
self.is_active = True |
|
1991 |
self.save() |
|
1992 |
|
|
1993 | 1943 |
def terminate(self): |
1994 | 1944 |
self.deactivation_reason = 'TERMINATED' |
1945 |
self.deactivation_date = datetime.now() |
|
1995 | 1946 |
self.state = self.TERMINATED |
1996 | 1947 |
self.name = None |
1997 | 1948 |
self.save() |
1998 | 1949 |
|
1999 | 1950 |
def suspend(self): |
2000 | 1951 |
self.deactivation_reason = 'SUSPENDED' |
1952 |
self.deactivation_date = datetime.now() |
|
2001 | 1953 |
self.state = self.SUSPENDED |
2002 | 1954 |
self.save() |
2003 | 1955 |
|
2004 | 1956 |
def resume(self): |
2005 | 1957 |
self.deactivation_reason = None |
1958 |
self.deactivation_date = None |
|
2006 | 1959 |
self.state = self.APPROVED |
2007 | 1960 |
self.save() |
2008 | 1961 |
|
Also available in: Unified diff