Esempio n. 1
0
def save(request, class_name, slug):
    instance = get_class(class_name).objects.get(slug=slug)
    form = None

    if request.method == 'GET':
        initial = {
            'slug': slug,
        }

        form = AlbumForm(initial)
    else:
        form = AlbumForm(request.POST)
        if form.is_valid():
            data  = form.cleaned_data
            album = Album.create_album(title=data['title'], instance=instance)

            for picture_id in request.POST['picture_id'].split(','):
                album.add_picture(Picture.objects.get(pk=int(picture_id)))

            return HttpResponseRedirect(reverse('portal.album.views.detail', args=[class_name, slug, album.id,]))

    ctx = {
        'instance': instance,
        'form': form,
    }

    return direct_to_template(request, 'album/form.html', ctx)
Esempio n. 2
0
    def testSomething(self):
        picture = Picture()
        picture.picture  = db.Blob(self.picture_file)
        picture.filename = AlbumTestCase.PICTURE_FILE_NAME
        picture.save()

        institution = Institution(name='Institution', picture=picture, description='Description', homepage='http://www.homepage.com')
        institution.save()

        album = Album.create_album(title='Some party', instance=institution)
        album.add_picture(picture)

        logging.info('Institution albums: %s' % str(Album.objects.for_model(institution)))

        for rpa in album.picture_album_set.all():
            logging.info('Picture - %s [%d x %d]' % (rpa.picture.filename, rpa.picture.width, rpa.picture.height))