Beispiel #1
0
def edit_new(request, *args, **kwargs):
    id_url = kwargs["id"]
    selected_new = New.objects.get(id=id_url)
    if request.method == 'POST':
        form = Newform(request.POST, instance=selected_new)
        if form.is_valid():
            selected_new.title = request.POST.get('title')
            selected_new.comment = request.POST.get('comment')
            selected_new.date = datetime(form.cleaned_data.get('date').year,
                                         form.cleaned_data.get('date').month,
                                         form.cleaned_data.get('date').day,
                                         datetime.now().hour,
                                         datetime.now().minute,
                                         datetime.now().second)
            form.save()
            messages.success(request,
                             u"La nouvelle ({}) a été mise à jour".format(selected_new.title))
            return HttpResponseRedirect('/admin/')
    else:
        form = Newform(instance=selected_new)
    return render(request, 'administration/add_new.html',
                  {'form': form, 'page_title': _("Changing the news")})
Beispiel #2
0
def add_new(request):
    c = {'settings': settings, 'page_title': _("Adding new")}
    if request.method == 'POST':
        form = Newform(request.POST, request.FILES)
        if form.is_valid():
            request.date = datetime(form.cleaned_data.get('date').year,
                                    form.cleaned_data.get('date').month,
                                    form.cleaned_data.get('date').day)
            new = form.save(commit=False)
            new.author = request.user
            new.save()
            messages.success(
                request, u"La nouvelle ({}) a été ajoutée".format(new.title))
            return HttpResponseRedirect('/admin/')
    else:
        form = Newform()
    c.update({'form': form})
    return render(request, 'administration/add_new.html', c)