当前位置: 首页>>代码示例>>Python>>正文


Python Session.query方法代码示例

本文整理汇总了Python中abstrackr.model.meta.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在abstrackr.model.meta.Session的用法示例。


在下文中一共展示了Session.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: my_projects

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
    def my_projects(self):
        person = request.environ.get('repoze.who.identity')['user']
        c.person = person

        # Get user object from db.
        user = controller_globals._get_user_from_email(person.email)

        # Set user's show preference defaults in case they weren't set.
        if (user.show_journal==True or user.show_journal==False):
            c.show_journal = user.show_journal
        else:
            user.show_journal = True

        if (user.show_authors==True or user.show_authors==False):
            c.show_authors = user.show_authors
        else:
            user.show_authors = True

        if (user.show_keywords==True or user.show_keywords==False):
            c.show_keywords = user.show_keywords
        else:
            user.show_keywords = True

        project_q = Session.query(model.Project)
        c.leading_projects = user.leader_of_projects
        leading_project_ids = [proj.id for proj in c.leading_projects]

        c.participating_projects = [p for p in user.member_of_projects if p.id not in leading_project_ids]

        c.review_ids_to_names_d = self._get_review_ids_to_names_d(c.participating_projects)

        statuses_q = Session.query(model.PredictionsStatus)
        c.statuses = {}

        c.do_we_have_a_maybe = {}
        for project_id in leading_project_ids:

            predictions_for_review = statuses_q.filter(model.PredictionsStatus.project_id==project_id).all()
            if len(predictions_for_review) > 0 and predictions_for_review[0].predictions_exist:
                c.statuses[project_id] = True
            else:
                c.statuses[project_id] = False

            c.do_we_have_a_maybe[project_id] = False

        # Flag projects that have locked priorities
        c.projects_w_locked_priorities = self._get_projects_w_locked_priorities(leading_project_ids)

        c.my_work = False
        c.my_projects = True

        return render('/accounts/dashboard.mako')
开发者ID:shihikoo,项目名称:abstrackr-web,代码行数:54,代码来源:account.py

示例2: _build_tags_dict

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
 def _build_tags_dict(self):
     tags = Session.query(model.Tag, model.TagType).filter(model.Tag.citation_id.in_(self.all_citations)).join(model.TagType, model.Tag.tag_id == model.TagType.id).all()
     for citation_id in self.all_citations:
         if citation_id not in self.citation_to_tags_dict:
             self.citation_to_tags_dict[citation_id] = []
     for tag in tags:
         self.citation_to_tags_dict[tag[0].citation_id].append(tag[1].text)
开发者ID:bisen,项目名称:abstrackr-web,代码行数:9,代码来源:csvbuilder.py

示例3: _get_username_from_id

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
 def _get_username_from_id(self, id):
     if id == CONSENSUS_USER:
         return "consensus"
     if id not in self.user_dict:
         user_q = Session.query(model.User)
         self.user_dict[id] = user_q.filter(model.User.id == id).one().username
     return self.user_dict[id]
开发者ID:bisen,项目名称:abstrackr-web,代码行数:9,代码来源:csvbuilder.py

示例4: _get_users_labels_for_assignment

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
 def _get_users_labels_for_assignment(self, project_id, user_id, assignment_id):
     """Returns a user's list of labels across a specific project"""
     labels_q = Session.query(model.Label)
     labels = labels_q.filter_by(project_id=project_id,
                                 user_id=user_id,
                                 assignment_id=assignment_id).all()
     return labels
开发者ID:shihikoo,项目名称:abstrackr-web,代码行数:9,代码来源:account.py

示例5: _get_notes_for_citation

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
 def _get_notes_for_citation(self, citation_id, user_id):
     notes_q = Session.query(model.Note)
     notes = notes_q.filter(and_(\
             model.Note.citation_id == citation_id,
             model.Note.creator_id == user_id)).all()
     if len(notes) > 0:
         return notes[0]
     return None
开发者ID:bisen,项目名称:abstrackr-web,代码行数:10,代码来源:csvbuilder.py

示例6: _row_unique

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
def _row_unique(row, project_id, user_id):
  try:
    labeledfeatures = Session.query(model.LabeledFeature).\
                             filter_by(term = row[0]).\
                             filter_by(label = row[1]).\
                             filter_by(project_id = project_id).\
                             filter_by(user_id = user_id).all()
  except IndexError, e:
    return False, 2
