• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python db_session.DB_Session_Factory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中model.db_session.DB_Session_Factory的典型用法代码示例。如果您正苦于以下问题:Python DB_Session_Factory类的具体用法?Python DB_Session_Factory怎么用?Python DB_Session_Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: do_controller_specific_work

 def do_controller_specific_work(self):
     db_session = DB_Session_Factory.get_db_session()
     needed_user = db_session.query(User).get(self.resource_id)
     if needed_user is None:
         raise API_Exception("400 Bad Request", "Couldn't find a user with user_id <%s>" % (self.resource_id))
     else:
         return HTTP_Response("200 OK", {"user": needed_user.for_api(self.user)})
开发者ID:vovagalchenko,项目名称:mafia,代码行数:7,代码来源:get.py


示例2: do_controller_specific_work

    def do_controller_specific_work(self):    
        if self.user is None:
            raise Authorization_Exception("You must be logged in to list your targets.")

        db_session = DB_Session_Factory.get_db_session() 
        user_profile = db_session.query(UserProfile).get(self.user.phonenumber)

        if user_profile is None:
            raise API_Exception(500, "User profile does not exist")
        
        creditsWillConsume = len(self.event_ids)
        
        if user_profile.credits < creditsWillConsume:
            creditsRequired = creditsWillConsume - user_profile.credits
            raise API_Exception(402, {'credits_required' : creditsRequired})

        for event_id in self.event_ids:
            target = Target()
            target.event_id = event_id
            target.user_phone_number = self.user.phonenumber
            db_session.add(target)

        user_profile.credits = user_profile.credits - creditsWillConsume
        user_alert_dict = None
        if user_profile.first_target_timestamp is None:
            user_profile.first_target_timestamp = datetime.now()
            user_alert_dict = {
                'title' : 'Congratulations!',
                'msg'   : "You've set up your first tracked class. Whenever your tracked classes change enrollment status to 'Open' or 'Waitlist' we will send you push notifications immediately."
            }
        db_session.commit()
 
        return HTTP_Response('200 OK', {'credits' : user_profile.credits, 'user_msg' : user_alert_dict})
开发者ID:vovagalchenko,项目名称:class-ninja,代码行数:33,代码来源:create.py


示例3: is_authorized_to_access_game

 def is_authorized_to_access_game(self, game_id):
     db_session = DB_Session_Factory.get_db_session()
     player = db_session.query(Player).filter(Player.game_id == game_id, Player.user_id == self.user_id).first()
     ret_value = True
     if player is None:
         ret_value = False
     return ret_value
开发者ID:vovagalchenko,项目名称:mafia,代码行数:7,代码来源:user_model.py


示例4: print_body_for_user

 def print_body_for_user(self, authenticated_user):
     csv_writer = csv.writer(sys.stdout)
     db_session = DB_Session_Factory.get_db_session()
     interview_fields = [column.name for column in Interview.__mapper__.columns]
     candidate_fields = ['position']
     csv_writer.writerow(interview_fields + candidate_fields)
     [ csv_writer.writerow([getattr(interview, interview_field) for interview_field in interview_fields] + [getattr(candidate, candidate_field) for candidate_field in candidate_fields]) for interview, candidate in db_session.query(Interview, Candidate).filter(Interview.candidate_name == Candidate.candidate_name) ]
开发者ID:vovagalchenko,项目名称:onsite-inflight,代码行数:7,代码来源:interviews_dump.py


示例5: print_body

 def print_body(self):
     db_session = DB_Session_Factory.get_db_session()
     candidate = db_session.query(Candidate).get(self.candidate_name)
     if candidate is None:
         print json.dumps({"candidate_name": self.candidate_name, "error": "Invalid candidate_name passed in."})
     else:
         print candidate.json_representation(self.date, show_scores=self.show_scores)
开发者ID:heidivt73,项目名称:onsite-inflight,代码行数:7,代码来源:candidate_detail.py


