Example #1
0
def photo_edit(request, photo_id):
    print "POST: %s" % request.POST
    photo = Photo.objects.get(id=photo_id)
    form = EditPhotoForm()
    errmsg = ""
    succ = False
    if request.method == "POST":
        form = EditPhotoForm(request.POST, request.FILES)
        if form.is_valid():
            p = photo
            p.title = form.cleaned_data['title']
            p.description = form.cleaned_data['description']
            p.datetime = datetime.datetime.now()
            p.uuid = str(uuid.uuid4())
            p.license = form.cleaned_data['license']
            p.published = form.cleaned_data['published']
            p.featured = form.cleaned_data['featured']
            p.notes = form.cleaned_data['notes']
            p.postcard = form.cleaned_data['postcard']
            p.save()

            p.set_tags(request.POST.getlist('tags'))

            if 'photo' in request.FILES.keys():
                p.extension = os.path.splitext(form.cleaned_data['photo'].name)[1][1:]
                create_new_photo_storage(photo=p, 
                    f=request.FILES['photo'])
            
            succ = p.id

        else:
            errmsg = form.errors
    else:
        form.fields["title"].initial = photo.title
        form.fields["description"].initial = photo.description
        form.fields["license"].initial = photo.license
        form.fields["published"].initial = photo.published
        form.fields["featured"].initial = photo.featured
        form.fields["notes"].initial = photo.notes
        form.fields["postcard"].initial = photo.postcard
    

    return render(request, 'manage/photo-edit.html', {
            'NAV_PHOTO_CLASS': 'active',
            'form': form,
            'errmsg': errmsg,
            'succ': succ,
            'tags': photo.tags.all(),
            'all_tags': get_all_tags(),
        }
        )
Example #2
0
def photo_add(request):
    form = PhotoForm()
    errmsg = ""
    succ = False
    if request.method == "POST":
        form = PhotoForm(request.POST, request.FILES)
        if form.is_valid():
            p = Photo()
            p.title = form.cleaned_data['title']
            p.description = form.cleaned_data['description']
            p.datetime = datetime.datetime.now()
            p.uuid = str(uuid.uuid4())
            p.license = form.cleaned_data['license']
            p.published = form.cleaned_data['published']
            p.featured = form.cleaned_data['featured']
            p.extension = os.path.splitext(form.cleaned_data['photo'].name)[1][1:]
            p.notes = form.cleaned_data['notes']
            p.postcard = form.cleaned_data['postcard']
            p.save()

            p.set_tags(request.POST.getlist('tags'))

            create_new_photo_storage(photo=p, 
                f=request.FILES['photo'])
            
            succ = p.id

        else:
            errmsg = form.errors

    return render(request, 'manage/photo-add.html', {
            'NAV_PHOTO_CLASS': 'active',
            'form': form,
            'errmsg': errmsg,
            'succ': succ,
            'all_tags': get_all_tags(),
        }
        )