开发者ID:bisen,项目名称:abstrackr-web,代码行数:11,代码来源:upload_term_helper.py

示例7: _build_notes_dict

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
    def _build_notes_dict(self):
        notes = Session.query(model.Note).filter(model.Note.citation_id.in_(self.all_citations)).all()
        for citation_id in self.all_citations:
            if citation_id not in self.citation_to_notes_dict:
                self.citation_to_notes_dict[citation_id] = {}
                for labeler in self.all_labelers:
                    self.citation_to_notes_dict[citation_id][labeler.username] = None

        for note in notes:
            self.citation_to_notes_dict[note.citation_id][self._get_username_from_id(note.creator_id)] = note
开发者ID:bisen,项目名称:abstrackr-web,代码行数:12,代码来源:csvbuilder.py

示例8: _get_all_priorities_locked_by_this_user

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
 def _get_all_priorities_locked_by_this_user(self, all_assignments):
     locked_priorities = []
     for a in all_assignments:
         user_id = a.user_id
         project_id = a.project_id
         priorities_q = Session.query(model.Priority).filter_by(project_id=project_id).\
                                                      filter_by(locked_by=user_id)
         priorities = priorities_q.all()
         locked_priorities.extend([p for p in priorities])
     return list(set(locked_priorities))
开发者ID:shihikoo,项目名称:abstrackr-web,代码行数:12,代码来源:account.py

示例9: _get_tag_types_for_review

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
    def _get_tag_types_for_review(self, review_id, only_for_user_id=None):
        tag_q = Session.query(model.TagType)

        if only_for_user_id:
            tag_types = tag_q.filter(and_(\
                        model.TagType.project_id == review_id,\
                        model.TagType.creator_id == only_for_user_id
                )).all()
        else:
            tag_types = tag_q.filter(model.TagType.project_id == review_id).all()
        return [tag_type.text for tag_type in tag_types]
开发者ID:bisen,项目名称:abstrackr-web,代码行数:13,代码来源:csvbuilder.py

示例10: _project_has_locked_priorities

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
    def _project_has_locked_priorities(self, project_id):
        """Returns True if project has any locked priorities, else False

           Integer -> Boolean
        """

        priorities_q = Session.query(model.Priority).\
                               filter_by(project_id=project_id).\
                               filter_by(is_out=1)
        priority = priorities_q.first()
        if priority:
            return True
        else:
            return False
开发者ID:shihikoo,项目名称:abstrackr-web,代码行数:16,代码来源:account.py

示例11: _get_tag_types_for_citation

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
    def _get_tag_types_for_citation(self, citation_id, objects=False):
        tags = self._get_tags_for_citation(citation_id)
        # now map those types to names
        tag_type_q = Session.query(model.TagType)
        tags = []

        for tag in tags:
            tag_obj = tag_type_q.filter(model.TagType.id == tag.tag_id).one()

            if objects:
                tags.append(tag_obj)
            else:
                tags.append(tag_obj.text)

        return tags
开发者ID:bisen,项目名称:abstrackr-web,代码行数:17,代码来源:csvbuilder.py

示例12: _get_tags_for_citation

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
    def _get_tags_for_citation(self, citation_id, texts_only=True, only_for_user_id=None):

        tag_q = Session.query(model.Tag)
        tags = None
        if only_for_user_id:
            # then filter on the study and the user
            tags = tag_q.filter(and_(\
                    model.Tag.citation_id == citation_id,\
                    model.Tag.creator_id == only_for_user_id)).all()
        else:
            # all tags for this citation, regardless of user
            tags = tag_q.filter(model.Tag.citation_id == citation_id).all()

        if texts_only:
            return self._tag_ids_to_texts([tag.tag_id for tag in tags])
        return tags
开发者ID:bisen,项目名称:abstrackr-web,代码行数:18,代码来源:csvbuilder.py

示例13: gen_token_to_reset_pwd

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
    def gen_token_to_reset_pwd(self, user):
        # generate a random token for the user to reset their password; stick
        # it in the database
        make_token = lambda N: ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
        reset_pwd_q = Session.query(model.ResetPassword)
        existing_tokens = [entry.token for entry in reset_pwd_q.all()]
        token_length=10
        cur_token = make_token(token_length)
        while cur_token in existing_tokens:
            cur_token = make_code(token_length)

        reset = model.ResetPassword()
        reset.token = cur_token
        reset.user_email = user.email
        Session.add(reset)
        Session.commit()
        return cur_token
