def upload_file_js(self): target_id = request.params.get('target_id') target = None try: target_id = int(target_id) target = ContentItem.get(target_id) if isinstance(target, Group) and\ (not target.is_member(c.user)\ or not target.has_file_area\ or target.upload_status == target.LIMIT_REACHED): target = None if not isinstance(target, (Group, Subject)): target = None except ValueError: target = None if target is None: return 'UPLOAD_FAILED' f = self._upload_file_basic(target) if f is None: return 'UPLOAD_FAILED' else: evt = meta.Session.query(FileUploadedEvent).filter_by(file_id=f.id).one().wall_entry() return evt
def content_link(content_id): from ututi.model import ContentItem, Subject, Group, Page, File, PrivateMessage, ForumPost from ututi.model.mailing import GroupMailingListMessage from pylons import url item = ContentItem.get(content_id) if type(item) == ForumPost: # we don't want to link to forum posts anymore return item.title if type(item) in [Subject, Group, Page]: if item.deleted_on is None: return link_to(item.title, url(controller='content', action='get_content', id=content_id)) else: return item.title elif type(item) == File: return link_to(item.filename, url(controller='content', action='get_content', id=content_id)) elif type(item) in [PrivateMessage, GroupMailingListMessage]: return link_to(item.subject, url(controller='content', action='get_content', id=content_id))
def get_content(self, id=None, next_action=None): try: id = int(id) except (ValueError, TypeError): abort(404) content_item = ContentItem.get(id) if content_item is None: abort(404) if content_item.deleted_on is not None: abort(404) if next_action is None: redirect(content_item.url()) else: redirect(content_item.url(action=next_action))
def _to_python(self, value, state): obj = None # check if this is a plain numeric id try: num_id = int(value) obj = ContentItem.get(num_id) except ValueError: pass # check if the id is a path to a subject if obj is None and value.startswith('subject'): path = value.split('/')[1:] location = LocationTag.get(path[:-1]) obj = Subject.get(location, path.pop()) # check if the object is a group if obj is None and value.startswith('group'): id = value.split('/') obj = Group.get(id.pop()) return obj