- try:
- elixir.session.commit()
- redirect(url('show_art', id=c.art.id))
- except IntegrityError:
- # hurr, there must be a better way to do this but I am lazy right now
- hash = c.art.hash
- elixir.session.rollback()
- duplicate_art = Art.get_by(hash=hash)
- h.flash("We already have that one.")
- redirect(url('show_art', id=duplicate_art.id))
+ size = int(config_size)
+ shrunken_img = img.copy()
+ shrunken_img.thumbnail((size, size), PIL.Image.ANTIALIAS)
+ shrunken_img.save(path, img.format)
+
+ #magicker = magic.Magic(mime=True)
+ buffer = upload.file.read(64)
+ upload.file.seek(0)
+ mimetype = 'image/unknown' #magickery.from_buffer(buffer)
+
+ # XXX Ensure we can actually handle the mimetype
+
+ print mimetype
+ c.art = Art(
+ uploader=c.user,
+ original_filename=upload.filename,
+ hash=hash,
+ mimetype=mimetype,
+ )
+ c.art.discussion = Discussion(count=0)
+
+ for artist in c.form.by.data:
+ UserRelation(user=artist, kind="by", creator=c.user, art=c.art)
+
+
+ try:
+ elixir.session.commit()
+ redirect(url('show_art', id=c.art.id))
+ except IntegrityError:
+ # XXX Check this as early as possible, and clean up the filesystem!
+ # Right now this replaces the original file!
+ hash = c.art.hash
+ elixir.session.rollback()
+ duplicate_art = Art.get_by(hash=hash)
+ h.flash("We already have that one.")
+ redirect(url('show_art', id=duplicate_art.id))