parent
e32382f411
commit
d6307273a8
|
@ -1,11 +1,24 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .rbac import Role
|
||||
from .. import fields
|
||||
|
||||
class StatusManager(models.Manager):
|
||||
def get_after_start_statuses(self):
|
||||
start_ids = set(self.filter(start=True).values_list('id', flat=True))
|
||||
transitions = Transition.objects.values_list('source_id', 'destination_id')
|
||||
while True:
|
||||
last_len = len(start_ids)
|
||||
for a, b in transitions:
|
||||
if a in start_ids:
|
||||
start_ids.add(b)
|
||||
if len(start_ids) == last_len:
|
||||
break
|
||||
return self.filter(id__in=start_ids)
|
||||
|
||||
|
||||
class Status(models.Model):
|
||||
class Meta:
|
||||
app_label = 'base'
|
||||
|
@ -15,6 +28,8 @@ class Status(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
objects = StatusManager()
|
||||
|
||||
code = models.CharField(max_length=40, unique=True, verbose_name=_(u'Code statut'))
|
||||
visible = models.BooleanField(verbose_name=_('Visible dans les listings'),
|
||||
blank=True, default=True)
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.core.cache import cache
|
|||
from django.shortcuts import render
|
||||
from django.utils.timezone import utc
|
||||
|
||||
from ..base.models import Request
|
||||
from ..base.models import Request, Status
|
||||
|
||||
import app_settings
|
||||
|
||||
|
@ -56,6 +56,7 @@ record_templates_by_prefix = {
|
|||
|
||||
def queryset():
|
||||
return Request.objects.filter(
|
||||
status__in=Status.objects.get_after_start_statuses(),
|
||||
licence__diffusion_tags__contains='oai-pmh') \
|
||||
.exclude(uploadfile='')
|
||||
|
||||
|
|
Reference in New Issue