Ejemplo n.º 1
0
Archivo: views.py Proyecto: loum/itt
def insert(request):
    """Present a form that allows:

     * New server resources to be defined
     * Control server resources

    """
    response = None

    t = loader.get_template('server/server_form.html')

    if request.method =='POST':
        # Check for the Cancel button.
        if 'cancel' not in request.POST:
            form = ServerForm(request.POST)
            form.save()

        response = HttpResponseRedirect('/server/')
    else:
        form = ServerForm()
        c = RequestContext(request,
                        {'form': form,})
        response = HttpResponse(t.render(c))

    return response
def ajax_id(request, server_id):
    server = Server.objects.get(id=server_id)
    if request.method == 'DELETE':
        if server.user != request.user:
            return HttpResponseForbidden(
                "Thou shal only delete your own server!")

        server.delete()
    elif request.method == 'POST':
        form = ServerForm(request.POST, instance=server, prefix=server.id)
        if form.is_valid():
            if server.user != request.user:
                return HttpResponseForbidden(
                    "Thou shal only edit your own server!")
            server = form.save()

            changed = set(form.changed_data)
            moderate_properties = {
                'contact',
                'contact_name',
                'contact_type',
                'website',
            }
            if 'domain' in changed:
                server.moderated = None
                server.verified = None
            if moderate_properties & changed:
                server.moderated = None
            if set(['ca', 'ssl_port']) & changed:
                server.verified = None

            # We have special treatment if contact was JID or email:
            if form.contact_changed():
                server.confirmations.all().delete()
                server.do_contact_verification()

            server.save()

            form = ServerForm(
                instance=server, prefix=server.id)

        return render(request, 'ajax/server_table_row.html', {'form': form})

    return HttpResponse('ok.')
def ajax(request):
    if request.method == 'POST':
        form = ServerForm(request.POST)
        if form.is_valid():
            server = form.save(commit=False)
            server.user = request.user
            server.features = Features.objects.create()
            server.save()

            server.do_contact_verification()
            server.save()

            form = ServerForm(
                instance=server, prefix=server.id)
            return render(request, 'ajax/server_table_row.html',
                          {'form': form})
        return render(request, 'ajax/server_table_row.html',
                      {'form': form}, status=400)
    return HttpResponseForbidden("No humans allowed.")
Ejemplo n.º 4
0
def ajax_id(request, server_id):
    server = Server.objects.get(id=server_id)
    if request.method == 'DELETE':
        if server.user != request.user:
            return HttpResponseForbidden(
                "Thou shal only delete your own server!")

        server.delete()
    elif request.method == 'POST':
        form = ServerForm(request.POST, instance=server, prefix=server.id)
        if form.is_valid():
            if server.user != request.user:
                return HttpResponseForbidden(
                    "Thou shal only edit your own server!")
            server = form.save()

            changed = set(form.changed_data)
            moderate_properties = {
                'contact',
                'contact_name',
                'contact_type',
                'website',
            }
            if 'domain' in changed:
                server.moderated = None
                server.verified = None
            if moderate_properties & changed:
                server.moderated = None
            if set(['ca', 'ssl_port']) & changed:
                server.verified = None

            # We have special treatment if contact was JID or email:
            if form.contact_changed():
                server.confirmations.all().delete()
                server.do_contact_verification()

            server.save()

            form = ServerForm(instance=server, prefix=server.id)

        return render(request, 'ajax/server_table_row.html', {'form': form})

    return HttpResponse('ok.')
Ejemplo n.º 5
0
def ajax(request):
    if request.method == 'POST':
        form = ServerForm(request.POST)
        if form.is_valid():
            server = form.save(commit=False)
            server.user = request.user
            server.features = Features.objects.create()
            server.save()

            server.do_contact_verification()
            server.save()

            form = ServerForm(instance=server, prefix=server.id)
            return render(request, 'ajax/server_table_row.html',
                          {'form': form})
        return render(request,
                      'ajax/server_table_row.html', {'form': form},
                      status=400)
    return HttpResponseForbidden("No humans allowed.")