示例6: print_body_for_user

 def print_body_for_user(self, authenticated_user):
     db_session = DB_Session_Factory.get_db_session()
     panel = []
     for interview in db_session.query(Interview).filter(Interview.candidate_name == self.candidate_name, func.date(Interview.start_time) == func.date(datetime.now())):
         panel.append({
             'email' : interview.interviewer_email,
             'optional' : True,
             'responseStatus' : 'needsAction'
         })
     if len(panel) is 0:
         print json.dumps({'error' : 'Nobody to invite to roundup for ' + self.candidate_name})
     else:
         event = {}
         event['organizer'] = {'self' : True}
         event['location'] = 'RWC-A-423-Lambda-5-AV2.1'
         event['start'] = datetime_to_google_ts(self.roundup_start_date)
         event['end'] = datetime_to_google_ts(self.roundup_start_date + timedelta(minutes = self.roundup_length))
         event['summary'] = "Roundup for " + self.candidate_name
         event['guestsCanInviteOthers'] = True
         event['attendees'] = panel
         now_date = date.today()
         event['description'] = "https://onsite-inflight.com/#" + str(now_date.year) + "-" + ("%02d"%now_date.month) + "-" + ("%02d"%now_date.day) + "/" + urllib.quote_plus(self.candidate_name)
         calendar = Google_Calendar.get_calendar()
         try:
             calendar.service.events().insert(calendarId = "[email protected]", body = event, sendNotifications=True).execute(calendar.http)
             print json.dumps({'status' : 'success'})
         except HttpError as e:
             error_response = json.dumps({"error" : "Google calendar http error: " + e.content})
             sys.stderr.write(error_response)
             print error_response
         except AccessTokenRefreshError:
             print json.dumps({"error" : "The Google calendar credentials have been revoked or expired"})
开发者ID:vovagalchenko,项目名称:onsite-inflight,代码行数:32,代码来源:schedule_roundup.py


示例7: main

def main(argv):
    db_session = DB_Session_Factory.get_db_session()
    deletion_sql = Department.__table__.delete('1')
    db_session.execute(deletion_sql)
    deletion_sql = Department_Keyword.__table__.delete('1')
    db_session.execute(deletion_sql)

    f = open("../data/bootstrap/departments.json", 'r')
    departments_string = f.read()
    departments = json.loads(departments_string)
    for department_dict in departments:
        department = Department(department_dict['id'], department_dict['name'], department_dict['maximum_coffee_break_length'], department_dict['recruiter_name'], department_dict['recruiter_email'], department_dict['recruiter_phone_number'])
        db_session.add(department)
        db_session.commit()
        for keyword in department_dict.get('keywords', []):
            department_keyword = Department_Keyword(department.id, keyword)
            db_session.add(department_keyword)
        db_session.commit()
    for candidate in db_session.query(Candidate):
        department = candidate.calculate_department()
        if department is None:
            department_name = "None"
            department_id = 0
        else:
            department_name = department.name
            department_id = department.id
        candidate_position = "None" if candidate.position is None else candidate.position
        print '\t\t'.join([candidate.candidate_name, candidate.position, department_name])
        if candidate.department_id is not None:
            candidate.department_id = department_id
            db_session.add(candidate)
    db_session.commit()
开发者ID:vovagalchenko,项目名称:onsite-inflight,代码行数:32,代码来源:build_departments_table.py


示例8: main

def main(argv):
    db_session = DB_Session_Factory.get_db_session()
    deletion_sql = Interviewer.__table__.delete('1')
    db_session.execute(deletion_sql)
    interviewers = {}
    
    with open("scripts/interviewers.dat", "r") as interviewer_file:
        for interviewer_info in interviewer_file:
            interviewer_info = interviewer_info.strip(' \t\n\r')
            if not interviewer_info:
                continue
            interviewer_data = interviewer_info.split("\t")
            print interviewer_data[0] + "\t" + interviewer_data[1] + "\t" + interviewer_data[2]
            interviewer = Interviewer(interviewer_data[1], interviewer_data[0], interviewer_data[2])
            if len(interviewer_data) == 4:
                original_url = interviewer_data[3]
                final_url = '/avatars/' + interviewer.name.lower().replace(' ', '-')
                match = re.search('\.([^.]*?)$', original_url)
                if match:
                    final_url += '.' + match.group(1)
                local_path = ROOT + final_url
                if not path.isfile(local_path):
                    print 'Downloading image for ' + final_url
                    urlretrieve(interviewer_data[3], local_path)
                interviewer.avatar_url = final_url
            interviewers[interviewer_data[1]] = interviewer
            db_session.add(interviewer)

    print "Adding opt-ins now..."
    for optin in db_session.query(Opt_In):
        if interviewers.get(optin.email, None) is None:
            print optin.name + "\t" + optin.email + "\t" + optin.phone_number;
            db_session.add(Interviewer(optin.email, optin.name, optin.phone_number))
    db_session.commit()
开发者ID:heidivt73,项目名称:onsite-inflight,代码行数:34,代码来源:rebuild_interviewer_table.py


