Ejemplo n.º 1
0
    def lookup(self):
        # save posted variables for future
        title = self.form_result['title']
        location = self.form_result['location']
        session['subject_title'] = title
        session['subject_location_id'] = location.id
        session.save()

        # lookup for subjects similar to the one
        # that is about to be created
        search_params = {}
        search_params['obj_type'] = 'subject'
        search_params['text'] = title
        search_params['tags'] = ', '.join(location.title_path)
        search_params['language'] = location.language

        query = search_query(**search_params)
        c.similar_subjects = paginate.Page(
            query,
            items_per_page = 30,
            item_count = search_query_count(query),
            **search_params)

        if c.similar_subjects:
            return render('subject/add_lookup.mako')
        else:
            # no similar subjects found
            return redirect(url(controller='subject', action='add_description'))
Ejemplo n.º 2
0
    def _subjects(self, group):
        """
        The basis for views displaying all the subjects the group is already watching and allowing
        members to choose new subjects for the group.
        """
        c.search_target = url(controller='group', action='subjects_watch', id=group.group_id)

        #retrieve search parameters
        c.text = self.form_result.get('text', '')

        if 'tagsitem' in self.form_result or 'tags' in self.form_result:
            c.tags = self.form_result.get('tagsitem', None)
            if c.tags is None:
                c.tags = self.form_result.get('tags', None).split(', ')
        else:
            c.tags = c.group.location.hierarchy() if c.group.location is not None else []
        c.tags = ', '.join(filter(bool, c.tags))

        sids = [s.id for s in group.watched_subjects]

        search_params = {}
        if c.text:
            search_params['text'] = c.text
        if c.tags:
            search_params['tags'] = c.tags
        search_params['obj_type'] = 'subject'

        query = search_query(extra=_exclude_subjects(sids), **search_params)
        if self.form_result != {}:
            c.searched = True

        if search_params != {}:
            c.results = paginate.Page(
                query,
                page=int(request.params.get('page', 1)),
                item_count = search_query_count(query),
                items_per_page = 10,
                **search_params)

        return render('group/subjects.mako')
Ejemplo n.º 3
0
    def watch_subjects(self):
        c.breadcrumbs.append(self._actions("subjects"))
        c.search_target = url(controller="profile", action="watch_subjects")

        # retrieve search parameters
        c.text = self.form_result.get("text", "")

        tags = []

        if "tagsitem" in self.form_result:
            tags = self.form_result.get("tagsitem", None)
        elif "tags" in self.form_result:
            tags = self.form_result.get("tags", [])
            if isinstance(tags, basestring):
                tags = tags.split(", ")

        c.tags = ", ".join(filter(bool, tags))

        sids = [s.id for s in c.user.watched_subjects]

        search_params = {}
        if c.text:
            search_params["text"] = c.text
        if c.tags:
            search_params["tags"] = c.tags
        search_params["obj_type"] = "subject"

        query = search_query(extra=_exclude_subjects(sids), **search_params)
        c.results = paginate.Page(
            query,
            page=int(request.params.get("page", 1)),
            items_per_page=10,
            item_count=search_query_count(query),
            **search_params
        )

        c.watched_subjects = c.user.watched_subjects

        return render("profile/watch_subjects.mako")
Ejemplo n.º 4
0
 def _make_search_query(self, search_params):
     query = search_query(**search_params)
     if getattr(c, 'selected_sub_department_id', None):
         query = query.join(Subject)
         query = query.filter(Subject.sub_department_id==c.selected_sub_department_id)
     return query
Ejemplo n.º 5
0
 def _make_search_query(self, search_params):
     return search_query(**search_params)