def js_watch_subject(self): # This action is used in watch_subjects view and # differs from above ones by returning specific snippets. self._watch_subject() return render_mako_def( "profile/watch_subjects.mako", "subject_flash_message", subject=self._getSubject() ) + render_mako_def("profile/watch_subjects.mako", "watched_subject", subject=self._getSubject(), new=True)
def _reject_post(self, group, thread, redirecturl=None, ajax=False): success = False if thread.in_moderation_queue: thread.reject() meta.Session.commit() success = True if ajax: if success: return render_mako_def('mailinglist/administration.mako', 'rejectedMessage') else: return render_mako_def('mailinglist/administration.mako', 'warningMessage') if success: h.flash(_("Message %(link_to_message)s has been rejected.") % { 'link_to_message': h.link_to(thread.subject, thread.url()) }) else: h.flash(_("Could not reject %(link_to_message)s as it was already approved.") % { 'link_to_message': h.link_to(thread.subject, thread.url()) }) if redirecturl is None: redirecturl = group.url(controller='mailinglist', action='administration') redirect(redirecturl)
def js_watch_subject(self, group): self._watch_subject(group) return render_mako_def('group/subjects.mako', 'subject_flash_message', subject=self._getSubject()) +\ render_mako_def('group/subjects.mako', 'watched_subject', subject=self._getSubject(), new = True)
def file_info(self, group): """Information on the group's usage of the files area.""" info = { 'image' : render_mako_def('sections/files.mako', 'free_space_indicator', obj=group), 'text' : render_mako_def('sections/files.mako', 'free_space_text', obj=group) } section_id = request.POST.get('section_id', None) if section_id is not None: info['section_id'] = section_id return info
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 watch_subject(self): self._watch_subject() if request.params.has_key("js"): return "OK" else: h.flash(render_mako_def("subject/flash_messages.mako", "watch_subject", subject=self._getSubject())) redirect(request.referrer)
def catalog_js(self, location): self.form_result['tagsitem'] = location.hierarchy() obj_type = self.form_result.setdefault('obj_type', '*') if obj_type == 'teacher': self._search_teachers(location, self.form_result.get('text', '')) elif obj_type == 'department': self._list_departments(location, c.text) elif obj_type == 'sub_department': self._list_sub_departments(location, c.text) else: self._search() if self.form_result.has_key('text'): search_query = self.form_result['text'] else: search_query = None # return specific snippet per object type if obj_type in self.catalog_template_names: return render_mako_def(self.catalog_template_names[obj_type], 'search_results', results=c.results, search_query=search_query)
def forum_reply(self, group_id, category_id, thread_id): try: group_id = int(group_id) group = Group.get(group_id) except ValueError: group = Group.get(group_id) try: thread_id = int(thread_id) category_id = int(category_id) except ValueError: abort(404) category = ForumCategory.get(category_id) thread = ForumPost.get(thread_id) if group is None or category is None or thread is None: abort(404) post = make_forum_post(c.user, thread.title, self.form_result['message'], group_id=group.group_id, category_id=category_id, thread_id=thread_id, controller='forum') thread.mark_as_seen_by(c.user) meta.Session.commit() if request.params.has_key('js'): return render_mako_def('/sections/wall_entries.mako', 'thread_reply', id=post.id, author_id=post.created.id, message=post.message, created_on=post.created_on, allow_comment_deletion=True) else: self._redirect()
def mailinglist_reply(self, group_id, thread_id): try: group = Group.get(int(group_id)) thread_id = int(thread_id) except ValueError: abort(404) thread = GroupMailingListMessage.get(thread_id, group.id) if group is None or thread is None: abort(404) last_post = thread.posts[-1] msg = post_message(group, c.user, u"Re: %s" % thread.subject, self.form_result['message'], reply_to=last_post.message_id) if request.params.has_key('js'): return render_mako_def('/sections/wall_entries.mako', 'thread_reply', id=msg.id, author_id=msg.author_id if msg.author_id is not None else msg.author_or_anonymous, message=msg.body, created_on=msg.sent, attachments=msg.attachments, allow_comment_deletion=False) else: self._redirect()
def round(self): challengeid = int(request.GET.get('id', -1)) round = int(request.GET.get('round', -1)) c.challenge = self.session.query(Challenge).get(challengeid) c.round = self.session.query(ChallengeRound) \ .filter(ChallengeRound.challengeid == challengeid) \ .filter(ChallengeRound.round == round).first() loadSingleRoundResults(self.session, c.challenge, c.round) return render_mako_def('/challenge/challengereport.mako', 'roundReport', round=c.round)
def browse(self): self._get_unis(items_per_page=18) c.teaser = False c.obj_type = '*' if request.params.has_key('js'): return render_mako_def('/search/browse.mako', 'universities', unis=c.unis, ajax_url=url(controller='search', action='browse')) return render('/search/browse.mako')
def getevent(self): eventid = int(self.routingargs.get('other', 0)) event = c.eventmap.get(eventid, None) if event is None: return "Event does not exist" event.regentries = self.session.query(Registration).join('car').filter(Registration.eventid==event.id).filter(Car.driverid==c.driverid).all() event.payments = self.session.query(Payment).filter(Payment.eventid==event.id).filter(Payment.driverid==c.driverid).all() self._loadCars() return render_mako_def('/register/events.mako', 'eventdisplay', ev=event)
def browse(self): c.breadcrumbs = [{'title': _('Search'), 'link': url(controller='profile', action='browse')}] self._get_unis() c.obj_type = '*' if request.params.has_key('js'): return render_mako_def('/search/browse.mako', 'universities', unis=c.unis, ajax_url=url(controller='profile', action='browse')) return render('/profile/browse.mako')
def js_check_id(self): group_id = request.params.get('id') exists = len(group_id) < 4 or len(group_id) > 20 try: GroupIdValidator.to_python(group_id) except Invalid: exists = True return render_mako_def('group/create_base.mako', 'id_check_response', group_id=group_id, taken=exists)
def show_groups(self): """ """ already_selected = request.params.get('as', '') log.debug("These are selected: " + already_selected) if len(already_selected) > 0: already_selected = already_selected.split(',') return render_mako_def('/default/component/popups.mako', \ 'group_list', \ already_selected=already_selected)
def path(self): """ Returns the contents of the selected folder. Usually called via AJAX using the Popup that allows the user to select a path """ path = request.params.get('path', '/') log.debug("We want the folders in: " + path) return render_mako_def('/default/component/popups.mako', \ 'select_path', \ current=path)
def render(*args, **kwargs): if not config['beaker.cache.enabled']: if 'cache_key' in kwargs: del kwargs['cache_key'] if 'cache_expire' in kwargs: del kwargs['cache_expire'] if len(args)==2: # if args is 'template_filename', 'def_name' then call the def return render_mako_def(*args, **kwargs) else: # else if only 'template_filename' call the template file return render_mako(*args, **kwargs)
def _copy(self, source, file_to_copy): target_id = int(request.POST['target_id']) target = meta.Session.query(ContentItem).filter_by(id=target_id).one() new_file = file_to_copy.copy() new_file.folder = request.POST['target_folder'] target.files.append(new_file) meta.Session.commit() return render_mako_def('/sections/files.mako','file', file=new_file, new_file=True)
def js_group_search(self): """Group live search in group creation view.""" if hasattr(self, 'form_result'): location = self.form_result.get('location', None) year = self.form_result['year'] groups = meta.Session.query(Group) if location is not None: groups = groups.filter(Group.location_id.in_([loc.id for loc in location.flatten])) if year != '': groups = groups.filter(Group.year == date(int(year), 1, 1)) return render_mako_def('group/create_base.mako', 'live_search', groups=groups.all()) else: abort(404)
def _flag(self, file): if request.method == 'POST': reason = request.POST.get('reason') if c.user: email = c.user.email.email else: email = request.POST.get('reporter_email') extra_vars = dict(f=file, reason=reason, email=email) send_email(config['ututi_email_from'], config['ututi_email_from'], 'Flagged file: %s' % file.filename, render('/emails/flagged_file.mako', extra_vars=extra_vars), send_to=[config['ututi_email_from']]) return htmlfill.render(render_mako_def('/sections/files.mako', 'flag_file', f=file))
def render_def(template_name, def_name, extra_vars=None, cache_key=None, cache_type=None, cache_expire=None, **kwargs): """ Signature matches that of pylons actual render_mako_def. """ if not extra_vars: extra_vars = {} extra_vars.update(tpl_vars()) extra_vars.update(kwargs) return render_mako_def(template_name, def_name, cache_key=cache_key, cache_type=cache_type, cache_expire=cache_expire, **extra_vars)
def unteach(self, subject): if c.user.teaches(subject): c.user.unteach_subject(subject) h.flash(render_mako_def('subject/flash_messages.mako', 'unteach_subject', subject=subject)) else: h.flash(_("The course was not in your taught courses list.")) meta.Session.commit() redirect(url(controller='subject', action='home', id=subject.subject_id, tags=subject.location_path))
def users_groups(self): """ Returns the HTML containing a list of the System's Users and Groups. Usually called via AJAX using the Popup that allows the user to select Users and Groups. """ already_selected = request.params.get('as', '') log.debug("These are selected: " + already_selected) if len(already_selected) > 0: already_selected = already_selected.split(',') return render_mako_def('/default/component/popups.mako', \ 'select_user_group', \ already_selected=already_selected, shares=True)
def round(self): challengeid = myint(request.GET.get('id', -1)) round = myint(request.GET.get('round', -1)) c.challenge = self.session.query(Challenge).get(challengeid) if c.challenge is None: return "No challenge found" c.round = self.session.query(ChallengeRound) \ .filter(ChallengeRound.challengeid == challengeid) \ .filter(ChallengeRound.round == round).first() if c.round is None: return "No round found" loadSingleRoundResults(self.session, c.challenge, c.round) return render_mako_def('/challenge/challengereport.mako', 'roundReport', round=c.round)
def eventcomment_reply(self, event_id): event = Event.get(event_id) if event is None: abort(404) comment = EventComment(c.user, self.form_result['message']) event.post_comment(comment) meta.Session.commit() if request.params.has_key('js'): return render_mako_def('/sections/wall_entries.mako', 'thread_reply', id=comment.id, author_id=comment.created.id, message=comment.content, created_on=comment.created_on, allow_comment_deletion=True) else: self._redirect()
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 index(self): if c.user is not None: redirect(url(controller='profile', action='home')) else: # If default_location is set in configuration.ini, try # redirecting to it. default_location_path = config.get('default_location', None) if default_location_path: default_location = LocationTag.get(default_location_path) if default_location: return redirect(default_location.url()) self._get_unis() (c.subjects, c.groups, c.universities) = (self._subjects(), self._groups(), self._universities(limit=12)) c.all_universities = self._universities() if request.params.has_key('js'): return render_mako_def('/search/browse.mako', 'universities', unis=c.unis, ajax_url=url(controller='home', action='index')) c.slideshow = request.params.has_key('slide') return htmlfill.render(self._sign_up_form())
def search_js(self): self._search() return render_mako_def('/search/index.mako', 'search_results', results=c.results, controller='profile', action='search_js')
def _upload_file_short(self, obj): f = self._upload_file_basic(obj) return render_mako_def('/portlets/group.mako','portlet_file', file=f)
def _upload_file(self, obj): f = self._upload_file_basic(obj) if f is not None: return render_mako_def('/sections/files.mako','file', file=f, new_file=True) else: return 'UPLOAD_FAILED'
def Event(self): carid = int(self.routingargs.get('other', 0)) c.results = self._classlist(carid) c.e2label = self.e2label return render_mako_def('/live/tables.mako', 'classlist')
def getprofile(self): self._loadDriver() return render_mako_def('/register/profile.mako', 'profile')
def getcars(self): self._loadCars() return render_mako_def('/register/cars.mako', 'carlist')
def snippet(self): """Render a short snippet with the basic teacher information. Used in university's teacher catalog to render search results.""" return render_mako_def('/sections/content_snippets.mako', 'teacher', object=self)
def Champ(self): carid = int(self.routingargs.get('other', 0)) c.champ = self._champlist(carid) c.cls = self.cls c.e2label = self.e2label return render_mako_def('/live/tables.mako', 'champlist')