Example #1
0
File: docs.py Project: szkocka/api
    def find(cls, keyword, status, tag, page):
        page_size = int(os.environ['PAGE_SIZE'])
        offset = page_size * int(page)

        query = 'title:*'
        if keyword:
            query = keyword.encode('utf-8').strip()

        if status:
            query += ' AND status:{0}'.format(status)
        if tag:
            encoded_tag = tag.encode('utf-8').strip()
            query += ' AND tags:{0}'.format(encoded_tag)

        search_query = search.Query(
                query_string=query.strip(),
                options=search.QueryOptions(ids_only=True,
                                            limit=page_size,
                                            offset=offset)
        )

        logging.info(query)
        results = RESEARCH_INDEX.search(search_query).results

        found_researches = map(lambda r: Research.get(int(r.doc_id)), results)

        return filter(lambda r: r.status != StatusType.DELETED, found_researches)
Example #2
0
    def get(self, current_user):
        relationship_types = get_relationship_types(current_user)

        cursor = request.args.get('cursor')
        researches, cursor, _ = Research.all(cursor)

        return ok(ListResearchesJson(researches, relationship_types, cursor))
Example #3
0
File: docs.py Project: szkocka/api
    def reindex_all(cls):
        for r in Research.all2():
            r_index = ResearchIndex(r)
            r_index.delete()

            if r.status == StatusType.ACTIVE:
                r_index.put()
Example #4
0
File: tasks.py Project: szkocka/api
    def post(self):
        research_id = int(request.json['research_id'])
        research = Research.get(research_id)

        ResearchIndex(research).put()

        return ok_msg('Research indexed.')
Example #5
0
    def wrapper(*args, **kwargs):
        if 'research_id' not in kwargs:
            return bad_request('To use insert_research wrapper research_id must be in url.')

        _id = kwargs['research_id']
        research = Research.get(int(_id))

        if research is None:
            return research_not_found(_id)

        del kwargs['research_id']
        kwargs['research'] = research

        return func(*args, **kwargs)
Example #6
0
 def get(self):
     tags = Research.all_tags()
     return ok(TagsJson(tags))
Example #7
0
File: users.py Project: szkocka/api
    def get(self, current_user, user):
        relationship_types = get_relationship_types(user)
        cursor = request.args.get('cursor')
        users, cursor, _ = Research.by_user(user.key, cursor)

        return ok(ListUserResearchesJson(users, relationship_types, cursor))
Example #8
0
File: users.py Project: szkocka/api
    def get(self, current_user, user):
        supervisor_of = Research.by_supervisor(user.key)
        researcher_in = Research.by_researcher(user.key)

        return ok(UserDetailsJson(user, supervisor_of, researcher_in))