(request)
Modify a top-level object's releasability. Should be an AJAX POST.

    :param request: Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
Modify a top-level object's releasability. Should be an AJAX POST.
Modify a top - level object s releasability . Should be an AJAX POST .
def source_releasability(request):
    """
    Modify a top-level object's releasability. Should be an AJAX POST.

    :param request: Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == 'POST' and request.is_ajax():
        type_ = request.POST.get('type', None)
        id_ = request.POST.get('id', None)
        name = request.POST.get('name', None)
        note = request.POST.get('note', None)
        action = request.POST.get('action', None)
        date = request.POST.get('date', datetime.datetime.now())
        user = request.user
        if not isinstance(date, datetime.datetime):
            date = parse(date, fuzzy=True)

        acl = get_acl_object(type_)

        if not type_ or not id_ or not name or not action:
            error = "Modifying releasability requires a type, id, source, and action"
            return render(request, "error.html", {"error" : error })
        if action  == "add":
            if user.has_access_to(acl.RELEASABILITY_ADD):
                result = add_releasability(type_, id_, name, user.username)
            else:
                result = {'success':False,
                          'message':'User does not have permission to add releasability.'}
        elif action  == "add_instance":
            if user.has_access_to(acl.RELEASABILITY_ADD):
                result = add_releasability_instance(type_, id_, name, user.username,
                                                    note=note)
            else:
                result = {'success':False,
                          'message':'User does not have permission to add releasability.'}
        elif action == "remove":
            if user.has_access_to(acl.RELEASABILITY_DELETE):
                result = remove_releasability(type_, id_, name, user.username)
            else:
                result = {'success':False,
                          'message':'User does not have permission to remove releasability.'}
        elif action == "remove_instance":
            if user.has_access_to(acl.RELEASABILITY_DELETE):
                result = remove_releasability_instance(type_, id_, name, date, user.username)
            else:
                result = {'success':False,
                          'message':'User does not have permission to delete releasability.'}
        else:
            error = "Unknown releasability action: %s" % action
            return render(request, "error.html", {"error" : error })
        if result['success']:
            subscription = {
                'type': type_,
                'id': id_
            }

            html = render_to_string('releasability_header_widget.html',
                                    {'releasability': result['obj'],
                                     'subscription': subscription},
                                    request=request)
            response = {'success': result['success'],
                        'html': html}
        else:
            response = {'success': result['success'],
                        'error': result['message']}
        return HttpResponse(json.dumps(response),
                            content_type="application/json")
    else:
        error = "Expected AJAX POST!"
        return render(request, "error.html", {"error" : error })
def source_releasability ( request ) : if request . method == 'POST' and request . is_ajax ( ) : type_ = request . POST . get ( 'type' , None ) id_ = request . POST . get ( 'id' , None ) name = request . POST . get ( 'name' , None ) note = request . POST . get ( 'note' , None ) action = request . POST . get ( 'action' , None ) date = request . POST . get ( 'date' , datetime . datetime . now ( ) ) user = request . user if not isinstance ( date , datetime . datetime ) : date = parse ( date , fuzzy = True ) acl = get_acl_object ( type_ ) if not type_ or not id_ or not name or not action : error = "Modifying releasability requires a type, id, source, and action" return render ( request , "error.html" , { "error" : error } ) if action == "add" : if user . has_access_to ( acl . RELEASABILITY_ADD ) : result = add_releasability ( type_ , id_ , name , user . username ) else : result = { 'success' : False , 'message' : 'User does not have permission to add releasability.' } elif action == "add_instance" : if user . has_access_to ( acl . RELEASABILITY_ADD ) : result = add_releasability_instance ( type_ , id_ , name , user . username , note = note ) else : result = { 'success' : False , 'message' : 'User does not have permission to add releasability.' } elif action == "remove" : if user . has_access_to ( acl . RELEASABILITY_DELETE ) : result = remove_releasability ( type_ , id_ , name , user . username ) else : result = { 'success' : False , 'message' : 'User does not have permission to remove releasability.' } elif action == "remove_instance" : if user . has_access_to ( acl . RELEASABILITY_DELETE ) : result = remove_releasability_instance ( type_ , id_ , name , date , user . username ) else : result = { 'success' : False , 'message' : 'User does not have permission to delete releasability.' } else : error = "Unknown releasability action: %s" % action return render ( request , "error.html" , { "error" : error } ) if result [ 'success' ] : subscription = { 'type' : type_ , 'id' : id_ } html = render_to_string ( 'releasability_header_widget.html' , { 'releasability' : result [ 'obj' ] , 'subscription' : subscription } , request = request ) response = { 'success' : result [ 'success' ] , 'html' : html } else : response = { 'success' : result [ 'success' ] , 'error' : result [ 'message' ] } return HttpResponse ( json . dumps ( response ) , content_type = "application/json" ) else : error = "Expected AJAX POST!" return render ( request , "error.html" , { "error" : error } )