Esempio n. 1
0
def create(request):
    if request.method == "POST":
        form = ServerForm(request.POST, request.FILES)
        if form.is_valid():
            pass

    return render(request, "server_create.html")
Esempio n. 2
0
    def get_context_data(self, **kwargs):
        context = super(EditView, self).get_context_data(**kwargs)

        servers = self.request.user.servers.all()
        forms = [ServerForm(instance=s, prefix=s.id) for s in servers]

        context['new_server_form'] = ServerForm()
        context['forms'] = forms

        return context
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.")
Esempio n. 5
0
File: views.py Progetto: 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
Esempio n. 6
0
    def form_valid(self, form):
        server = form.save(commit=False)
        server.user = self.request.user
        server.features = Features.objects.create()
        server.save()  # TODO: required? (maybe for a valid pk?)

        server.do_contact_verification(self.request)
        server.save()

        # start verification in a separate thread:
        t = Thread(target=server.verify)
        t.start()

        context = self.get_context_data(form=form)
        context['new_server_form'] = ServerForm()
        return self.render_to_response(context)
Esempio n. 7
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.')
Esempio n. 8
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.")