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


Python Session.query方法代码示例

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


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

示例1: index

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
def index():
	if session.get('logged_in'):
		return redirect(url_for('main'))

	new = Session.query(music).order_by(music.id.desc())[0:10]
	most = Session.query(music).order_by(music.count.desc())[0:10]

	return render_template('login.html', most=most, new = new)
开发者ID:Pusnow,项目名称:OSWebMusicPlayer,代码行数:10,代码来源:View.py

示例2: addfav

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
def addfav():
	data = request.get_json()
	playlist1 = Session.query(playlist).filter(playlist.userid==session['userid']).order_by(playlist.id).first()
	maxorder = Session.query(func.max(playlist_item.order)).filter(playlist_item.listid == playlist1.id).first()[0]
	if not maxorder:
		maxorder = 0
	Session.add(playlist_item(listid=playlist1.id, musicid=data['id'], order=maxorder+1))
	Session.commit()
	return "Success"
开发者ID:Pusnow,项目名称:OSWebMusicPlayer,代码行数:11,代码来源:View.py

示例3: albuminfo

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
def albuminfo ():
	data = request.get_json()

	album1 = Session.query(album).filter(album.id==data['id']).one()
	json_data = dict(id = data['id'] ,name=album1.name,singer=album1.singer, url=album1.name+'.jpg', musicnum = album1.music_count)
	musiclist1=[]
	for m in Session.query(music).filter(music.albumid==data['id']).order_by(music.num).all():
		musiclist1.append(m.diction())
	json_data ["musiclist"] =musiclist1
	return jsonify(json_data)
开发者ID:Pusnow,项目名称:OSWebMusicPlayer,代码行数:12,代码来源:View.py

示例4: getlist

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
def getlist():
	data = request.get_json()
	item = Session.query(playlist_item).filter(playlist_item.listid==data['id']).order_by(playlist_item.order).all()
	json_data = dict(id = data['id'])
	musiclist = []
	for m in item:
		mm = m.music.diction()
		mm["order"] = m.order
		musiclist.append(mm)
		
	json_data ["name"] = Session.query(playlist.name).filter(playlist.id==data['id']).first()
	json_data ["musiclist"] =musiclist
	return jsonify(json_data)
开发者ID:Pusnow,项目名称:OSWebMusicPlayer,代码行数:15,代码来源:View.py

示例5: delete_user

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
 def delete_user(self, user_id):
     s = Session()
     del_user = s.query(User).filter(User.id == user_id).one()
     s.delete(del_user)
     s.commit()
     self.signal_delete_user.emit(user_id)
     s.close()
开发者ID:Inktvisje,项目名称:alchtest,代码行数:9,代码来源:UserModel.py

示例6: usersocial

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
def usersocial(id):
	user1 = Session.query(user).filter(user.id == id).first()
	if request.method == 'POST':
		post = True
	else :
		post = False
	group1 = [
		dict(name=u"애픽하이"),

	]

	

	feedlist = Session.query(feed).filter(feed.userid==id).order_by(feed.id.desc()).all()
	user1 = dict(name=user1.realname, grouplist = group1, profileurl = session['profile'])
	return render_template('social.html', user = user1, feedlist = feedlist, post=post)
开发者ID:Pusnow,项目名称:OSWebMusicPlayer,代码行数:18,代码来源:View.py

示例7: register_view

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
    def register_view(self):
        form = RegistrationForm(request.form)
        if request.method == 'POST' and form.validate():
            user = Users()

            user.username = form.username.data
            user.email = form.email.data
            user.roles = ','.join(form.role.data)
            # we hash the users password to avoid saving it as plaintext in the db,
            # remove to use plain text:
            user.password = generate_password_hash(form.password.data)

            Session.add(user)
            Session.commit()

            login.login_user(user)
            flash('Thanks for registering')
            return redirect(url_for('.index'))
        link = '<p>Already have an account? <a href="' + url_for('.login_view') + '">Click here to log in.</a></p>'
        form_roles = []
        roles = Session.query(Role).all()
        for role in roles:
            form_roles.append((role.key, role.name))
        form.role.choices = form_roles
        self._template_args['form'] = form
        self._template_args['link'] = link
        return super(MyAdminIndexView, self).index()
开发者ID:maximusmai,项目名称:flask-test,代码行数:29,代码来源:test_admin_role.py

示例8: load

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
def load(file_path):
    if not file_path.endswith('xml'):
        print('Not an XML file:' + file_path)
        pass
    if file_path.endswith('DIY.xml'):
        author, title, sections = parse_xml(open(file_path))
    else:
        author, title, sections = parse_perseus(open(file_path),'div1')
    session = Session()
    a = get_or_create(session, Author, name=author)
    session.commit()
    t = get_or_create(session, Text, name=title, author=a.id)
    session.commit()
    global_ngrams = session.query(GlobalNgrams).first()
    section_count = 1
    log('Loading: ' + t.name)
    
    if not USE_ORIGINAL_DIVISIONS:
        sections = [' '.join(sections)]
        if DIVISION_LENGTH:
            sections = create_chunks(sections[0],DIVISION_LENGTH)

    for sec in sections:
        temp_section = get_or_create(session, Section, source_text=t.id, number=section_count)
        log('Loading section ' + str(section_count))
        session.commit()
        temp_section_content = get_or_create(session, SectionContent, section = temp_section.id, content = sec)
        log('Creating ngrams of ' + str(section_count))
        temp_section_ngrams = get_or_create(session, SectionNgrams, section = temp_section.id, ngrams = generate_ngrams(temp_section_content.content))
        log('Updating global ngram counts.')
        update_global_counts(session, global_ngrams,temp_section_ngrams.ngrams)
        section_count = section_count + 1
    session.commit()
    update_vector_space(session, global_ngrams)