示例9: do_controller_specific_work

 def do_controller_specific_work(self):
     if self.user is None:
         raise Authorization_Exception("You must be logged in to list your targets.")
     targets = self.user.targets
     events = sorted(map(lambda target: target.event, targets), key = lambda event: event.section_id)
     targets_by_event_id = {}
     for target in targets:
         targets_by_event_id[target.event_id] = target.target_id
     events_by_section_id = dict((k, list(g)) for k, g in groupby(events, lambda event: event.section_id))
     db_session = DB_Session_Factory.get_db_session()
     sections = db_session.query(Section).filter(Section.section_id.in_(events_by_section_id.keys())).order_by(Section.course_id).all()
     sections_by_course_id = dict((k, list(g)) for k, g in groupby(sections, lambda section: section.course_id))
     courses = db_session.query(Course).filter(Course.course_id.in_(sections_by_course_id.keys())).all()
     response = []
     for course in courses:
         course_dict = course.for_api()
         sections_list = []
         for section in sections_by_course_id.get(course.course_id):
             section_dict = section.for_api()
             events = []
             for event_in_this_section in events_by_section_id[section.section_id]:
                 event_dict = event_in_this_section.for_api()
                 target_id_number = targets_by_event_id.get(event_in_this_section.event_id, None)
                 if target_id_number is not None:
                      event_dict['target_id'] = str(target_id_number)
                 events.append(event_dict)
             section_dict['events'] = events
             sections_list.append(section_dict)
         course_dict['course_sections'] = sections_list
         response.append(course_dict)
     return HTTP_Response('200 OK', {'targets' : response})
开发者ID:vovagalchenko,项目名称:class-ninja,代码行数:31,代码来源:list.py


示例10: for_api

 def for_api(self, asking_player, min_time=None):
     all_columns = super(Game, self).for_api()
     db_session = DB_Session_Factory.get_db_session()
     all_columns["players"] = []
     mafia_player_ids = []
     for player in self.players.all():
         all_columns["players"].append(player.for_api(asking_player))
         if player.role == "MAFIA":
             mafia_player_ids.append(player.player_id)
     num_events_limit = 20
     conditions = [Game_Event.game_id == self.game_id]
     if min_time is not None:
         if asking_player.role != "MAFIA" and len(mafia_player_ids) > 0:
             conditions.append(
                 not_(and_(Game_Event.game_state == "NIGHT", Game_Event.from_player_id.in_(mafia_player_ids)))
             )
         conditions.append(Game_Event.created > min_time)
         game_events = map(
             lambda game_event: game_event.for_api(),
             db_session.query(Game_Event)
             .filter(*conditions)
             .order_by(Game_Event.created.asc())
             .limit(num_events_limit)
             .all(),
         )
         all_columns["game_events"] = {"limit": num_events_limit, "min_time": min_time, "events": game_events}
     return all_columns
开发者ID:vovagalchenko,项目名称:mafia,代码行数:27,代码来源:game.py


示例11: log

def log(event_name, phone_number, data):
    if len(phone_number) > 10:
        phone_number = phone_number[2:]
    db_session = DB_Session_Factory.get_db_session()
    log_event = Log(event_name, phone_number, data)
    db_session.add(log_event)
    db_session.commit()
开发者ID:heidivt73,项目名称:onsite-inflight,代码行数:7,代码来源:logger.py


示例12: print_body_for_user

    def print_body_for_user(self, authenticated_user):
        db_session = DB_Session_Factory.get_db_session()
        if self.tag is not None:
            print json.dumps({'tag' : self.tag, 'teammates' : self.get_teammates_from_tag(self.tag)})
        else:
            candidate = db_session.query(Candidate).get(self.candidate_name)
            position = re.sub("^.*?,\s?", "", candidate.position)
            position_list = re.split("[/ ]", position)

            if candidate is None:
                print json.dumps({'candidate_name' : self.candidate_name, 'error' : 'Invalid candidate_name passed in.'})
            else:
                interviewer_list = []
                for position_token in position_list:
                    if position_token == "":
                        continue
                    tag = db_session.query(Interviewer_Tag).get(position_token)
                    if tag is not None:
                        for interviewer_email in tag.get_interviewers():
                            interviewer_list.append(db_session.query(Interviewer).get(interviewer_email).dict_representation())
                        break
                            
                print json.dumps({
                    'candidate_name' : self.candidate_name,
                    'position' : position,
                    'teammates' : interviewer_list
                })
