def post(self): root = ET.fromstring(self.request.body) password = root.find('password').text session = getSession() passw = session.query(Password).filter(Password.id == 1).all() if passw: self.set_secure_cookie('getpassword',password) # 放入会话(Cookie)
def post(self, mpid_str): mpid = int(mpid_str) root = ET.fromstring(self.request.body) title = root.findtext('title').encode('utf-8') from datetime import datetime dt = datetime.now() summary = root.findtext('summary').encode('utf-8') content = root.findtext('content').encode('utf-8') priority = root.findtext('priority') taglist = [] map(lambda t: taglist.append(t.attrib['id']), root.find('tags').iter('tag')) thumb = root.findtext('thumb').encode('utf-8') images = ET.tostring(root.find('images'), encoding='utf-8') enabled = root.findtext('enabled') session = getSession() mpsite = session.query(MpSite).filter(MpSite.id == mpid).one() tags = session.query(Tag).filter(Tag.id.in_(taglist)).all() a = Article(title, dt, summary, content, priority, thumb, images, enabled) map(lambda t: a.tags.append(t), tags) a.mpsite = mpsite session.add(a) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<article id="%d"/>' % a.id)
def get_module_template(handler, id): session = getSession() md = session.query(ModuleDeployment).filter(ModuleDeployment.id == id).first() if md: clsname = md.cls ps = clsname.split('.') cls = __import__('.'.join(ps[:-1]), globals(), locals(), fromlist=(ps[-1], )) return cls.__dict__[ps[-1]].__module_template__
def post(self): root = ET.fromstring(self.request.body) name = root.find('loginname').text password = root.find('password').text session = getSession() user = session.query(FlowerUser).filter(FlowerUser.user_name == name, FlowerUser.user_password == password).first() if user: self.set_secure_cookie('getuser', user.loginname) # 放入会话(Cookie)
def update_user(self, username, fullname, mobile, email): session = getSession() a = session.query(Account).filter(Account.username == username).first() a.fullname = fullname a.mobile = mobile a.email = email session.merge(a) session.commit() return a.id
def delete(self, id): uid = int(id) self.set_header('Content-Type', 'text/xml; charset=utf-8') session = getSession() cuser = self.get_cookie('getuser') user = session.query(FlowerUser).filter(FlowerUser.user_id == uid).first() if user: session.delete(user) session.commit() self.write('<user id="%s"/>'% int(user.user_id))
def post(self): root = ET.fromstring(self.request.body) name = root.find('name').text password = root.find('password').text session = getSession() user = session.query(FlowerUser).filter(FlowerUser.user_name == name, FlowerUser.user_password == password).first() if user: list = (user.user_name, user.user_password, user.user_email, user.user_mobile) #生成元组放进会话 self.set_secure_cookie('getuser',list) # 放入会话(Cookie)
def delete(self, tag_id): session = getSession() t = session.query(Tag).filter(Tag.id == int(tag_id)).one() if not self.get_mpdao().own(self.get_secure_cookie('username'), t.mpid): raise tornado.web.HTTPError(401) name = t.name session.delete(t) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<tag id="%s" name="%s"/>' % (tag_id, name))
def post(self): root = ET.fromstring(self.request.body) name = root.find('name').text session = getSession() utype = FlowerUserType(name) if utype: session.add(utype) session.commit() self.set_header('Content-Type', 'text/xml: charset=utf-8') self.write('<usertypes id="%s"/>' % int(utype.utype_id))
def emit(self, record): try: msg = self.format(record) import model.logging from orm import getSession session = getSession() l = model.logging.Logging(msg) session.add(l) session.commit() except: self.handleError(record)
def put(self, tag_id): session = getSession() root = ET.fromstring(self.request.body) name = root.attrib['name'] t = session.query(Tag).filter(Tag.id == int(tag_id)).one() if not self.get_mpdao().own(self.get_secure_cookie('username'), t.mpid): raise tornado.web.HTTPError(401) t.name = name.encode('utf-8') session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<tag id="%s" name="%s"/>' % (tag_id, name))
def post(self): root = ET.fromstring(self.request.body) articleid = int(root.get('articleid')) email = root.find('email').text content = root.find('content').text session = getSession() cc = Comment(articleid, content, email) session.add(cc) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<comment id="%s"/>'% int(cc.id))
def put(self): pas = self.get_cookie('getpassword') root = ET.fromstring(self.request.body) self.set_header('Content-Type', 'text/xml; charset=utf-8') session = getSession() pw = session.query(Password).filter(Password.id == 1).first() if pw and pas: pw.password = root.find('password').text session.merge(pw) session.commit() self.write('<password id="%s"/>' %int(pw.id))
def post(self): root = ET.fromstring(self.request.body) session = getSession() tname = str(root.find('tname').text) # 类别名称 ftype = FlowerTypeHandler(tname) if ftype: session.add(ftype) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<flowertype id="%d"/>' % ftype.ftype_id) else: self.send_error(401)
def get(self, mg): session = getSession() root = ET.Element('images') img = session.query(Images).filter(Images.filepath == mg).all() if img: for result in img: imgel = ET.SubElement(root, 'image') imgel.attrib['id'] = str(result.id) ET.SubElement(imgel, 'filename').text = result.filename ET.SubElement(imgel, 'filepath').text = result.filepath self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write(ET.tostring(root, encoding='UTF-8'))
def get(self): session = getSession() root = ET.Element('flowertypes') ftype = session.query(FlowerTypeHandler).all() if ftype: for val in ftype: # user = session.query(FlowerTypeHandler).filter(FlowerTypeHandler.ftype_id == int(val.user_id)).first() # 根据ID找到发布人信息 ft = ET.SubElement(root, 'flowertype') ft.attrib['id'] = str(val.ftype_id) # 设置根节点属性 ET.SubElement(ft, 'name').text = val.ftype_name # 类型 self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write(ET.tostring(root, encoding='UTF-8'))
def get(self): root = ET.Element('usertypes') session = getSession() utype = session.query(FlowerUserType).all() if utype: for val in utype: ut = ET.SubElement(root, 'usertype') ut.attrib['tid'] = str(val.utype_id) # 设置根节点属性 ET.SubElement(ut, 'name').text = val.utype_name self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write(ET.tostring(root, encoding='UTF-8'))
def post(self): root = ET.fromstring(self.request.body) name = str(root.find('name')) session = getSession() utype = FlowerUserType(name) if utype: session.add(utype) session.commit self.set_header('Content-Type', 'text/xml: charset=utf-8') self.write('<usertypes id="%d"/>' % utype.id) else: self.send_error(401)
def delete(self, id): self.set_header('Content-Type', 'text/xml; charset=utf-8') pas = self.get_cookie('getpassword') cid = int(id) session = getSession() cc = session.query(Comment).filter(Comment.id == cid).first() if cc and pas: session.delete(cc) session.commit() self.write('<article id="%s"/>'% int(cid)) else: self.send_error(401)
def post(self, mpid_str): mpid = int(mpid_str) if not self.get_mpdao().own(self.get_secure_cookie('username'), mpid): raise tornado.web.HTTPError(401) root = ET.fromstring(self.request.body) name = root.attrib['name'] session = getSession() t = Tag(name.encode('utf-8'), mpid) session.add(t) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<tag id="%d" name="%s"/>' % (t.id, name))
def post(self): root = ET.fromstring(self.request.body) tagname = root.find('tagname').text fid = int(root.get('fid')) session = getSession() tags = FlowerTagsHandler(tagname, fid) if tags: session.add(tags) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<flowertags id="%d"/>' % tags.tags_id) else: self.send_error(401)
def delete(self, id): self.set_header('Content-Type', 'text/xml; charset=utf-8') pas = self.get_cookie('getpassword') aid = int(id) session = getSession() aa = session.query(Article).filter(Article.id == aid).first() if aa and pas: session.delete(aa) session.commit() self.write('<article id="%s"/>'% int(aid)) else: self.send_error(401)
def get(self): root = ET.Element('comments') # 设置根节点 session = getSession() cc = session.query(Comment).order_by(Comment.id).offset(0).limit(10) #offset(0).limit(10).order_by(desc=True) if cc: for val in cc: com = ET.SubElement(root, 'comment') com.attrib['id'] = str(val.id) com.attrib['aid'] = str(val.article_id) ET.SubElement(com, 'email').text = self.acess_email(val.email) ET.SubElement(com, 'content').text = val.content self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write(ET.tostring(root, encoding='UTF-8'))
def delete(self, id): uid = int(id) self.set_header('Content-Type', 'text/xml; charset=utf-8') session = getSession() cuser = self.get_cookie('getuser') utype = session.query(FlowerUserType).filter(FlowerUser.user_name == str(cuser)).first() # 判断该用户是否为管理员和当前用户 user = session.query(FlowerUser).filter(FlowerUser.user_id == uid).first() if user and utype.utype_name is r'系统管理员' and utype: session.delete(user) session.commit() self.write('<user id="%s"/>'% int(user.user_id)) else: self.send_error(401)
def post(self, cid_str): # 从引用路径获得id cid = int(cid_str) root = ET.fromstring(self.request.body) session = getSession() cls = root.findtext('class') name = root.findtext('name') version = root.findtext('version') md = ModuleDeployment(cls, name, version, uuid4().hex, cid) session.add(md) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<deployment id="%d"/>' % md.id)
def get(self, id): root = ET.Element('users') session = getSession() user = session.query(FlowerUser).filter(FlowerUser.user_id == int(id)) if user: for val in user: u = ET.SubElement('user') u.attrib['id'] = str(val.user_id) u.attrib['tid'] = str(val.user_typeid) ET.SubElement(u, 'name').text = val.user_name ET.SubElement(u, 'email').text = str(val.user_email) ET.SubElement(u, 'mobile').text = str(val.user_mobile) self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write(ET.tostring(root, encoding='UTF-8'))
def put(self, tid): id = int(tid) session = getSession() root = ET.fromstring(self.request.body) ftype = session.query(FlowerTypeHandler).filter(FlowerTypeHandler.ftype_id == id).first() if ftype: ftype.ftype_name = root.find('tname').text # 类型 ftype.flower_id = root.get('fid') session.merge(ftype) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<flowertype id="%d"/>' % ftype.ftype_id) else: self.send_error(401)
def post(self): email = self.get_argument('email', '') password = self.get_argument('password', '') mobile = self.get_argument('mobile', '') try: session = getSession() pp = Passport(email, mobile, password) session.add(pp) session.commit() self.set_secure_cookie('passport', json.dumps(dict(id=pp.id, email=pp.email, mobile=pp.mobile))) self.redirect(r'/') except: self.set_status(500) self.render('error.html', status=500, message='注册失败,请重新输入')
def post(self): root = ET.fromstring(self.request.body) session = getSession() pp = self.get_current_user() c = session.query(Circle).filter(Circle.id == int(root.attrib['id'])).first() if c: p = session.query(Passport).filter(Passport.id == pp['id']).first() c.members.append(p) session.merge(c) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<circle id="%d"/>' % c.id) else: self.send_error(500)
def get(self, cid_str): root = ET.Element('deployments') cid = int(cid_str) root.attrib['circle-id'] = str(cid) session = getSession() mds = session.query(ModuleDeployment).filter(ModuleDeployment.circle_id == cid).all() if mds: for md in mds: d_elm = ET.SubElement(root, 'deployment', {'id': str(md.id), 'serial': md.serial}) ET.SubElement(d_elm, 'name').text = md.name ET.SubElement(d_elm, 'class').text = md.cls ET.SubElement(d_elm, 'version').text = md.version self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write(ET.tostring(root, encoding='UTF-8'))
def commit_db(): nonebot.logger.debug("Exiting. Commiting database changes...") orm.getSession().commit()
async def vote(s: CommandSession, user, group, user_in_group, state): parser = ArgumentParser(session=s, usage=USAGE) parser.add_argument( 'command', choices=['list', 'new', 'yea', 'nay', 'commit', 'count', 'announce']) parser.add_argument('ITEM') parser.add_argument('extra', nargs='?') args = parser.parse_args(s.argv) name = args.ITEM.strip() db: orm.Session = orm.getSession() vote_item = db.query(VoteItem).filter(VoteItem.GroupId == group.GroupId, VoteItem.Name == name).one_or_none() try: if args.command == 'list': msg = Message("List of available vote items:\n") items = None if args.extra == 'all': # Extract all items items = db.query(VoteItem).filter( VoteItem.GroupId == group.GroupId).all() else: # Extract active items items = db.query(VoteItem).filter( VoteItem.GroupId == group.GroupId, VoteItem.Committed == False).all() for item in items: msg.append( MessageSegment.text( f"'{item.Name}' - {item.Description}\n")) await s.send(msg) elif args.command == 'new': if not vote_item: if not args.extra: desc = f"Vote on {name}" else: desc = args.extra item = VoteItem(GroupId=group.GroupId, ProposerId=user.UserId, Name=name, Committed=False, Description=desc) db.add(item) db.commit() await s.send( f"Vote item '{item.Description}' ({item.Name}) created.", at_sender=True) else: await s.send(f"Vote item '{vote_item.Name}' already exisist.", at_sender=True) elif args.command == 'yea': if not vote_item: raise _VoteItemNotFound() if vote_item.Committed: raise _VoteClosed() vote = db.query(Vote).filter( Vote.Item == vote_item.Id, Vote.Voter == user.UserId).one_or_none() if not vote: vote = Vote(Item=vote_item.Id, Voter=user.UserId, Ballot=_BALLOT_YEA) db.add(vote) else: vote.Ballot = _BALLOT_YEA db.commit() await s.send( f"You voted YES to '{vote_item.Description}' ({vote_item.Name}).", at_sender=True) elif args.command == 'nay': if not vote_item: raise _VoteItemNotFound if vote_item.Committed: raise _VoteClosed vote = db.query(Vote).filter( Vote.Item == vote_item.Id, Vote.Voter == user.UserId).one_or_none() if not vote: vote = Vote(Item=vote_item.Id, Voter=user.UserId, Ballot=_BALLOT_NAY) db.add(vote) else: vote.Ballot = _BALLOT_NAY db.commit() await s.send( f"You voted NO to '{vote_item.Description}' ({vote_item.Name}).", at_sender=True) elif args.command == 'commit': if not vote_item: raise _VoteItemNotFound() if vote_item.ProposerId != user.UserId: raise _NotVoteOwner() vote_item.Committed = True db.commit() await s.send( f"You concluded vote item '{vote_item.Description}' ({vote_item.Name}).", at_sender=True) elif args.command == 'count': if not vote_item: raise _VoteItemNotFound total_count = db.query(Vote).filter( Vote.Item == vote_item.Id).count() positives = db.query(Vote).filter( Vote.Item == vote_item.Id, Vote.Ballot == _BALLOT_YEA).count() await s.send( f"Vote item '{vote_item.Description}' ({vote_item.Name}) got {positives} YES among {total_count} votes." ) elif args.command == 'announce': if not vote_item: raise _VoteItemNotFound total_count = db.query(Vote).filter( Vote.Item == vote_item.Id).count() # proposer = db.query(orm.User).filter(orm.User.UserId==vote_item.ProposerId).one() positives = db.query(Vote).filter( Vote.Item == vote_item.Id, Vote.Ballot == _BALLOT_YEA).all() # positives = db.query(Vote, orm.User) \ # .join(Vote.Voter == orm.User.UserId) \ # .filter(Item=vote_item.Id, Ballot=_BALLOT_YEA) \ # .all() msg = nonebot.Message( f"Vote item '{vote_item.Description}' ({vote_item.Name}) initiated by " ) msg.append(MessageSegment.at(vote_item.ProposerId)) msg.append( MessageSegment.text( f" got {len(positives)} YES among {total_count} votes. ")) msg.append( MessageSegment.text( f"The following users in favor of the item:")) segs = [ nonebot.MessageSegment.at(vote.Voter) for vote in positives ] for seg in segs: msg.append(seg) await s.send(msg) else: raise Exception except _VoteItemNotFound: await s.send(f"Vote item '{name}' does not exist.", at_sender=True) except _NotVoteOwner: await s.send(f"You does not own vote item '{name}'.", at_sender=True) except _VoteClosed: await s.send(f"Voting for '{name}' is already closed.", at_sender=True)
def get_log_list(): import model.logging from orm import getSession return getSession().query(model.logging.Logging).order_by( model.logging.Logging.id.desc()).limit(100)
def valid(self, username, password): session = getSession() n = session.query(Account).filter( Account.username == username, Account.password == password).count() return n == 1
import orm s = orm.getSession() users = s.query(orm.User).all() groups = s.query(orm.Group).all() users_in_group = s.query(orm.UserInGroup).all() for row in groups: print(f"Group (id = {row.GroupId})") for row in users: print(f"User (id = {row.UserId}, Name = {row.Name})") for row in users_in_group: print( f"Affil (id = {row.Id}, GID = {row.GroupId}, UID = {row.UserId}, Name = {row.Name})" )
def get_session(self): if not self.session: self.session = getSession() return self.session
def initialize(self): self.session = getSession()
def get(self): session = getSession() aa = session.query(Article).count() # 拿到博客的总记录数 self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<count>%s</count>' %int(aa))
def get(self, aid): session = getSession() aa = session.query(Comment).filter(Comment.article_id == int(aid)).count() # 拿到博客的总记录数 self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<count>%s</count>' %int(aa))