Revision c4028837 snf-astakos-app/astakos/im/functions.py
b/snf-astakos-app/astakos/im/functions.py | ||
---|---|---|
573 | 573 |
|
574 | 574 |
def submit_application(owner=None, |
575 | 575 |
name=None, |
576 |
precursor_id=None,
|
|
576 |
project_id=None,
|
|
577 | 577 |
homepage=None, |
578 | 578 |
description=None, |
579 | 579 |
start_date=None, |
... | ... | |
585 | 585 |
resource_policies=None, |
586 | 586 |
request_user=None): |
587 | 587 |
|
588 |
precursor = None
|
|
589 |
if precursor_id is not None:
|
|
590 |
get_chain_of_application_for_update(precursor_id)
|
|
591 |
precursor = ProjectApplication.objects.get(id=precursor_id)
|
|
588 |
project = None
|
|
589 |
if project_id is not None:
|
|
590 |
get_chain_for_update(project_id)
|
|
591 |
project = Project.objects.get(id=project_id)
|
|
592 | 592 |
|
593 | 593 |
if (request_user and |
594 |
(not precursor.owner == request_user and
|
|
594 |
(not project.application.owner == request_user and
|
|
595 | 595 |
not request_user.is_superuser |
596 | 596 |
and not request_user.is_project_admin())): |
597 | 597 |
m = _(astakos_messages.NOT_ALLOWED) |
598 | 598 |
raise PermissionDenied(m) |
599 | 599 |
|
600 | 600 |
force = request_user.is_project_admin() |
601 |
ok, limit = qh_add_pending_app(owner, precursor, force)
|
|
601 |
ok, limit = qh_add_pending_app(owner, project, force)
|
|
602 | 602 |
if not ok: |
603 | 603 |
m = _(astakos_messages.REACHED_PENDING_APPLICATION_LIMIT) % limit |
604 | 604 |
raise PermissionDenied(m) |
... | ... | |
607 | 607 |
applicant=request_user, |
608 | 608 |
owner=owner, |
609 | 609 |
name=name, |
610 |
precursor_application_id=precursor_id, |
|
611 | 610 |
homepage=homepage, |
612 | 611 |
description=description, |
613 | 612 |
start_date=start_date, |
... | ... | |
617 | 616 |
limit_on_members_number=limit_on_members_number, |
618 | 617 |
comments=comments) |
619 | 618 |
|
620 |
if precursor is None:
|
|
619 |
if project is None:
|
|
621 | 620 |
chain = new_chain() |
622 | 621 |
application.chain_id = chain.chain |
623 | 622 |
application.save() |
624 | 623 |
Project.objects.create(id=chain.chain, application=application) |
625 | 624 |
else: |
626 |
chain = precursor.chain |
|
627 |
application.chain = chain |
|
625 |
application.chain = project |
|
628 | 626 |
application.save() |
629 |
if chain.application.state != ProjectApplication.APPROVED:
|
|
630 |
chain.application = application
|
|
631 |
chain.save()
|
|
627 |
if project.application.state != ProjectApplication.APPROVED:
|
|
628 |
project.application = application
|
|
629 |
project.save()
|
|
632 | 630 |
|
633 | 631 |
pending = ProjectApplication.objects.filter( |
634 |
chain=chain,
|
|
632 |
chain=project,
|
|
635 | 633 |
state=ProjectApplication.PENDING).exclude(id=application.id) |
636 | 634 |
for app in pending: |
637 | 635 |
app.state = ProjectApplication.REPLACED |
... | ... | |
816 | 814 |
return usage |
817 | 815 |
|
818 | 816 |
|
819 |
def get_pending_app_diff(user, precursor):
|
|
820 |
if precursor is None:
|
|
817 |
def get_pending_app_diff(user, project):
|
|
818 |
if project is None:
|
|
821 | 819 |
diff = 1 |
822 | 820 |
else: |
823 |
chain = precursor.chain |
|
824 | 821 |
objs = ProjectApplication.objects |
825 |
q = objs.filter(chain=chain, state=ProjectApplication.PENDING)
|
|
822 |
q = objs.filter(chain=project, state=ProjectApplication.PENDING)
|
|
826 | 823 |
count = q.count() |
827 | 824 |
diff = 1 - count |
828 | 825 |
return diff |
829 | 826 |
|
830 | 827 |
|
831 |
def qh_add_pending_app(user, precursor=None, force=False):
|
|
828 |
def qh_add_pending_app(user, project=None, force=False):
|
|
832 | 829 |
user = AstakosUser.forupdate.get_for_update(id=user.id) |
833 |
diff = get_pending_app_diff(user, precursor)
|
|
830 |
diff = get_pending_app_diff(user, project)
|
|
834 | 831 |
return register_pending_apps(user, diff, force) |
835 | 832 |
|
836 | 833 |
|
837 |
def check_pending_app_quota(user, precursor=None):
|
|
838 |
diff = get_pending_app_diff(user, precursor)
|
|
834 |
def check_pending_app_quota(user, project=None):
|
|
835 |
diff = get_pending_app_diff(user, project)
|
|
839 | 836 |
quota = get_pending_app_quota(user) |
840 | 837 |
limit = quota['limit'] |
841 | 838 |
usage = quota['usage'] |
Also available in: Unified diff