예제 #1
0
def create_album_view(request):
    owner = request.user
    if request.method == 'POST':
        form = CreateAlbumForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            album = Album(name=name, owner=owner)
            album.save()
            return HttpResponseRedirect('/main')
    else:
        form = CreateAlbumForm()
        return render(request, 'photorizer/create_album.html', {'form': form})
예제 #2
0
    def create_album(self, form):
        if self.request.method == 'POST':
            form = CreateAlbumForm(self.request.POST)

        if form.is_valid():
            title = form.cleaned_data['title']

            if title:
                album, created = Album.objects.get_or_create(title=title)


        else:
            form = CreateAlbumForm()
예제 #3
0
파일: views.py 프로젝트: jsaxton/riGallery
def createAlbum():
    form = CreateAlbumForm(prefix="createAlbum")
    if form.validate_on_submit():
        album = Album(name=form.name.data, 
                      description=form.description.data, 
                      creationDate=datetime.utcnow(), 
                      numImages=0, 
                      coverImageId=0)
        if form.passwordProtected.data and form.passwordHash.data:
            album.passwordHash = getAlbumPasswordHash(album.creationDate, form.passwordHash.data)
        db.session.add(album)
        db.session.commit()
    return admin(createAlbumForm=form)
예제 #4
0
def create():
    if not session.get('user'):
        return redirect(url_for('home'))
    form = CreateAlbumForm()
    if form.validate_on_submit():
        title = request.form.get('title')
        description = request.form.get('description')
        date = datetime.datetime.strptime(request.form.get('date'), '%Y-%m-%d')
        new_album = Album(title=title, description=description, date=date)
        db.session.add(new_album)
        db.session.commit()
        return redirect(url_for('home'))
    return render_template('create.html', form=form)
예제 #5
0
def createAlbum(request):
	if request.method=="POST":
		form = CreateAlbumForm(request.POST, request.FILES)
		if form.is_valid():
			newAlbumForm=form.save(commit=False)
			object_name = "Albums/%s" % (str(uuid4()))
			newAlbumForm.awsObjectName = object_name
			success = uploadToS3(request.FILES,object_name)
			if success:
				newAlbumForm.save()
				return render(request,"Albums/createAlbum.html",{"Success":"Congratulations Dad! You Uploaded an album!"})
			else:
				return render(request,"Albums/createAlbum.html",{"Error":"Uh oh something bad happened!"})
	else:
		form = CreateAlbumForm()
	return render(request,"Albums/createAlbum.html",{"form":form})
예제 #6
0
파일: app.py 프로젝트: calvinhla/wanderlust
def create_new_album(username):
    form = CreateAlbumForm()
    form.country.choices = country_choices
    if form.validate_on_submit():
        title = form.title.data
        country_id = form.country.data
        album = Album.add_album(g.user.id, country_id, title)
        if album:
            country_albums[album.country.iso] += 1
            return redirect(
                f'/users/{username}/albums/{countries[country_id]["iso"]}/{album.title}'
            )
        else:
            form.title.errors.append('Album title already exists')
            return render_template('form.html', form=form)
    return render_template('form.html', form=form)
예제 #7
0
def create_album(request):
  staff_only(request)
  #if request.method == 'GET':
   # render_to_response(create_album.html)
  
  if request.method == 'POST':
    pass
  else:
    form = CreateAlbumForm()
    return render_to_response('form.html',{'form': form})
예제 #8
0
def edit_album_view(request, album_id):
    # try:
    #     album = Album.objects.get(pk=album_id)
    # except Album.DoesNotExist:
    #     raise Http404
    album = get_object_or_404(Album, pk=album_id)
    if album.owner_id == request.user.id:
        if request.method == 'POST':
            form = CreateAlbumForm(request.POST)
            if form.is_valid():
                name = form.cleaned_data['name']
                album.name = name
                album.save()
                return HttpResponseRedirect('/main')
        else:
            form = CreateAlbumForm(initial={'name': album.name})
            return render(request, 'photorizer/edit_album.html',
                          {'form': form, 'album': album})
    else:
        return render(request, 'photorizer/permission_denied.html')
예제 #9
0
def make_album(request, user_id):
    logged_in_user = request.user
    if request.method == 'POST':
        form = CreateAlbumForm(request.POST)
        if form.is_valid():
            albuminfo = form.cleaned_data
            title = albuminfo['title']
            published = albuminfo['published']
            date_published = timezone.now()
            date_uploaded = timezone.now()
            date_modified = timezone.now()
            owner_id = logged_in_user.id
            new_album = Album(title=title, published=published, date_modified=date_modified,
                date_published=date_published, date_uploaded=date_uploaded, owner_id=owner_id)
            new_album.save()
            return HttpResponseRedirect('/imagr/profile/{}'.format(logged_in_user.id))
        else:
            return HttpResponse("Sorry, we couldn't process your request")
    else:
        return HttpResponse('Access Denied')
예제 #10
0
파일: views.py 프로젝트: jsaxton/riGallery
def admin(createAlbumForm=None):
    albums = Album.query.order_by("id asc")
    # Can't set default values in function declaration - causes "RuntimeError: working outside of application context"
    if createAlbumForm == None:
        createAlbumForm = CreateAlbumForm(prefix="createAlbum")
    return render_template('admin.html', createAlbumForm=createAlbumForm, albums=albums)