def set_autoreg_rules(request, pk=None):
    if request.GET.get("gr", None):
        g = Group.objects.get(pk=request.GET.get("gr"))

        try:
            a_g = AutoregGroupRules.objects.get(group=g)
            return HttpResponse(str(a_g.values))
        except AutoregGroupRules.DoesNotExist:
            return HttpResponse("")
    if pk:
        gr = AutoregGroupRules.objects.get(pk=pk)
    else:
        gr = AutoregGroupRules()

    if request.method == "POST":

        group_form = GroupRules(request.POST, instance=gr)
        if group_form.is_valid():
            gf = group_form.save()
            transaction.commit()
            reprocess_groups.delay(gf.group)
            return HttpResponse("Awesome")
        print group_form.errors
    else:
        group_form = GroupRules(instance=gr)
    return render_to_response(
        "ureport/partials/groups_form.html", {"group_form": group_form}, context_instance=RequestContext(request)
    )
def set_autoreg_rules(request):
    if request.GET.get('gr', None):
        g = Group.objects.get(pk=request.GET.get('gr'))

        try:
            a_g = AutoregGroupRules.objects.get(group=g)
            return HttpResponse(str(a_g.values))
        except AutoregGroupRules.DoesNotExist:
            return HttpResponse('')

    if request.method == 'POST':

        group_form = GroupRules(request.POST)
        if group_form.is_valid():
            group_form.save()
    else:
        group_form = GroupRules()
    return render_to_response('ureport/partials/groups_form.html',
                              {'group_form': group_form},
                              context_instance=RequestContext(request))
示例#3
0
def set_autoreg_rules(request, pk=None):
    if request.GET.get('gr', None):
        g = Group.objects.get(pk=request.GET.get('gr'))

        try:
            a_g = AutoregGroupRules.objects.get(group=g)
            return HttpResponse(str(a_g.values))
        except AutoregGroupRules.DoesNotExist:
            return HttpResponse('')
    if pk:
        gr = AutoregGroupRules.objects.get(pk=pk)
    else:
        gr = AutoregGroupRules()

    if request.method == 'POST':

        group_form = GroupRules(request.POST, instance=gr)
        if group_form.is_valid():
            gf = group_form.save()
            transaction.commit()
            reprocess_groups.delay(gf.group)
            return HttpResponse('Awesome')
        print group_form.errors
    else:
        group_form = GroupRules(instance=gr)
    return render_to_response('ureport/partials/groups_form.html',
                              {'group_form': group_form},
                              context_instance=RequestContext(request))