示例#1
0
def domain_record_form(request, name):
    """
    Ajax page for updating, removing and adding DNS records.
    """
    domain = get_domain(request, name)
    form_class = DnsRecordForm

    if request.POST['action'] == 'update':
        try:
            record = Record.objects.get(domain=domain,
                                        id=request.POST.get('id'))
        except Record.DoesNotExist:
            raise Http404
    else:
        record = None
        if request.POST.get('records', False):
            form_class = MultiDnsRecordForm

    form = form_class(request, domain, record, request.POST)

    if form.is_valid():
        status = form.save(args=form.api_call_args(domain.name))

        if status == 204:
            return HttpResponse(None, status=status)
        elif status in (200, 201):
            assert request.GET['flt-domain'] == domain.name
            return redirect('dc_domain_record_list', query_string=request.GET)

    return render(request, form.template, {'form': form, 'domain': domain})
示例#2
0
def admin_domain_form(request):
    """
    Ajax page for updating, removing and adding DNS domains.
    """
    qs = request.GET.copy()
    nodc = request.GET.get('nodc', '')

    if request.POST['action'] == 'create':
        domain = None
    else:
        domain = get_domain(request, request.POST['adm-name'])

    form = AdminDomainForm(request, domain, request.POST, prefix='adm')

    if form.is_valid():
        args = (form.cleaned_data['name'], )
        status = form.save(args=args)

        if status == 204:
            return HttpResponse(None, status=status)
        elif status in (200, 201):
            if form.action == 'create' and not form.cleaned_data.get(
                    'dc_bound'):
                qs['all'] = 1  # Show all items if adding new item and not attaching

            return redirect('dc_domain_list', query_string=qs)

    return render(request, 'gui/dc/domain_admin_form.html', {
        'form': form,
        'nodc': nodc
    })
示例#3
0
def dc_domain_record_list(request):
    """
    List/filter DNS records for a DNS domain (domain parameter in querystring).
    """
    context = collect_view_data(request, 'dc_domain_list', dc_dns_only=True)
    context['is_staff'] = is_staff = request.user.is_staff
    qs = request.GET.copy()
    name = qs.get('flt-domain', None)
    context['all'] = _all = is_staff and request.GET.get(
        'all', request.GET.get('flt-all', False))
    qs['flt-all'] = '1' if _all else ''

    if not name:
        raise PermissionDenied

    context['domain'] = domain = get_domain(request, name)
    context['filters'] = filter_form = DnsRecordFilterForm(request,
                                                           qs,
                                                           _all=_all,
                                                           prefix='flt')
    context['qs'] = qs.urlencode()
    context['order_by'], order_by = get_order_by(request,
                                                 api_view=RecordView,
                                                 db_default=('-id', ),
                                                 user_default=('-id', ))
    records = domain.record_set.order_by(*order_by)

    if filter_form.is_valid() and filter_form.has_changed():
        q = filter_form.get_filters()

        if q:
            records = records.filter(q)

    context['records'] = context['pager'] = get_pager(request,
                                                      records,
                                                      per_page=50)
    context['form_record'] = DnsRecordForm(request,
                                           domain,
                                           None,
                                           initial={
                                               'prio': Record.PRIO,
                                               'ttl': Record.TTL,
                                               'type': Record.A,
                                               'id': 0,
                                               'disabled': False,
                                               'name': '.%s' % domain.name
                                           })
    context['form_records'] = MultiDnsRecordForm(request, domain, None)
    context['url_form_record'] = reverse('domain_record_form',
                                         name,
                                         query_string=qs)

    return render(request, 'gui/dc/domain_record_list.html', context)