def upload_extract(real_user, user, change, **kw): """ File is binary in the request body. """ from pylons import request order_index = int(to_unicode(request.headers.get('X-Up-Order-Index'))) type = to_unicode(request.headers.get('X-Up-Type')) if not type: return None f, tmpname = tempfile.mkstemp('png') if isinstance(f, int): f = open(tmpname, 'wb') #this is inefficient. Pylons supposedly already creates a tmp file. We are instead #reading the thing into memory. I'm lazy until this beomes an issue (prolly soon) #V: please make this not suck f.write(request.environ['wsgi.input'].read()) f.close() new = False change_extract = Session.query(projects.ChangeExtract).filter_by(change=change, extract_type=type, order_index=order_index).first() if not change_extract: new = True change_extract = projects.ChangeExtract(change=change, extract_type=type, order_index=order_index) Session.add(change_extract) change_extract.set_contents(tmpname) return new and 'new' or 'existing'
def upload(real_user, user, project, **kw): """ File is binary in the request body. """ from pylons import request fname = utils.to_unicode(request.headers.get('X-Up-Filename')) type = utils.to_unicode(request.headers.get('X-Up-Type')) path = utils.to_unicode(request.headers.get('X-Up-Path')) description = utils.to_unicode(request.headers.get('X-Up-Description')) if not fname or not type or not path: return None ext = None if type: ext = mimetypes.guess_extension(type) if not ext: _, ext = os.path.splitext(fname) ext = ext or '' f, tmpname = tempfile.mkstemp(ext) #why is this returning an int on my machine? Supposed to be a file pointer. if isinstance(f, int): f = open(tmpname, 'wb') #this is inefficient. Pylons supposedly already creates a tmp file. We are instead #reading the thing into memory. I'm lazy until this beomes an issue (prolly soon) #V: please make this not suck f.write(request.environ['wsgi.input'].read()) f.close() change = project.add_change(user, os.path.join(path, fname), tmpname, u'') if change.version == 1: #email users = project.interested_users if user in users: users.remove(user) email.send(users, 'create_file.txt', { 'project': project, 'change': change, 'creator': user }) else: #email users = change.entity.interested_users if user in users: users.remove(user) email.send(users, 'create_change.txt', { 'project': project, 'change': change, 'creator': user }) return change.entity, change
def set_extra_split(self, v): self.extra = self.JOINT.join([to_unicode(a) for a in v])