def post(self): user = users.get_current_user() if user is None: self.error(401) bucket_name = app_identity.get_default_gcs_bucket_name() uploaded_file = self.request.POST.get('uploaded_file') file_name = getattr(uploaded_file, 'filename', None) file_content = getattr(uploaded_file, 'file', None) real_path = '' if file_name and file_content: content_t = mimetypes.guess_type(file_name)[0] real_path = os.path.join('/', bucket_name, user.user_id(), file_name) with cloudstorage.open(real_path, 'w', content_type=content_t, options={'x-goog-acl': 'public-read'}) as f: f.write(file_content.read()) log_operation(user, OpTypes.FILE_ADDED, datetime.datetime.now()) self._create_note(user, file_name, real_path) log_operation(user, OpTypes.NOTE_CREATED, datetime.datetime.now()) logout_url = users.create_logout_url(self.request.uri) template_context = { 'user': user.nickname(), 'logout_url': logout_url, } self.response.out.write( self._render_template('main.html', template_context))
def get(self): user = users.get_current_user() if user is None: login_url = users.create_login_url(self.request.uri) return self.redirect(login_url) taskqueue.add(url='/shrink', params={'user_email': user.email()}) log_operation(user, OpTypes.SHRINK_PERFORMED, datetime.datetime.now()) self.response.write('Task added to the queue.')
def receive(self, mail_message): email_pattern = re.compile(r'([\w\-\.]+@(\w[\w\-]+\.)+[\w\-]+)') match = email_pattern.findall(mail_message.sender) email_addr = match[0][0] if match else '' try: user = users.User(email_addr) user = self._reload_user(user) except users.UserNotFoundError: return self.error(403) title = mail_message.subject content = '' for content_t, body in mail_message.bodies('text/plain'): content += body.decode() attachments = getattr(mail_message, 'attachments', None) self._create_note(user, title, content, attachments) log_operation(user, OpTypes.NOTE_CREATED, datetime.datetime.now())