def announcements_page(): if request.method == 'GET': announcements = app.store.get_announcements() now = datetime.datetime.now() return render_template('announcements.html', announcements=announcements, current_time=now.ctime()) elif 'announcements_to_delete' in request.form or 'search' in request.form: if request.form['submit'] == 'Delete': keys = request.form.getlist('announcements_to_delete') for key in keys: app.store.delete_announcement(int(key)) return redirect(url_for('announcements_page')) elif request.form['submit'] == 'search': keyword = request.form['search'] announcements = app.store.search_announcement(keyword) now = datetime.datetime.now() return render_template('announcements.html', announcements=announcements, current_time=now.ctime()) else: title = request.form['title'] text = request.form['text'] announcement = Announcement(title, text) app.store.add_announcement(announcement) return redirect( url_for('announcement_page', key=app.store.announcement_last_key))
def __init__(self): self.user = User() self.course = Course() self.category = Category() self.quiz = Quiz() self.announcement = Announcement() self.discussion = Discussion()
def get_announcement(self, key): with dbapi2.connect(self.app.config['dsn']) as connection: cursor = connection.cursor() query = "SELECT TITLE, TEXT FROM ANNOUNCEMENT WHERE (ID = %s)" cursor.execute(query, (key,)) title, text = cursor.fetchone() return Announcement(title, text)
def announcement_from_json(item): SGX_KEY_KEY = "key" ISSUER_NAME_KEY = "IssuerName" SECURITY_NAME_KEY = "SecurityName" GROUP_CODE_KEY = "GroupCode" CATEGORY_CODE_KEY = "CategoryCode" CATEGORY_NAME_KEY = "CategoryName" TITLE_KEY = "AnnTitle" BROADCAST_TIME_KEY = "BroadcastDateTime" SIBLINGS_KEY = "Siblings" try: broadcast_time = _to_broadcast_time(item[BROADCAST_TIME_KEY]) return Announcement(sgx_key=item[SGX_KEY_KEY], broadcast_time=broadcast_time, issuer_name=item[ISSUER_NAME_KEY], security_name=item[SECURITY_NAME_KEY], group_code=item[GROUP_CODE_KEY], category_code=item[CATEGORY_CODE_KEY], category_name=item[CATEGORY_NAME_KEY], title=item[TITLE_KEY], siblings=item[SIBLINGS_KEY]) except: logging.warning("Cannot create announcement from %s" % item) return None
def get_announcements(self): with dbapi2.connect(self.app.config['dsn']) as connection: cursor = connection.cursor() query = "SELECT * FROM ANNOUNCEMENT ORDER BY ID" cursor.execute(query) announcements = [(key, Announcement(title, text)) for key, title, text in cursor] return announcements
def search_announcement(self, key): with dbapi2.connect(self.app.config['dsn']) as connection: cursor = connection.cursor() query = "SELECT * FROM ANNOUNCEMENT WHERE (TITLE ILIKE %s OR TEXT ILIKE %s)" key = '%'+key+'%' cursor.execute(query, (key, key)) announcements = [(key, Announcement(title,text)) for key, title, text in cursor] return announcements
def setup(base, conf_fn): print '\n**** service initialization ****\n' global room, courseobj, categoryobj, userobj, announcementobj, discussionobj, quizobj, messageobj room = Room(base, conf_fn) courseobj = Course() categoryobj = Category() userobj = Users() announcementobj = Announcement() discussionobj = Discussion() quizobj = Quiz() messageobj = Message()
class Admin(object): db = None ''' classdocs ''' #constructor def __init__(self): self.user = User() self.course = Course() self.category = Category() self.quiz = Quiz() self.announcement = Announcement() self.discussion = Discussion() def resetDB(self): self.user.reset() self.course.reset() self.category.reset() self.quiz.reset() self.announcement.reset() self.discussion.reset()
def __init__(self, parent): self.announcement = Announcement( sorted(list(users.keys()))[0], sorted(list(mail.keys()))[0]) self.initializeGui(parent)
class ControlAnnouncement: def __init__(self, parent): self.announcement = Announcement( sorted(list(users.keys()))[0], sorted(list(mail.keys()))[0]) self.initializeGui(parent) def initializeGui(self, parent): self.parent = parent self.frame = Frame(self.parent) self.frame.grid(column=0, row=0) Label(self.frame, text="User").grid(row=0, sticky=W) Label(self.frame, text="Type").grid(row=1, sticky=W) userList = sorted(list(users.keys())) self.comboBoxUser = Combobox(self.frame, state="readonly", width=20, values=userList) self.comboBoxUser.set(userList[0]) self.comboBoxUser.grid(row=0, column=1, sticky=W) self.comboBoxUser.bind('<<ComboboxSelected>>', self.updateUser) announcementTypes = sorted(list(mail.keys())) self.comboBoxType = Combobox(self.frame, state="readonly", width=35, values=announcementTypes) self.comboBoxType.set(announcementTypes[0]) self.comboBoxType.grid(row=1, column=1, sticky=W) self.comboBoxType.bind('<<ComboboxSelected>>', self.updateType) self.scolledText = ScrolledText(self.frame, wrap=WORD, width=80, height=15) self.scolledText.grid(row=2, column=1, columnspan=2) self.scolledText.config(state=NORMAL) self.scolledText.insert(INSERT, self.announcement.message.as_string()) self.scolledText.config(state=DISABLED) self.buttonSendTestMail = Button(self.frame, text='Send Test Mail', command=self.sendTestMail) self.buttonSendTestMail.grid(row=4, column=1) self.buttonSendMail = Button(self.frame, text='Send Mail', command=self.sendMail) self.buttonSendMail.grid(row=4, column=2) self.checkButtonAttachmentAvailable = Checkbutton( self.frame, text="Attachments available") self.checkButtonAttachmentAvailable.grid(row=3, sticky=W) self.checkAttachments() def checkAttachments(self): key = self.announcement.getAttachmentKey() print("Info: Attachment key is " + str(key)) self.checkButtonAttachmentAvailable.config(state=NORMAL) if key is None: self.checkButtonAttachmentAvailable.deselect() self.buttonSendTestMail.config(state=NORMAL) self.buttonSendMail.config(state=NORMAL) else: if not self.announcement.attachmentsMissing(): self.checkButtonAttachmentAvailable.select() self.buttonSendTestMail.config(state=NORMAL) self.buttonSendMail.config(state=NORMAL) else: self.checkButtonAttachmentAvailable.deselect() # self.buttonSendTestMail.config(state=DISABLED) self.buttonSendMail.config(state=DISABLED) self.checkButtonAttachmentAvailable.config(state=DISABLED) def updateUser(self, *args): print(__class__.__name__ + "::" + sys._getframe().f_code.co_name) self.announcement.setUser(self.comboBoxUser.get()) self.scolledText.config(state=NORMAL) self.scolledText.delete(1.0, END) self.scolledText.insert(INSERT, self.announcement.message.as_string()) self.scolledText.config(state=DISABLED) self.checkAttachments() def updateType(self, *args): print(__class__.__name__ + "::" + sys._getframe().f_code.co_name) self.announcement.setMailType(self.comboBoxType.get()) self.scolledText.config(state=NORMAL) self.scolledText.delete(1.0, END) self.scolledText.insert(INSERT, self.announcement.message.as_string()) self.scolledText.config(state=DISABLED) self.checkAttachments() def sendTestMail(self): print(__class__.__name__ + "::" + sys._getframe().f_code.co_name) self.announcement.sendTestMail() def sendMail(self): print(__class__.__name__ + "::" + sys._getframe().f_code.co_name) pwDialog = PasswordDialog( self.frame, title=self.announcement.getFullAddressList()[0]) # print(pwDialog.result) if pwDialog.result: self.announcement.attach() self.announcement.sendMail(pwDialog.result) self.announcement.renderMessage()
def run(self) -> bool: while True: # Create 2 empty lists for photo and video filenames photos = [] videos = [] # Create empty lists for annoucement data announcements = [] announcement_data = [] # Get current datetime current_date = datetime.datetime.today().date() if self._use_mongo_db: try: with pymongo.MongoClient( self._mongo_db_conn_string) as mongo_client: db = mongo_client[self._mongo_db_name] coll = db[self._mongo_db_collection] announcement_data = list(coll.find()) mongo_success = True except Exception: mongo_success = False if not self._use_mongo_db or not mongo_success: with open(self._announcement_file, 'r') as f: announcement_data = json.load(f) # Iterate through all root elements for item in announcement_data: # Get start date and end date for announcement ann_start_date = datetime.datetime.strptime( item['start_date'], self._date_fmt).date() ann_end_date = datetime.datetime.strptime( item['end_date'], self._date_fmt).date() # Only show announcements that are within the # specified date range if (ann_start_date <= current_date and ann_end_date >= current_date): ann_temp = Announcement(ann_start_date, ann_end_date) # Iterate through all "line" elements for line in item['lines']: # "hspace" elements represent blank vertical spaces if 'hspace' in line: ann_temp.lines.append( AnnouncementLine("", line['hspace'], (0, 0, 0), False)) else: # Append each line to the list that represents # the lines of the announcement ann_temp.lines.append( AnnouncementLine(line['text'], line['size'], pygame.Color(line['color']), line['center'])) # Append each complete announcement to the master list # of announcements announcements.append(ann_temp) # Find all photos in designated folder based on the # list of extensions. Allow for both uppercase and lowercase # extensions, but not mixed case for wildcard in self._photo_files: photos.extend( glob.glob(os.path.join(self._photo_path, wildcard.upper()))) photos.extend( glob.glob(os.path.join(self._photo_path, wildcard.lower()))) # Find all videos in designated folder based on the # list of extensions. Allow for both uppercase and lowercase # extensions, but not mixed case for wildcard in self._video_files: videos.extend( glob.glob(os.path.join(self._video_path, wildcard.upper()))) videos.extend( glob.glob(os.path.join(self._video_path, wildcard.lower()))) # Display photos in alphabetical order by filename photos.sort() # Loop through all photos and insert videos at random. Note that the # contents of the folder will be reparsed each time all of the # photos are displayed, so this provides an opportunity to # add/change the contents without restarting the script. for photo in photos: # Check to see if user has requested to quit if self._check_for_quit(): return False self._show_image(photo) next_time = time.monotonic() + self._photo_time while time.monotonic() < next_time: # Check to see if user has requested to quit if self._check_for_quit(): return False # Sleep to avoid running CPU at 100% time.sleep(0.5) # Display announcements based on the specified probability. # Check to be sure we have any announcements to display before # we try to display one. if (random.random() <= self._announcement_probability and announcements): self._show_announcement(random.choice(announcements), self._announcement_font, self._announcement_line_spacing) next_time = time.monotonic() + self._announcement_time while time.monotonic() < next_time: # Check to see if user has requested to quit if self._check_for_quit(): return False # Sleep to avoid running CPU at 100% time.sleep(0.5) # Check to see if user has requested to quit if self._check_for_quit(): return False # Play videos based on the specified probability. # Check to be sure we have any videos to play before we try # to play one. if (random.random() <= self._video_probability and videos): if not self._show_video(random.choice(videos)): # _show_video() returns False if user requested to # quit during video playback return False return True
def announcements(self): return [Announcement.from_json(self, obj) for obj in self.__get_json_attr('announcements', agencies=self.id, contents=1)]
def announcements(self): return [ Announcement.from_json(self, obj) for obj in self.__get_json_attr( 'announcements', agencies=self.id, contents=1) ]