Beispiel #1
0
def home_page(request, logged_in_template):
    img_cap_list = []
    context = RequestContext(request)
    if request.user.is_active:
        user_exists = UserProfile.objects.get(user = request.user)
        photo_album = PhotoAlbum()
        if not photo_album.album_exists('default'):
            photo_album.album_name = 'default'
            photo_album.description = "Default Album"
            photo_album.user = user_exists
            photo_album.user_id = user_exists.user_id
            photo_album.save()
        img_cap_list_dict = PhotoAlbum.objects.filter(user = request.user).values('album_name', 'description')
        img_cap_list = map(lambda img_cap_dict: (str(img_cap_dict['album_name']),str(img_cap_dict['description'])),img_cap_list_dict)
        context['photos'] = img_cap_list
        return render_to_response(logged_in_template, {'request': request}, context_instance=context)
    else: return HttpResponseRedirect(reverse("login"))
Beispiel #2
0
def create_album_page(request, new_album_template):
    if request.user.is_active:
        if request.method == 'POST': # If the form has been submitted...
            user_exists = UserProfile.objects.get(user = request.user)
            album_obj = PhotoAlbum()
            album_obj.album_name = request.POST['album_name']
            album_obj.description = request.POST['description']
            album_obj.user = user_exists
            album_obj.user_id = user_exists.user_id
            album_obj.save()
            return HttpResponseRedirect('/home/')
        else:
            form = PhotoAlbumForm() # An unbound form
            return render_to_response(new_album_template, {
                    'form': form,
                    })
    else: return HttpResponseRedirect(reverse("login"))