开发者ID:fmcc,项目名称:StylometricAnalyser,代码行数:36,代码来源:load.py

示例9: get_announcements

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
def get_announcements(course, url):
    '''Gets all new announcements

    Returns a list of all new announcements.
    '''
    session = Session()
    try:
        r = s.get('https://edux.pjwstk.edu.pl/Announcements.aspx', stream=True)
        r.raise_for_status()
        new_announcements = extract_announcements(r.content)
        # All pairs of (timestamp, message) are saved to db
        # if they arent there already
        for (timestamp, message) in new_announcements:
            announcement = session.query(Announcement). \
                filter_by(course=course,
                          created_at=timestamp,
                          message=message). \
                first()
            if announcement is None:
                # This is what we care about
                announcement = Announcement(
                    course=course,
                    created_at=timestamp,
                    message=message)
                session.add(announcement)
                print u'New announcement at {0}'.format(timestamp)
                yield (timestamp, message)
        session.commit()
    except Exception:
        session.rollback()
        raise
    finally:
        session.close()
开发者ID:mpapierski,项目名称:edux,代码行数:35,代码来源:edux.py

示例10: on_return

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
    def on_return(self, task):
        """Called by main thread on the return of data from the workers.
        Post-processing"""
        logger.info('Retrieved task %s', task.tag)
        traj = Session.query(models.Trajectory).get(int(task.tag))
        
        try:
            # save lh5 version of the trajectory
            conf = load_file(self.project.pdb_topology_file)
            coordinates = msmbuilder.Trajectory.load_trajectory_file(str(traj.dry_xtc_fn), Conf=conf)
            save_file(traj.lh5_fn, coordinates)
        
        except Exception as e:
            logger.error('When postprocessing %s, convert to lh5 failed!', traj)
            logger.exception(e)
            raise
        
        # convert last_wet_snapshot to lh5
        pdb_to_lh5(traj, 'last_wet_snapshot_fn')
        pdb_to_lh5(traj, 'init_pdb_fn')


        traj.host = task.host
        traj.returned_time = datetime.now()
        traj.length = len(coordinates)
        logger.info('Finished converting new traj to lh5 sucessfully')
开发者ID:pandegroup,项目名称:msmaccelerator,代码行数:28,代码来源:QMaster.py

示例11: for_name

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
 def for_name(cls, name, create=False):
     try:
         return Session.query(cls).filter_by(name=name).one()
     except NoResultFound:
         if create:
             return returnit(Session.add, cls(name))
         else:
             raise EventNotFound(name)
开发者ID:sionide21,项目名称:HackerTracker,代码行数:10,代码来源:event.py

示例12: main

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
def main():
    reading_id = int(sys.argv[1])
    session = Session()
    reading = session.query(Reading).filter(Reading.id == reading_id).one()
    text = reading.text
    PrependStream(sys.stdout, '    ').write('"' + text.strip() + '"')
    sys.stdout.write('\n')
    session.rollback()
开发者ID:giomasce,项目名称:liturgy,代码行数:10,代码来源:print_reading.py

示例13: login_check

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
 def login_check(user_name):
     session = Session()
     user = session.query(User).filter(or_(
         User.nickname == user_name)).first()
     print session
     session.commit()
     if not user:
         return None
     return user
开发者ID:sa615153,项目名称:learn_prototype1,代码行数:11,代码来源:models.py

示例14: attributes

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
 def attributes(self):
     return [
         x
         for x, in Session.query(Attribute.key)
         .join(Attribute.entry)
         .filter_by(event_id=self.id)
         .order_by(Attribute.key)
         .distinct()
     ]
开发者ID:sionide21,项目名称:HackerTracker,代码行数:11,代码来源:event.py

示例15: index

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import query [as 别名]
    def index(self, username=None):
        tableText = '<div class="container">\n\
			<table class="table">\n\
				<thead>\n\
					<tr>\n\
						<th>Name</th>\n\
						<th>Username</th>\n\
						<th>Password</th>\n\
					</tr>\n\
				</thead>\n\
				<tbody>\n'
        session = Session()
        if username == None:
            for user in session.query(User).order_by(User.id):
                tableText += (
                    "<tr>\n<td>"
                    + user.fullname
                    + "</td>\n"
                    + "<td>"
                    + user.username
                    + "</td>\n"
                    + "<td>"
                    + user.password
                    + "</td>\n</tr>\n"
                )
        else:
            for user in session.query(User).filter(User.username.like("%" + username + "%")).order_by(User.id):
                tableText += (
                    "<tr>\n<td>"
                    + user.fullname
                    + "</td>\n"
                    + "<td>"
                    + user.username
                    + "</td>\n"
                    + "<td>"
                    + user.password
                    + "</td>\n</tr>\n"
                )

        tableText += "</tbody>\n</table>\n"
        session.close()
        return top + tableText + bottom
开发者ID:FissionCat,项目名称:cherrypy-practice,代码行数:44,代码来源:hello.py


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