예제 #1
0
def delete_source(request, sid):
    "Delete a source"
    source = get_object_or_404(Source, pk=sid)
    if request.method == 'POST':
        form = SourceForm(request.POST, instance=source)
        if form.is_valid():
            try:
                source.delete()
                msg = _('The source has been deleted')
            except DatabaseError:
                msg = _('The source could not be deleted')
            messages.info(request, msg)
            return HttpResponseRedirect(reverse('source-rules'))
    else:
        form = SourceForm(instance=source)
    form.fields['name'].widget.attrs['size'] = '45'
    return render_to_response('web/config/delete_source.html',
                              locals(),
                              context_instance=RequestContext(request))
예제 #2
0
def add_source(request):
    "add a source"
    if request.method == 'POST':
        form = SourceForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                msg = _('The source was created successfully')
                messages.info(request, msg)
                return HttpResponseRedirect(reverse('source-rules'))
            except DatabaseError:
                msg = _('The source could not be created')
                messages.info(request, msg)
                return HttpResponseRedirect(reverse('source-rules'))
    else:
        form = SourceForm()
    form.fields['name'].widget.attrs['size'] = '45'
    return render_to_response('web/config/add_source.html',
                              locals(),
                              context_instance=RequestContext(request))