def approve_permission_request(request, requested_permission, extra_context={}): """ View for approving/rejecting a user's permission request. This view is a centralized place for approving permission requests for any kind of object through the whole Transifex. Following the upstream django-authority app, all the entries are considered requests until the field approved be set to True. """ requested_permission.approve(request.user) if extra_context.has_key('notice'): # ActionLog & Notification _send_notice_save_action(request, extra_context['notice']) messages.info(request, _('You approved the permission request.')) next = get_next(request, requested_permission) return HttpResponseRedirect(next)
def add_permission_or_request(request, obj, view_name, approved=False, template_name = 'authority/permission_form.html', extra_context={}): """ View for adding either a permission or a permission request for a user. This view is a centralized place for adding permissions/requests for any kind of object through the whole Transifex. Following the upstream django-authority app, all the entries are considered requests until the field approved be set to True. For the extra_context, this view expect a key called 'notice' that MUST have a determinate dictionary structure to be able to send notifications and save action logs. See the `_send_notice_save_action` function docstring for more information. Example of `extra_context` with `notice` key: # See `_send_notice_save_action` docstring for the `notice` var below notice = {} extra_context.update({'notice': notice}) If the key 'notice' is not found in the extra_context parameter, nothing is executed about notification and action log. """ codename = request.POST.get('codename', None) next = get_next(request, obj) if request.method == 'POST': # POST method requires a permission codename if codename is None: return HttpResponseForbidden(next) form = UserAjaxPermissionForm(data=request.POST, obj=obj, approved=approved, perm=codename, initial=dict(codename=codename)) if not approved: # Limit permission request to current user form.data['user'] = request.user if form.is_valid(): permission = form.save(request) if extra_context.has_key('notice'): # ActionLog & Notification _send_notice_save_action(request, extra_context['notice']) if approved: msg = _('You added a permission.') else: msg = _('You added a permission request.') messages.info(request, msg) return HttpResponseRedirect(next) else: form = None context = { 'form': form, 'form_url': txurl_for_obj(view_name, obj), 'next': next, 'perm': codename, 'approved': approved, } extra_context.update({'notice':None}) context.update(extra_context) return render_to_response(template_name, context, context_instance=RequestContext(request))
def add_permission_or_request(request, obj, view_name, approved=False, template_name='authority/permission_form.html', extra_context={}): """ View for adding either a permission or a permission request for a user. This view is a centralized place for adding permissions/requests for any kind of object through the whole Transifex. Following the upstream django-authority app, all the entries are considered requests until the field approved be set to True. For the extra_context, this view expect a key called 'notice' that MUST have a determinate dictionary structure to be able to send notifications and save action logs. See the `_send_notice_save_action` function docstring for more information. Example of `extra_context` with `notice` key: # See `_send_notice_save_action` docstring for the `notice` var below notice = {} extra_context.update({'notice': notice}) If the key 'notice' is not found in the extra_context parameter, nothing is executed about notification and action log. """ codename = request.POST.get('codename', None) next = get_next(request, obj) if request.method == 'POST': # POST method requires a permission codename if codename is None: return HttpResponseForbidden(next) form = UserAjaxPermissionForm(data=request.POST, obj=obj, approved=approved, perm=codename, initial=dict(codename=codename)) if not approved: # Limit permission request to current user form.data['user'] = request.user if form.is_valid(): permission = form.save(request) if extra_context.has_key('notice'): # ActionLog & Notification _send_notice_save_action(request, extra_context['notice']) if approved: msg = _('You added a permission.') else: msg = _('You added a permission request.') messages.info(request, msg) return HttpResponseRedirect(next) else: form = None context = { 'form': form, 'form_url': txurl_for_obj(view_name, obj), 'next': next, 'perm': codename, 'approved': approved, } extra_context.update({'notice': None}) context.update(extra_context) return render_to_response(template_name, context, context_instance=RequestContext(request))