Revision a75dbd7b

b/snf-astakos-app/astakos/im/functions.py
411 411
        raise IOError(
412 412
            _(astakos_messages.UNKNOWN_PROJECT_APPLICATION_ID) % project_application_id)
413 413

  
414
def get_related_project_id(application_id):
415
    try:
416
        app = ProjectApplication.objects.get(id=application_id)
417
        chain = app.chain
418
        project = Project.objects.get(id=chain)
419
        return chain
420
    except:
421
        return None
422

  
414 423
def get_project_by_id(project_id):
415 424
    try:
416 425
        return Project.objects.get(id=project_id)
b/snf-astakos-app/astakos/im/messages.py
193 193
APPLICATION_CANNOT_DENY                 =   "Cannot deny application %s in state '%s'"
194 194
APPLICATION_CANNOT_DISMISS              =   "Cannot dismiss application %s in state '%s'"
195 195
APPLICATION_CANNOT_CANCEL               =   "Cannot cancel application %s in state '%s'"
196
APPLICATION_CANCELLED                   =   "Your project request has been cancelled."
197

  
196 198

  
197 199
# Auth providers messages
198 200
AUTH_PROVIDER_NOT_ACTIVE                     =   "'%(provider)s' is disabled."
b/snf-astakos-app/astakos/im/models.py
1456 1456
            uplimit = p.get('uplimit', 0)
1457 1457
            self.add_resource_policy(service, resource, uplimit)
1458 1458

  
1459
    def pending_modifications(self):
1459
    def pending_modifications_incl_me(self):
1460 1460
        q = self.chained_applications()
1461
        q = q.filter(~Q(id=self.id) & Q(state=self.PENDING))
1462
        q = q.order_by('id')
1461
        q = q.filter(Q(state=self.PENDING))
1463 1462
        return q
1464 1463

  
1464
    def last_pending_incl_me(self):
1465
        try:
1466
            return self.pending_modifications_incl_me().order_by('-id')[0]
1467
        except IndexError:
1468
            return None
1469

  
1470
    def pending_modifications(self):
1471
        return self.pending_modifications_incl_me().filter(~Q(id=self.id))
1472

  
1465 1473
    def last_pending(self):
1466 1474
        try:
1467 1475
            return self.pending_modifications().order_by('-id')[0]
b/snf-astakos-app/astakos/im/templates/im/projects/project_detail.html
51 51
      <a style="font-size:0.7em"
52 52
         href="{% url astakos.im.views.project_modify object.pk %}">MODIFY</a>
53 53

  
54
      {% with object.last_pending_incl_me as last_pending %}
55
      {% if last_pending %}
56
        -
57
        <a style="font-size:0.7em"
58
           href="{% url astakos.im.views.project_app_cancel last_pending.pk %}">
59
          CANCEL {% if object.is_modification %} MODIFICATION {% else %}
60
          PROJECT {% endif %} REQUEST
61
        </a>
62
      {% endif %}
63
      {% endwith %}
64

  
54 65
      <!-- only one is possible, perhaps add cancel button too -->
55 66
      {% if can_join_request or can_leav_request %}
56
      -
67
        <br />
57 68
      {% endif %}
58 69
    {% endif %}
59 70

  
b/snf-astakos-app/astakos/im/urls.py
71 71
    url(r'^projects/(?P<chain_id>\d+)/(?P<user_id>\d+)/remove/?$', 'project_remove_member', {}, name='project_remove_member'),
72 72
    url(r'^projects/app/(?P<application_id>\d+)/?$', 'project_app', {}, name='project_app'),
73 73
    url(r'^projects/app/(?P<application_id>\d+)/modify$', 'project_modify', {}, name='project_modify'),
74
    url(r'^projects/app/(?P<application_id>\d+)/cancel$', 'project_app_cancel', {}, name='project_app_cancel'),
74 75

  
75 76
    url(r'^projects/how_it_works/?$', 'how_it_works', {}, name='how_it_works'),
76 77
    url(r'^remove_auth_provider/(?P<pk>\d+)?$', 'remove_auth_provider', {}, name='remove_auth_provider'),
b/snf-astakos-app/astakos/im/views.py
98 98
    SendNotificationError,
99 99
    accept_membership, reject_membership, remove_membership, cancel_membership,
100 100
    leave_project, join_project, enroll_member, can_join_request, can_leave_request,
101
    cancel_application, get_related_project_id,
101 102
    get_by_chain_or_404)
102 103
from astakos.im.settings import (
103 104
    COOKIE_DOMAIN, LOGOUT_NEXT,
......
1100 1101
@require_http_methods(["GET", "POST"])
1101 1102
@signed_terms_required
1102 1103
@login_required
1104
@project_transaction_context()
1105
def project_app_cancel(request, application_id, ctx=None):
1106
    chain_id = None
1107
    try:
1108
        application_id = int(application_id)
1109
        chain_id = get_related_project_id(application_id)
1110
        cancel_application(application_id, request.user)
1111
    except (IOError, PermissionDenied), e:
1112
        messages.error(request, e)
1113
    except BaseException, e:
1114
        logger.exception(e)
1115
        messages.error(request, _(astakos_messages.GENERIC_ERROR))
1116
        if ctx:
1117
            ctx.mark_rollback()
1118
    else:
1119
        msg = _(astakos_messages.APPLICATION_CANCELLED)
1120
        messages.success(request, msg)
1121

  
1122
    next = request.GET.get('next')
1123
    if not next:
1124
        if chain_id:
1125
            next = reverse('astakos.im.views.project_detail', args=(chain_id,))
1126
        else:
1127
            next = reverse('astakos.im.views.project_list')
1128

  
1129
    next = restrict_next(next, domain=COOKIE_DOMAIN)
1130
    return redirect(next)
1131

  
1132

  
1133
@require_http_methods(["GET", "POST"])
1134
@signed_terms_required
1135
@login_required
1103 1136
def project_modify(request, application_id):
1104 1137

  
1105 1138
    try:

Also available in: Unified diff