def format_announcement_text(self, ticket, aliases, language, show_prefix): ''' Helper to format text-to-speech text. Parameters ---------- ticket: Serial record aliases: Aliases record language: str language of text-to-speech to produce show_prefix: bool include the office prefix in the announcement Returns ------- String of formated text-to-speech text ready to use. ''' with self.app.app_context(): single_row_queuing = Settings.get().single_row office_text = '' tts_text = '' if not single_row_queuing: office = ticket.office prefix = office.prefix if show_prefix else '' office_text = f'{prefix}{getattr(office, "name", "")}' tts_text = get_tts_safely().get(language, {})\ .get('message') if language.startswith('en'): tts_text = tts_text.format(aliases.office) return ticket.display_text if single_row_queuing\ else f'{ticket.display_text}{tts_text}{office_text}'
def test_display_screen_customization(c): properties = { 'title': 'testing', 'hsize': '500%', 'hcolor': 'testing', 'hbg': 'testing', 'tsize': '200%', 'tcolor': 'testing', 'h2size': '150%', 'h2color': 'testing', 'ssize': '500%', 'scolor': 'testing', 'mduration': '2000', 'hfont': 'testing', 'tfont': 'testing', 'h2font': 'testing', 'sfont': 'testing', 'rrate': '2000', 'anr': 3, 'anrt': 'each', 'effect': 'bounce', 'repeats': '2', 'prefix': True, 'always_show_ticket_number': True, 'bgcolor': 'testing' } data = {f'check{s}': True for s in get_tts_safely().keys()} data.update({'display': 1, 'background': 0, 'naudio': 0, **properties}) response = c.post('/displayscreen_c/1', data=data, follow_redirects=True) assert response.status == '200 OK' for key, value in properties.items(): assert getattr(Display_store.get(), key, None) == value
def __init__(self, *args, **kwargs): super(DisplayScreenForm, self).__init__(*args, **kwargs) for m in Media.get_all_images(): self.background.choices += [(m.id, f'{m.id}. {m.name}')] for m in Media.get_all_audios(): self.naudio.choices += [(m.id, f'{m.id}. {m.name}')] for shortcode, bundle in get_tts_safely().items(): self[f'check{shortcode}'].label = self.translate( bundle.get('language'))
def __init__(self, app, interval=5, limit=30): ''' Task to cache tickets text-to-speech announcement audio files. Parameters ---------- app: Flask app interval: int duration of sleep between iterations in seconds limit: int limit of tickets to processes each iteration. ''' super().__init__(app) self.app = app self.interval = interval self.limit = limit self.cached = [] self.tts_texts = get_tts_safely() self.session, self.db = create_aliternative_db(self.app.config.get('DB_NAME'))
def displayscreen_c(stab): ''' view for display screen customization ''' form = DisplayScreenForm() text_to_speech = get_tts_safely() if stab not in range(1, 9): flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) touch_s = data.Display_store.get() if form.validate_on_submit(): touch_s.tmp = form.display.data touch_s.title = form.title.data touch_s.hsize = form.hsize.data touch_s.hcolor = form.hcolor.data touch_s.hbg = form.hbg.data touch_s.tsize = form.tsize.data touch_s.tcolor = form.tcolor.data touch_s.h2size = form.h2size.data touch_s.h2color = form.h2color.data touch_s.ssize = form.ssize.data touch_s.scolor = form.scolor.data touch_s.mduration = form.mduration.data touch_s.hfont = form.hfont.data touch_s.tfont = form.tfont.data touch_s.h2font = form.h2font.data touch_s.sfont = form.sfont.data touch_s.mduration = form.mduration.data touch_s.rrate = form.rrate.data touch_s.anr = form.anr.data touch_s.anrt = form.anrt.data touch_s.effect = form.effect.data touch_s.repeats = form.repeats.data touch_s.prefix = form.prefix.data touch_s.always_show_ticket_number = form.always_show_ticket_number.data touch_s.wait_for_announcement = form.wait_for_announcement.data if not form.background.data: touch_s.bgcolor = form.bgcolor.data touch_s.ikey = None else: touch_s.bgcolor = data.Media.query.filter_by( id=form.background.data).first().name data.Media.query.filter_by( id=form.background.data).first().used = True db.session.commit() touch_s.ikey = form.background.data if not form.naudio.data: touch_s.audio = 'false' touch_s.akey = None else: touch_s.audio = data.Media.query.filter_by( id=form.naudio.data).first().name data.Media.query.filter_by(id=form.naudio.data).first().used = True db.session.commit() touch_s.akey = form.naudio.data enabled_tts = [ s for s in text_to_speech.keys() if form[f'check{s}'].data ] touch_s.announce = ','.join(enabled_tts) if enabled_tts else 'false' db.session.add(touch_s) db.session.commit() flash('Notice: Display customization has been updated. ..', 'info') return redirect(url_for('cust_app.displayscreen_c', stab=1)) if not form.errors: form.display.data = touch_s.tmp form.title.data = touch_s.title form.hsize.data = touch_s.hsize form.hcolor.data = touch_s.hcolor form.hbg.data = touch_s.hbg form.tsize.data = touch_s.tsize form.tcolor.data = touch_s.tcolor form.h2size.data = touch_s.h2size form.h2color.data = touch_s.h2color form.ssize.data = touch_s.ssize form.scolor.data = touch_s.scolor form.mduration.data = touch_s.mduration form.hfont.data = touch_s.hfont form.tfont.data = touch_s.tfont form.h2font.data = touch_s.h2font form.sfont.data = touch_s.sfont form.mduration.data = touch_s.mduration form.rrate.data = touch_s.rrate form.anr.data = touch_s.anr form.anrt.data = touch_s.anrt form.effect.data = touch_s.effect form.repeats.data = touch_s.repeats form.prefix.data = touch_s.prefix form.always_show_ticket_number.data = touch_s.always_show_ticket_number form.wait_for_announcement.data = touch_s.wait_for_announcement if touch_s.bgcolor[:3] == 'rgb': form.bgcolor.data = touch_s.bgcolor form.background.data = 0 else: form.background.data = touch_s.ikey if touch_s.audio == 'false': form.naudio.data = 0 else: form.naudio.data = touch_s.akey for short in touch_s.announce.split(','): field = getattr(form, f'check{short}', None) if field: field.data = short in touch_s.announce return render_template('display_screen.html', form=form, page_title='Display Screen customize', navbar='#snb2', hash=stab, dropdown='#dropdown-lvl2', vtrue=data.Vid.query.first().enable, strue=data.Slides_c.query.first().status, tts=text_to_speech)
class DisplayScreenForm(LocalizedForm): display = SelectField('Select a template for Display screen : ', coerce=int, choices=DISPLAY_TEMPLATES) title = StringField( 'Enter a title : ', validators=[ InputRequired('Title should be maximum of 300 letters'), Length(0, 300) ]) background = SelectField('Select a background : ', coerce=int, choices=[(0, 'Use color selection')]) hsize = SelectField('Choose title font size : ', coerce=str, choices=FONT_SIZES) hcolor = StringField('Choose title font color : ') hfont = StringField('Choose title font : ') hbg = StringField('Choose title background color : ') tsize = SelectField('choose main heading office font size :', coerce=str, choices=FONT_SIZES) tcolor = StringField('choose main heading office color : ') tfont = StringField('choose main heading office font : ') h2color = StringField('choose main heading ticket color : ') h2size = SelectField('choose main heading ticket font size :', coerce=str, choices=FONT_SIZES) h2font = StringField('choose main heading ticket font : ') ssize = SelectField('choose secondary heading font size : ', coerce=str, choices=FONT_SIZES) scolor = StringField('choose secondary heading color : ') sfont = StringField('choose secondary heading font :') mduration = SelectField('choose motion effect duration of appearing : ', coerce=str, choices=DURATIONS) rrate = SelectField('choose page refresh rate : ', coerce=str, choices=DURATIONS) effect = SelectField('choose visual motion effect for notification : ', coerce=str, choices=VISUAL_EFFECTS) repeats = SelectField('choose motion effect number of repeats : ', coerce=str, choices=VISUAL_EFFECT_REPEATS) anr = SelectField('Number of announcement repeating : ', coerce=int, choices=ANNOUNCEMENT_REPEATS) anrt = SelectField('Type of announcement and notification repeating :', coerce=str, choices=ANNOUNCEMENT_REPEAT_TYPE) naudio = SelectField('Select audio notification : ', coerce=int, choices=[(0, 'Disable audio notification')]) bgcolor = StringField('Select a background color : ') prefix = BooleanField('Attach prefix office letter: ') always_show_ticket_number = BooleanField('Always show ticket number: ') wait_for_announcement = BooleanField('Wait for announcement to finish:') hide_ticket_index = BooleanField('Hide ticket index number:') submit = SubmitField('Apply') for shortcode in get_tts_safely().keys(): locals()[f'check{shortcode}'] = BooleanField() def __init__(self, *args, **kwargs): super(DisplayScreenForm, self).__init__(*args, **kwargs) for m in Media.get_all_images(): self.background.choices += [(m.id, f'{m.id}. {m.name}')] for m in Media.get_all_audios(): self.naudio.choices += [(m.id, f'{m.id}. {m.name}')] for shortcode, bundle in get_tts_safely().items(): self[f'check{shortcode}'].label = self.translate( bundle.get('language'))
("300%", "Small medium"), ("200%", "small"), ("150%", "Very small")] btn_colors = [("btn-success", "Green"), ("btn-info", "Light blue"), ("btn-primary", "Blue"), ("btn-danger", "Red"), ("btn-link", "White")] durations = [("500", "Half a second"), ("1000", "One second"), ("2000", "Two seconds"), ("3000", "Three seconds"), ("4000", "Four seconds"), ("5000", "Five seconds"), ("8000", "Eight seconds"), ("10000", "Ten seconds")] export_tabels = [("User", "Users"), ("Roles", "Roles of usesrs"), ("Office", "Offices"), ("Task", "Tasks"), ("Serial", "Tickets"), ("Waiting", "Waiting tickets")] export_delimiters = [',', '\t', '\n', '*', '#'] export_options = {0: 'Comma', 1: 'Tab', 2: 'New line', 3: 'Star', 4: 'Hashtag'} tms = [(0, "First Template"), (1, "Second Template"), (2, "Third Template")] tts = get_tts_safely() # -- Customizing and updating touch class Touch_c(FlaskForm): touch = SelectField(coerce=int) title = StringField() hsize = SelectField(coerce=str) hcolor = StringField() hfont = StringField() hbg = StringField() tsize = SelectField(coerce=str) tcolor = SelectField(coerce=str) tfont = StringField() msize = SelectField()