def delete(web, args=None): """ Delete a gift. /gift/delete/gkey """ web.require_author() if args: gkey = args[0] else: gkey = web.get_param('gkey') me = web.user logging.debug('gift.delete: gkey=%s' % gkey) u = SuiBirthdayUser.get_by_key_name(me.key().name()) g = SuiBirthdayGift.get_by_key_name(gkey) if u and g: if g.creator != me.key().name(): web.fail('No permission') return ms = MediaStore.get_by_key_name('bdg_%s' % gkey) try: db.delete([ms, g]) u.del_mygift(gkey) helper.update_gift_cache('del', gkey, me.key().name()) u.put() web.succeed() except: logging.exception('Failed to delete my gift (%s)' % me.key().name()) web.fail('Cannot delete, retry later') else: web.fail('Not valid birthday user or gift')
def delete(web, args=None): """ Delete a gift. /gift/delete/gkey """ web.require_author() if args: gkey = args[0] else: gkey = web.get_param('gkey') me = web.user logging.debug('gift.delete: gkey=%s'%gkey) u = SuiBirthdayUser.get_by_key_name(me.key().name()) g = SuiBirthdayGift.get_by_key_name(gkey) if u and g: if g.creator != me.key().name(): web.fail('No permission') return ms = MediaStore.get_by_key_name('bdg_%s'%gkey) try: db.delete([ms,g]) u.del_mygift(gkey) helper.update_gift_cache('del',gkey,me.key().name()) u.put() web.succeed() except: logging.exception('Failed to delete my gift (%s)'%me.key().name()) web.fail('Cannot delete, retry later') else: web.fail('Not valid birthday user or gift')
def upload(web, args=None): """ Upload a gift image, or flash movie swf. Space used not counted into SuiUser.spaceused. """ web.require_author() me = web.user gname, gcat, gsex, gpic, myown = web.get_params( ['gname', 'gcat', 'gsex', 'gpic', 'myown']) if not gpic: web.redirect_with_msg('No picture uploaded') return if not gname: gname = gcat imgfile = web.request.POST.get('gpic').filename x = imgfile.rfind('.') if x < 0: web.redirect_with_msg('Unknown image file') return ext = imgfile[x + 1:].lower() if ext not in ['jpg', 'png', 'gif', 'swf']: web.redirect_with_msg( 'Image format not supported, only .jpg,.gif,.png', 'gift') return if not gsex: gsex = 'B' gsex = gsex[0].upper() if not gsex in ['M', 'F', 'B']: gsex = 'B' akey = db.Key.from_path('SuiBirthdayGift', 1) gid = db.allocate_ids(akey, 1)[0] gkey = '%s%s' % (gsex, gid) g = SuiBirthdayGift(key_name=gkey, creator=me.key().name(), name=gname, category=gcat, gender=gsex) u = SuiBirthdayUser.get_by_key_name(me.key().name()) u.usemyown = (myown == 'myown') ms = MediaStore(key_name='bdg_%s' % gkey) ms.stream = db.Blob(gpic) ms.format = ext ms.usage = 'BDG' u.add_mygift(gkey) db.put([ms, u, g]) # ms.put() helper.update_gift_cache('add', gkey, me.key().name()) web.redirect('/gift')
def upload(web, args=None): """ Upload a gift image, or flash movie swf. Space used not counted into SuiUser.spaceused. """ web.require_author() me = web.user gname,gcat,gsex,gpic,myown = web.get_params(['gname','gcat','gsex','gpic','myown']) if not gpic: web.redirect_with_msg('No picture uploaded') return if not gname: gname = gcat imgfile = web.request.POST.get('gpic').filename x = imgfile.rfind('.') if x < 0: web.redirect_with_msg('Unknown image file') return ext = imgfile[x+1:].lower() if ext not in ['jpg','png','gif','swf']: web.redirect_with_msg('Image format not supported, only .jpg,.gif,.png','gift') return if not gsex: gsex = 'B' gsex = gsex[0].upper() if not gsex in ['M','F','B']: gsex = 'B' akey = db.Key.from_path('SuiBirthdayGift',1) gid = db.allocate_ids(akey,1)[0] gkey = '%s%s'%(gsex,gid) g = SuiBirthdayGift(key_name=gkey,creator=me.key().name(),name=gname,category=gcat,gender=gsex) u = SuiBirthdayUser.get_by_key_name(me.key().name()) u.usemyown = (myown == 'myown') ms = MediaStore(key_name='bdg_%s'%gkey) ms.stream = db.Blob(gpic) ms.format = ext ms.usage = 'BDG' u.add_mygift(gkey) db.put([ms,u,g]) # ms.put() helper.update_gift_cache('add',gkey, me.key().name()) web.redirect('/gift')