+ # Save the file
+ upload = request.params['file']
+ hash = storage.save_file('art/original', upload.file)
+
+ # Create a thumbnail and a medium view
+ img = PIL.Image.open(
+ config['app_conf']['static_root']
+ + storage.get_path('art/original', hash)[1:]
+ )
+ for subdir, config_size in [('medium', config['medium_size']),
+ ('thumbnail', config['thumbnail_size'])]:
+ path = config['app_conf']['static_root'] + storage.get_path("art/{0}".format(subdir), hash)
+
+ dir, _ = os.path.split(path)
+ if not os.path.exists(dir):
+ os.makedirs(dir)
+
+ 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)
+
+ # <<<<<<< HEAD
+ # if c.form.by_me and c.user not in c.form.by.data:
+ # UserRelation(user=c.user, creator=c.user, kind="by", art=c.art)
+ #
+ # for artist in c.form.by.data:
+ # UserRelation(user=artist, creator=c.user, kind="by", art=c.art)
+ # =======
+ # For the moment, cheerfully assume that people are uploading their own
+ # art
+ ArtUser(art=c.art, user=c.user, type=ArtUserType.BY)
+ # >>>>>>> origin/master
+
+
+ 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))
+
+