def upload(self): title = request.POST['title'] description = request.POST['description'] file = request.POST['upload'] if file is not None and file != '': f = File(file.filename, title, mimetype=file.type) f.store(file.file) meta.Session.add(f) meta.Session.commit() redirect(url(controller='admin', action='files'))
def files(self, group): file_id = request.GET.get('serve_file') file = File.get(file_id) c.serve_file = file c.group_menu_current_item = 'files' c.show_info = True return render('group/files.mako')
def _upload_file_basic(self, obj): from ututi.model import Group if isinstance(obj, Group) and not obj.has_file_area: return None file = request.params['attachment'] folder = request.params['folder'] if obj.upload_status != obj.LIMIT_REACHED: if file is not None and file != '': f = File(file.filename, file.filename, mimetype=file.type) f.store(file.file) f.folder = folder obj.files.append(f) meta.Session.add(f) meta.Session.commit() return f else: return None
def _group_action(self, id, file_id): group = Group.get(id) if group is None: abort(404) file = File.get(file_id) if file not in group.files: abort(404) c.security_context = file c.object_location = group.location c.group = group c.breadcrumbs = [{'title': group.title, 'link': group.url()}] return method(self, group, file)
def _create_folder(self, obj): folder_name = request.params['folder'] if not folder_name: return None section_id = request.params.get('section_id', '') obj.files.append(File.makeNullFile(folder_name)) meta.Session.commit() for f in obj.folders: if f.title == folder_name: folder = f fid = "_".join(choose_boundary().split(".")[-3:]) return (render_mako_def('/sections/files.mako','folder_button', folder=folder, section_id=section_id, fid=fid) + render_mako_def('/sections/files.mako','folder', folder=folder, section_id=section_id, fid=fid))
def _move(self, source, file): source_folder = file.folder delete = asbool(request.POST.get('remove', False)) if delete: if check_crowds(['owner', 'moderator', 'admin']): file.deleted = c.user else: abort(501) else: file.folder = request.POST['target_folder'] file.deleted = None if source_folder and source.getFolder(source_folder) is None: source.files.append(File.makeNullFile(source_folder)) meta.Session.commit() return render_mako_def('/sections/files.mako','file', file=file)
def undelete(self, id): if hasattr(self, 'form_result'): parent = self.form_result['parent_id'] file = File.get(id) if file is None: abort(404) if parent is None: if file.parent is None: abort(400) else: file.parent = parent file.deleted_by = None meta.Session.commit() redirect(url(controller='admin', action='deleted_files')) else: abort(400) #bad request
def get(self, id): if isinstance(id, basestring): id = re.search(r"\d*", id).group() if not id: abort(404) file = File.get(id) if file is None: abort(404) if file.parent is not None: redirect(file.url()) elif is_root(c.user): return self._get(file) else: c.login_form_url = url(controller='home', action='login', came_from=file.url()) deny(_('You have no right to download this file.'), 403)
def _subject_action(self, id, tags, file_id): location = LocationTag.get(tags) subject = Subject.get(location, id) if subject is None: abort(404) file = File.get(file_id) if file is None: abort(404) if (file not in subject.files and not file.can_write()): abort(404) c.object_location = subject.location c.security_context = file c.subject = subject c.theme = subject.location.get_theme() return method(self, subject, file)
def _group_action(self, id, message_id, file_id): group = Group.get(id) if group is None: abort(404) message = meta.Session.query(GroupMailingListMessage).filter_by(id=message_id).first() if message is None: abort(404) if isinstance(file_id, basestring): file_id = re.search(r"\d*", file_id).group() file = File.get(file_id) if file is None: #not in group.files: ??? are mailing list files added as the group's files? abort(404) c.security_context = group c.object_location = group.location c.group = group c.group_menu_items = group_menu_items() c.breadcrumbs = [{'title': group.title, 'link': group.url()}] c.theme = group.location.get_theme() return method(self, group, message, file)
def studentgroup_send_message(self, group): if hasattr(self, 'form_result'): subject = self.form_result['subject'] message = self.form_result['message'] #wrap the message with additional information msg_text = render('/emails/teacher_message.mako', extra_vars={'teacher':c.user, 'subject':subject, 'message':message}) if group.group is not None: recipient = group.group if recipient.mailinglist_enabled: attachments = [] if self.form_result['file'] != '': file = self.form_result['file'] f = File(file.filename, file.filename, mimetype=file.type) f.store(file.file) meta.Session.add(f) meta.Session.commit() attachments.append(f) post_message(recipient, c.user, subject, msg_text, force=True, attachments=attachments) else: attachments = [] if self.form_result['file'] != '': attachments = [{'filename': self.form_result['file'].filename, 'file': self.form_result['file'].file}] msg = EmailMessage(_('Message from %(teacher_name)s: %(subject)s') % { 'subject': subject, 'teacher_name': c.user.fullname}, msg_text, sender=recipient.list_address, attachments=attachments) msg.send(group.group) evt = TeacherMessageEvent() evt.context = group.group evt.data = '%s \n\n %s' % (subject, msg_text) evt.user = c.user meta.Session.add(evt) meta.Session.commit() else: attachments = [] if self.form_result['file'] != '': attachments = [{'filename': self.form_result['file'].filename, 'file': self.form_result['file'].file}] msg = EmailMessage(subject, msg_text, sender=c.user.email.email, force=True, attachments=attachments) msg.send(group.email) message = _(u'Message sent to %(group_title)s (%(group_email)s).') % { 'group_title': group.title, 'group_email': group.email} h.flash(message) redirect(url(controller='profile', action='dashboard'))
def index(self): md5_list = request.POST.getall("md5[]") mime_type_list = request.POST.getall("mime-type[]") file_name_list = request.POST.getall("filename[]") message_text = request.str_POST['Mail'] message = GroupMailingListMessage.parseMessage(message_text) group = message.getGroup() author = message.getAuthor() if group is None: return "Silent bounce!" if not group.mailinglist_enabled: if author is not None and group.is_member(author): meta.set_active_user(author.id) request.environ['repoze.who.identity'] = author.id if not group.forum_categories: return 'Ok!' post = make_forum_post(author, message.getSubject(), message.getBody(), group.id, category_id=group.forum_categories[0].id, thread_id=None, controller='forum') meta.Session.add(post) meta.Session.commit() return 'Ok!' return "Silent bounce!" try: message = GroupMailingListMessage.fromMessageText(message_text) except MessageAlreadyExists: return "Ok!" if message is None: return "Silent bounce!" if message.author is not None: meta.set_active_user(message.author.id) request.environ['repoze.who.identity'] = message.author.id else: meta.set_active_user('') meta.Session.add(message) meta.Session.commit() # to keep message and attachment ids stable attachments = [] for md5, mimetype, filename in zip(md5_list, mime_type_list, file_name_list): if message.author is not None: meta.set_active_user(message.author.id) request.environ['repoze.who.identity'] = message.author.id else: meta.set_active_user('') # XXX we are not filtering nonsense files like small # images, pgp signatures, vcards and html bodies yet. f = File(filename, filename, mimetype=mimetype, md5=md5) f.parent = message meta.Session.add(f) attachments.append(f) meta.Session.commit() # to keep attachment ids stable message.attachments.extend(attachments) if not message.in_moderation_queue: # only send emails for messages that don't have to be # moderated first self._queueMessage(message) meta.Session.commit() # Only send actual emails if commit succeeds self._sendQueuedMessages() return "Ok!"
def files(self, subject): c.current_tab = 'files' file_id = request.GET.get('serve_file') file = File.get(file_id) c.serve_file = file return render('subject/home_files.mako')
def delete(self, id): file = File.get(id) if file is None: abort(404) return self._delete(file)