开发者ID:shihikoo,项目名称:abstrackr-web,代码行数:19,代码来源:account.py

示例14: confirm_password_reset

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
 def confirm_password_reset(self, id):
     token = str(id)
     reset_pwd_q = Session.query(model.ResetPassword)
     # we pull all in case they've tried to reset their pwd a few times
     # by the way, these should time-expire...
     matches = reset_pwd_q.filter(model.ResetPassword.token == token).all()
     if len(matches) == 0:
         return """
             Hrmm... It looks like you're trying to reset your password, but I can't match the provided token.
             Please go back to the email that was sent to you and make sure you've copied the URL correctly.
             """
     user = controller_globals._get_user_from_email(matches[0].user_email)
     for match in matches:
         Session.delete(match)
     user._set_password(token)
     Session.commit()
     return '''
       ok! your password has been set to %s (you can change it once you've logged in).\n
       <a href="%s">log in here</a>.''' % (token, url('/', qualified=True))
开发者ID:shihikoo,项目名称:abstrackr-web,代码行数:21,代码来源:account.py

示例15: my_work

# 需要导入模块: from abstrackr.model.meta import Session [as 别名]
# 或者: from abstrackr.model.meta.Session import query [as 别名]
    def my_work(self):
        person = request.environ.get('repoze.who.identity')['user']
        c.person = person
        user = controller_globals._get_user_from_email(c.person.email)
        if not user:
            log.error('''\
Hum...fetching user from the database returned False.
We need to investigate. Go remove the catch all in
controller_globals.py, method _get_user_from_email()
to see which OperationalError is being raised ''')

        # If somehow the user's citation settings variables don't get initialized yet,
        # then the following 3 if-else blocks should take care of it in order to avoid
        # any errors due to the values of the variables being null:
        c.show_journal = user.show_journal if not user.show_journal is None else True

        if (user.show_authors==True or user.show_authors==False):
            c.show_authors = user.show_authors
        else:
            user.show_authors = True

        if (user.show_keywords==True or user.show_keywords==False):
            c.show_keywords = user.show_keywords
        else:
            user.show_keywords = True


        # pull all assignments for this person
        assignment_q = Session.query(model.Assignment)
        all_assignments = assignment_q.filter(model.Assignment.user_id == person.id).all()

        # This process is incredibly slow. Take it out for now and find out
        # why the .done and .done_so_far field on assignment is off sometimes.
        #self._set_assignment_done_status(all_assignments)

        self._clear_this_user_locks(all_assignments)

        # Build assignment completion status dictionary
        c.d_completion_status = self._get_assignment_completion_status(all_assignments)

        c.outstanding_assignments = [a for a in all_assignments if not a.done]
        # if there's an initial assignment, we'll only show that.
        assignment_types = [assignment.assignment_type for assignment in \
                                                    c.outstanding_assignments]

        #####
        # for any review that has an initial assignment, we will show
        # *only* that assignment, thereby forcining participants to
        # finish initial assignments before moving on to other
        # assignments. fix for issue #5.
        ####
        # which reviews have (outstanding) initial assigments?
        reviews_with_initial_assignments = []
        for assignment in c.outstanding_assignments:
            if assignment.assignment_type == "initial":
                reviews_with_initial_assignments.append(assignment.project_id)


        # now remove other (non-initial) assignments for reviews
        # that have an initial assignment
        filtered_assignments = [assignment for assignment in c.outstanding_assignments if \
                                assignment.project_id not in reviews_with_initial_assignments or \
                                assignment.assignment_type == "initial"]

        c.outstanding_assignments = filtered_assignments

        c.finished_assignments = [a for a in all_assignments if a.done]


        project_q = Session.query(model.Project)
        c.participating_projects = user.member_of_projects
        c.review_ids_to_names_d = self._get_review_ids_to_names_d(c.participating_projects)

        c.my_work = True
        c.my_projects = False
        return render('/accounts/dashboard.mako')
开发者ID:shihikoo,项目名称:abstrackr-web,代码行数:78,代码来源:account.py


注:本文中的abstrackr.model.meta.Session.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。