def render(self, request): """Don't actually render, but calls a process which returns a deferred. Callbacks on the deferred do the rendering, which is actually achieved through redirection. """ #natasha convert # turn form into simple dictionary, dropping multiple values. reqargs = request.args self.assignedstages = reqargs.get('assigned') form = dict([(k, v[0]) for k,v in request.args.iteritems()]) # natasha: added prefix value prefix = '' try: self.mediatype = form.pop('type', None) if not self.mediatype in self.mediatypes: raise UpstageError('Not a real kind of thing: %s' % self.mediatype) self.media_dict = self.mediatypes[self.mediatype] #self.media_dict = self.collections #change to starswith 'avcontents' if self.mediatype == 'avatar': prefix = 'av' # self.media_dict = self.collection.avatars elif self.mediatype == 'prop': prefix = 'pr' elif self.mediatype == 'backdrop': prefix = 'bk' elif self.mediatype == 'audio': #remem audio not included as things prefix = 'au' #imgs = [ (k, v) for k, v in form.iteritems() if k.startswith('contents') and v ] contentname = prefix + 'contents' imgs = [ (k, v) for k, v in form.iteritems() if k.startswith(prefix + 'contents') and v ] imgs.sort() # save input files in /tmp, also save file names tfns = [ save_tempfile(x[1]) for x in imgs ] # Alan (12/09/07) ==> Gets the size of image files using the previously created temp filenames. #natasha getfilesize fileSizes = getFileSizes(tfns) # imported from misc.py swf = new_filename(suffix='.swf') thumbnail = swf.replace('.swf', '.jpg') swf_full = os.path.join(config.MEDIA_DIR, swf) thumbnail_full = os.path.join(config.THUMBNAILS_DIR, thumbnail) except UpstageError, e: return errorpage(request, e, 500)
def render(self, request): #XXX not checking rights. args = request.args # Natasha - get assigned stages self.assignedstages = request.args.get('assigned') name = args.pop('name',[''])[0] audio = args.pop('aucontents0', [''])[0] #was 'audio' before, aucontents0 is the name of the mp3 file field type = args.pop('audio_type', [''])[0] mediatype = args.pop('type',['audio'])[0] self.message = 'Audio file uploaded & registered as %s, called %s. ' % (type, name) #Corey, Heath, Karena 24/08/2011 - Added to store tags for this audiothing self.tags = args.pop('tags',[''])[0] # PQ & EB Added 13.10.07 # Chooses a thumbnail image depending on type (adds to audios.xml file) if type == 'sfx': thumbnail = config.SFX_ICON_IMAGE_URL else: thumbnail = config.MUSIC_ICON_IMAGE_URL self.media_dict = self.mediatypes[mediatype] mp3name = new_filename(suffix=".mp3") the_url = config.AUDIO_DIR +"/"+ mp3name file = open(the_url, 'wb') file.write(audio) file.close() filenames = [the_url] # Alan (09/05/08) ==> Gets the size of audio files using the previously created temp filenames. fileSizes = getFileSizes(filenames) if not (fileSizes is None): if (validSizes(fileSizes, self.player.can_su()) or self.player.can_unlimited()): now = datetime.datetime.now() # AC () - Unformated datetime value self.media_dict.add(url='%s/%s' % (config.AUDIO_SUBURL, mp3name), #XXX dodgy? (windows safe?) file=mp3name, name=name, voice="", thumbnail=thumbnail, # PQ: 13.10.07 was "" medium="%s" %(type), # AC (14.08.08) - Passed values to be added to media XML files. uploader=self.player.name, dateTime=(now.strftime("%d/%m/%y @ %I:%M %p")), tags=self.tags)#Corey, Heath, Karena 24/08/2011 - Added for media tagging set the tags to self.tags if self.assignedstages is not None: for x in self.assignedstages: self.media_dict.set_media_stage(x, mp3name) request.write(successpage(request, 'Your Media "' + name + '" has uploaded successfully')) request.finish() else: try: ''' Send new audio page back containing error message ''' """ self.player.set_setError(True) os.remove(the_url) request.redirect('/admin/new/%s' %(mediatype)) request.finish() """ AdminError.errorMsg = 'File over 1MB' #Change error message to file exceed - Gavin request.write(errorpage(request, 'Media uploads are limited to files of 1MB or less, to help ensure that unnecessarily large files do not cause long loading times for your stage. Please make your file smaller or, if you really need to upload a larger file, contact the administrator of this server to ask for permission.')) request.finish() except OSError, e: log.err("Error removing temp file %s (already gone?):\n %s" % (tfn, e))