开发者ID:vovagalchenko,项目名称:onsite-inflight,代码行数:27,代码来源:teammates.py


示例13: print_body_for_user

 def print_body_for_user(self, authenticated_user):
     db_session = DB_Session_Factory.get_db_session()
     candidate = db_session.query(Candidate).get(self.candidate_name)
     if candidate is None:
         print json.dumps({'candidate_name' : self.candidate_name, 'error' : 'Invalid candidate_name passed in.'})
     else:
         print candidate.json_representation(self.date, show_scores = self.show_scores)
开发者ID:vovagalchenko,项目名称:onsite-inflight,代码行数:7,代码来源:candidate_detail.py


示例14: search_for_departments_by_dept_ids

 def search_for_departments_by_dept_ids(self, department_ids): 
     db_session = DB_Session_Factory.get_db_session()
     if len(department_ids) == 0:
        return []
     
     departments = db_session.query(Department).filter(Department.department_id.in_(department_ids)).all()
     return departments
开发者ID:vovagalchenko,项目名称:class-ninja,代码行数:7,代码来源:get.py


示例15: search_for_courses

 def search_for_courses(self, whereClause):
     db_session = DB_Session_Factory.get_db_session()
     sqlQuery = "SELECT course_id from " + Course.__tablename__ + " " + whereClause + " LIMIT 20"
     course_ids = self.single_row_query(sqlQuery)
     if len(course_ids) == 0:
         return []
     courses = db_session.query(Course).filter(Course.course_id.in_(course_ids)).all()
     return courses
开发者ID:vovagalchenko,项目名称:class-ninja,代码行数:8,代码来源:get.py


示例16: generate_access_token

 def generate_access_token(self):
     db_session = DB_Session_Factory.get_db_session() 
     access_token = uuid.uuid4()
     while True:
         users_with_generated_access_token = db_session.query(User).filter(User.access_token == access_token)
         if (len(users_with_generated_access_token.all()) == 0):
             return access_token 
         access_token = uuid.uuid4()
开发者ID:vovagalchenko,项目名称:class-ninja,代码行数:8,代码来源:update.py


示例17: single_row_query

    def single_row_query(self, sqlQuery): 
        db_session = DB_Session_Factory.get_db_session()
        query_result = db_session.execute(sqlQuery)
        searched_department_ids = []
        for row in query_result:
            searched_department_ids.append(row[0])

        return searched_department_ids
开发者ID:vovagalchenko,项目名称:class-ninja,代码行数:8,代码来源:get.py


示例18: get_teammates_from_tag

 def get_teammates_from_tag(self, tag_string):
     ret_value = []
     db_session = DB_Session_Factory.get_db_session()
     tag = db_session.query(Interviewer_Tag).get(tag_string)
     if tag is not None:
         for interviewer_email in tag.get_interviewers():
             ret_value.append(db_session.query(Interviewer).get(interviewer_email).dict_representation())
     return ret_value
开发者ID:vovagalchenko,项目名称:onsite-inflight,代码行数:8,代码来源:teammates.py


示例19: print_body_for_user

 def print_body_for_user(self, authenticated_user):
     opt_ins = []
     db_session = DB_Session_Factory.get_db_session()
     for interviewer in db_session.query(Interviewer).filter(Interviewer.created > self.date):
         interviewer_dict = interviewer.dict_representation()
         interviewer_dict['phone_number'] = interviewer.phone_number
         interviewer_dict['nickname'] = interviewer.nickname()
         opt_ins.append(interviewer_dict)
     print json.dumps(opt_ins)
开发者ID:vovagalchenko,项目名称:onsite-inflight,代码行数:9,代码来源:opt_in_list.py


示例20: print_body_for_user

 def print_body_for_user(self, authenticated_user):
     db_session = DB_Session_Factory.get_db_session()
     employee = db_session.query(Employee).get(authenticated_user.email)
     if employee is None:
         employee = Employee(authenticated_user.email)
     reimbursements = []
     for reimbursement in db_session.query(Reimbursement).all():
         reimbursements.append(reimbursement.dict_representation())
     final_output_dict = {"employee": employee.dict_representation(), "reimbursement_policy": reimbursements}
     print json.dumps(final_output_dict)
开发者ID:vovagalchenko,项目名称:onsite-inflight,代码行数:10,代码来源:reimbursements.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python elements.PeriodicTable类代码示例发布时间:2022-05-27
下一篇:
Python db.drop_all函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap