Пример #1
0
def album_new(request):
    check = auth_test(request)
    if admin_sec.are_you_login(request, check):
        return render(request, 'blog/reject.html', {'check': check})
    ImageFormset = modelformset_factory(Images,
                                        fields=('image', ),
                                        extra=5,
                                        max_num=5)
    if request.method == "GET":
        form = GallaryForm()
        formset = ImageFormset(queryset=Images.objects.none())
    elif request.method == "POST":
        form = GallaryForm(request.POST)
        formset = ImageFormset(request.POST or None, request.FILES or None)
        if form.is_valid() and formset.is_valid():
            gallary = form.save(commit=False)
            gallary.origin_date = timezone.now()
            gallary.final_date = timezone.now()
            gallary.writer_name = check['name']
            gallary.writer_id = check['id']
            gallary.save()

            for f in formset:
                try:
                    photo = Images(post=gallary, image=f.cleaned_data['image'])
                    photo.save()

                except Exception as e:
                    break
            return redirect('album')
    return render(request, 'blog/album_edit.html', {
        'form': form,
        'formset': formset,
        'check': check
    })
Пример #2
0
def notice_new(request):
    check = auth_test(request)
    if admin_sec.are_you_login(request, check):
        return render(request, 'blog/reject.html', {'check': check})
    if request.method == "GET":
        form = NoticeBoardForm()
    elif request.method == "POST":
        form = NoticeBoardForm(request.POST, request.FILES)

        if form.is_valid():
            post = form.save(commit=False)
            post.origin_date = timezone.now()
            post.final_date = timezone.now()
            post.writer_name = check['name']
            post.writer_id = check['id']
            post.save()
            return redirect(notice)
    ctx = {'form': form, 'check': check}

    return render(request, 'blog/notice_edit.html', ctx)