-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotices.py
43 lines (33 loc) · 1.03 KB
/
notices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
from dbentities import *
class Notices:
def __init__(self,db):
self.db = db
def HasNotice(self, rev):
session = self.db.sessionmaker()
db_rev = session.query( LobbyRevision ).filter( LobbyRevision.revision == rev ).first()
if not db_rev:
return False
ret = session.query( Notice ).filter( Notice.lobbyrev_id == db_rev.id ).count()
session.close()
return ret
def GetNotices(self,rev):
session = self.db.sessionmaker()
db_rev = session.query( LobbyRevision ).filter( LobbyRevision.revision == rev ).first()
if not db_rev:
return []
ret = session.query( Notice ).filter( Notice.lobbyrev_id == db_rev.id ).all()
session.close()
return ret
def AddNotice(self, rev, text):
session = self.db.sessionmaker()
db_rev = session.query( LobbyRevision ).filter( LobbyRevision.revision == rev ).first()
if not db_rev:
return False
notice = Notice()
notice.lobbyrev_id = db_rev.id
notice.text = text
session.add( notice )
session.commit()
session.close()
return True