예제 #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
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})
예제 #4
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')
예제 #5
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')