Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default background style, Add missing doc string. #76

Merged
merged 2 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ class Mixin:
def get(cls, id):
return cls.query.filter_by(id=id).first()


class TicketsMixin:
def get_ticket_display_text(self):
display_settings = Display_store.query.first()
always_show_ticket_number = display_settings.always_show_ticket_number
name_and_or_number = f'{getattr(self, "number", getattr(self, "ticket", "Empty"))}'

if self.n: # NOTE: registered ticket
if always_show_ticket_number:
name_and_or_number = f'{name_and_or_number} {self.name}'
else:
name_and_or_number = f'{self.name}'

return name_and_or_number


class Office(db.Model, Mixin):
__tablename__ = "offices"
id = db.Column(db.Integer, primary_key=True)
Expand Down Expand Up @@ -92,7 +108,7 @@ def migrate_tickets(self, from_office, to_office):

db.session.commit()

class Serial(db.Model):
class Serial(db.Model, TicketsMixin):
__tablename__ = "serials"
id = db.Column(db.Integer, primary_key=True)
number = db.Column(db.Integer)
Expand Down Expand Up @@ -210,7 +226,7 @@ def toggle_on_hold(self):
db.session.commit()


class Waiting(db.Model):
class Waiting(db.Model, TicketsMixin):
__tablename__ = "waitings"
id = db.Column(db.Integer, primary_key=True)
number = db.Column(db.Integer)
Expand Down Expand Up @@ -244,8 +260,16 @@ def drop(cls, tickets=[]):
db.session.delete(waiting_ticket)
db.session.commit()

@property
def task(self):
return Task.query.filter_by(id=self.task_id).first()

@property
def office(self):
return Office.query.filter_by(id=self.office_id).first()


class Waiting_c(db.Model):
class Waiting_c(db.Model, TicketsMixin):
__tablename__ = "waitings_c"
id = db.Column(db.Integer, primary_key=True)
ticket = db.Column(db.String)
Expand Down Expand Up @@ -475,6 +499,7 @@ class Display_store(db.Model):
bgcolor = db.Column(db.String(100))
tmp = db.Column(db.Integer)
prefix = db.Column(db.Boolean, default=False)
always_show_ticket_number = db.Column(db.Boolean, default=False)
# adding repeat announcement value
r_announcement = db.Column(db.Boolean)
akey = db.Column(db.Integer, db.ForeignKey("media.id",
Expand Down
2 changes: 2 additions & 0 deletions app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class Display_c(FlaskForm):
naudio = SelectField(coerce=int)
bgcolor = StringField()
prefix = BooleanField()
always_show_ticket_number = BooleanField()
submit = SubmitField()

def __init__(self, defLang='en', *args, **kwargs):
Expand Down Expand Up @@ -251,6 +252,7 @@ def __init__(self, defLang='en', *args, **kwargs):
self.naudio.label = gtranslator.translate("Select audio notification : ", 'en', [defLang])
self.bgcolor.label = gtranslator.translate("Select a background color : ", 'en', [defLang])
self.prefix.label = gtranslator.translate("Attach prefix office letter: ", 'en', [defLang])
self.always_show_ticket_number.label = gtranslator.translate("Always show ticket number: ", 'en', [defLang])
self.submit.label = gtranslator.translate('Apply', 'en', [defLang])
bgs = []
aud = []
Expand Down
2 changes: 2 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def create_db(app, testing=False):
----------
app: Flask app
app to use its context to create tables and load initial data.
testing: bool
flag to disable migrations, mainly used during integration testing.
'''
with app.app_context():
try:
Expand Down
3 changes: 1 addition & 2 deletions app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ def format_announcement_text(self, ticket, aliases, language, show_prefix):
office = ticket.office
prefix = office.prefix if show_prefix else ''
office_text = f'{prefix}{office.name}'
ticket_text = f'{prefix}{ticket.number}'
tts_text = self.tts_texts.get(language)

if language == 'en-us':
tts_text = tts_text.format(aliases.office)

return (f'{ticket.name if ticket.n else ticket_text}'
return (f'{ticket.get_ticket_display_text()}'
f'{tts_text}{office_text}')

def run(self):
Expand Down
14 changes: 7 additions & 7 deletions app/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,28 +327,28 @@ def feed():
display_settings = data.Display_store.query.first()
show_prefix = display_settings.prefix
current_ticket = data.Waiting_c.query.first()
current_ticket_text = current_ticket and current_ticket.get_ticket_display_text() or 'Empty'
office_name = getattr(current_ticket, 'oname', 'Empty')
task_name = getattr(current_ticket, 'tname', 'Empty')
name_or_number = getattr(current_ticket,
'name' if current_ticket and current_ticket.n else 'ticket',
'Empty')

def get_prefix(ticket):
return f'{ticket.office.prefix}.' if show_prefix else ''

waiting_tickets = (data.Waiting.query.limit(9).all() + ([None] * 9))[:9]
waiting_list_parameters = {
f'w{_index + 1}':
f'{_index + 1}. {get_prefix(ticket)}{ticket.name if ticket.n else ticket.number}'
if ticket else 'Empty'
f'{_index + 1}. {get_prefix(ticket)}{ticket.get_ticket_display_text()}' if ticket else 'Empty'
for _index, ticket in enumerate(waiting_tickets)
}

# NOTE: Ensure `waiting_list_parameters` last value is as distinct as the `current_ticket`
# To fix `uniqueness` not picking up the change in passed waiting list
waiting_list_parameters[f'w{len(waiting_list_parameters)}'] = name_or_number
waiting_list_parameters[f'w{len(waiting_list_parameters)}'] = (current_ticket.name
if current_ticket.n else
current_ticket.ticket
)if current_ticket else 'Empty'

return jsonify(con=office_name, cot=name_or_number, cott=task_name,
return jsonify(con=office_name, cot=current_ticket_text, cott=task_name,
replay='yes' if display_settings.r_announcement else 'no',
**waiting_list_parameters)

Expand Down
2 changes: 2 additions & 0 deletions app/views/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ def displayscreen_c(stab):
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
bg = form.background.data
if bg == 00:
touch_s.bgcolor = form.bgcolor.data
Expand Down Expand Up @@ -526,6 +527,7 @@ def displayscreen_c(stab):
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
if touch_s.bgcolor[:3] == "rgb":
form.bgcolor.data = touch_s.bgcolor
form.background.data = 00
Expand Down
21 changes: 21 additions & 0 deletions gt_cached.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@
"fr": "Ajouter un utilisateur",
"it": "Aggiungi utente"
},
"Additional preferences and settings to control certain features within the display screen": {
"ar": "\u062a\u0641\u0636\u064a\u0644\u0627\u062a \u0648\u0625\u0639\u062f\u0627\u062f\u0627\u062a \u0625\u0636\u0627\u0641\u064a\u0629 \u0644\u0644\u0633\u064a\u0637\u0631\u0629 \u0639\u0644\u0649 \u0645\u064a\u0632\u0627\u062a \u0645\u0639\u064a\u0646\u0629 \u0641\u064a \u0634\u0627\u0634\u0629 \u0627\u0644\u0639\u0631\u0636",
"en": "Additional preferences and settings to control certain features within the display screen",
"es": "preferencias y ajustes adicionales para controlar ciertas funciones dentro de la pantalla de visualizaci\u00f3n",
"fr": "pr\u00e9f\u00e9rences et param\u00e8tres suppl\u00e9mentaires pour contr\u00f4ler certaines fonctions au sein de l'\u00e9cran d'affichage",
"it": "preferenze e le impostazioni aggiuntive per controllare alcune funzioni all'interno dello schermo di visualizzazione"
},
"Administration": {
"ar": "\u0627\u0644\u0627\u062f\u0627\u0631\u0629",
"en": "Administration",
Expand Down Expand Up @@ -301,6 +308,13 @@
"fr": "Permet \u00e0 l'administrateur, autoris\u00e9 par les op\u00e9rateurs admin de rechercher avec des param\u00e8tres donn\u00e9s du num\u00e9ro de ticket, du pr\u00e9fixe de ticket et / ou de la date du ticket pour atteindre le ticket sp\u00e9cifique destin\u00e9 \u00e0 \u00eatre recherch\u00e9 de mani\u00e8re dynamique et r\u00e9parable.",
"it": "Consente all'amministratore, autorizzato dagli amministratori, di cercare con determinati parametri il numero del biglietto, il prefisso del biglietto e la data del biglietto per raggiungere lo specifico biglietto destinato alla ricerca in modo dinamico e risolvibile, che era ben inteso nel design."
},
"Always show ticket number: ": {
"ar": "\u062a\u0638\u0647\u0631 \u062f\u0627\u0626\u0645\u0627 \u0631\u0642\u0645 \u0627\u0644\u062a\u0630\u0643\u0631\u0629:",
"en": "Always show ticket number:",
"es": "Siempre mostrar el n\u00famero del billete:",
"fr": "Toujours afficher le num\u00e9ro de billet:",
"it": "Mostra sempre il numero del biglietto:"
},
"Apply": {
"ar": "\u062a\u0637\u0628\u064a\u0642",
"en": "Apply",
Expand Down Expand Up @@ -1924,6 +1938,13 @@
"Please, enter the number to be registered along with your ticket": {
"en": "Please, enter the number to be registered along with your ticket"
},
"Preferences": {
"ar": "\u062a\u0641\u0636\u064a\u0644\u0627\u062a",
"en": "Preferences",
"es": "preferencias",
"fr": "pr\u00e9f\u00e9rences",
"it": "Preferenze"
},
"Prefix": {
"ar": "\u0627\u062e\u062a\u0635\u0627\u0631",
"en": "Prefix",
Expand Down
29 changes: 29 additions & 0 deletions migrations/versions/1728b52497ba_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""empty message

Revision ID: 1728b52497ba
Revises: 8f8e67fcbd9c
Create Date: 2020-02-12 05:47:13.140826

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1728b52497ba'
down_revision = '8f8e67fcbd9c'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('displays', sa.Column('always_show_ticket_number', sa.Boolean(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('displays') as batch:
batch.drop_column('always_show_ticket_number')
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions templates/_wallpapers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $('{{ selector }}').css({
'background-size': 'cover',
'background-repeat': 'no-repeat',
'background-position': 'center',
'background-attachment': 'fixed',
'background-image': "linear-gradient({{ overlay }}, {{ overlay }}), url({{ url_for('static', filename='images/dbg.jpg') }})"
})
{% endif %}
Expand Down
29 changes: 29 additions & 0 deletions templates/display_screen.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,38 @@ <h3 class="text text-muted text-center ar2 mt-2 mb-4">
<hr>
{{ render_field(form.background, class="mb-3 form-control") }}
{{ form.bgcolor(class_="sp") }}
<p class="pb-3"></p>
<p class="pb-4"></p>
{{ unique_btns(translate('Previous', 'en', [defLang]), translate('Apply', 'en', [defLang]), translate('Next', 'en', [defLang])) }}
<p class="pt-4"></p>
</div>
</div>
<div class="panel panel-default uniqueness">
<div class="panel-heading text-center">
<h3 class="text-muted">
<strong>
<span class="fa fa-cog"></span>
{{ translate('Display screen', 'en', [defLang]) }} - {{ translate('Preferences', 'en', [defLang]) }}
</strong>
</h3>
</div>
<div class="panel-body">
<center>
<a data-toggle="modal" data-target="#mym">
<img class="img-responsive img-thumbnail tobc mt-4" id="map" width="40%"
src="{{ url_for('static', filename='images/map2.jpg') }}"
>
</a>
<h3 class="text text-muted text-center ar2 mt-2 mb-4">
| {{ translate('Additional preferences and settings to control certain features within the display screen', 'en', [defLang]) }} |
</h3>
</center>
<hr>
{{ render_field(form.rrate, class="form-control") }}
<p class="pb-1"></p>
{{ render_field(form.prefix, class="form-control") }}
<p class="pb-1"></p>
{{ render_field(form.always_show_ticket_number, class="form-control") }}
<p class="pb-3"></p>
{% if form.errors %}
<div class="well">
Expand Down
4 changes: 4 additions & 0 deletions templates/sb_cust.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
<li ><a href="{{ url_for('cust_app.displayscreen_c', stab=7) }}">
7. {{ translate('Background', 'en', [defLang]) }}
<span class="fa fa-picture-o"></span> <span class="badge pull-right" id="bb12"></span></a>
</li>
<li ><a href="{{ url_for('cust_app.displayscreen_c', stab=8) }}">
8. {{ translate('Preferences', 'en', [defLang]) }}
<span class="fa fa-cog"></span> <span class="badge pull-right" id="bb13"></span></a>
</li>
</ul>
</div>
Expand Down
5 changes: 4 additions & 1 deletion templates/sb_dis.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@
<span class="fa fa-bell"></span> <span class="badge pull-right"></span></a></li>
<li id="ds7"><a onclick="unique.goto(6)">
7. {{ translate('Background', 'en', [defLang]) }}
<span class="fa fa-picture-o"></span> <span class="badge pull-right" id="bb11"></span></a></li>
<span class="fa fa-picture-o"></span> <span class="badge pull-right" id="bb11"></span></a></li>
<li id="ds8"><a onclick="unique.goto(7)">
8. {{ translate('Preferences', 'en', [defLang]) }}
<span class="fa fa-cog"></span> <span class="badge pull-right" id="bb12"></span></a></li>
</ul>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions templates/sb_touch.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
<li><a href="{{ url_for('cust_app.displayscreen_c', stab=7) }}">
7. {{ translate('Background', 'en', [defLang]) }}
<span class="fa fa-picture-o"></span> <span class="badge pull-right" id="bb12"></span></a>
</li>
<li><a href="{{ url_for('cust_app.displayscreen_c', stab=8) }}">
8. {{ translate('Preferences', 'en', [defLang]) }}
<span class="fa fa-cog"></span> <span class="badge pull-right" id="bb13"></span></a>
</li>
</ul>
</div>
Expand Down
46 changes: 39 additions & 7 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,44 @@ def test_pull_ticket_on_hold(client):
.first() is None


def test_feed_stream_tickets(client):
def test_feed_stream_tickets_preferences_enabled(client):
client.get('/pull', follow_redirects=True) # NOTE: initial pull to fill stacks

with client.application.app_context():
# NOTE: enable settings to always display ticket number and prefix
display_settings = Display_store.query.first()
display_settings.prefix = True
display_settings.always_show_ticket_number = True
db.session.commit()

tickets = Waiting.query.limit(8)\
.all()
current_ticket = Waiting_c.query.first()

response = client.get('/feed', follow_redirects=True)

assert response.status == '200 OK'
assert response.json.get('con') == current_ticket.oname
assert response.json.get('cott') == current_ticket.tname
assert response.json.get('cot') == current_ticket.get_ticket_display_text()

for i, ticket in enumerate(tickets):
assert ticket.name in response.json.get(f'w{i + 1}')
assert f'{ticket.office.prefix}.' in response.json.get(f'w{i + 1}')
assert f'{ticket.number}' in response.json.get(f'w{i + 1}')



def test_feed_stream_tickets_preferences_disabled(client):
client.get('/pull', follow_redirects=True) # NOTE: initial pull to fill stacks

with client.application.app_context():
# NOTE: enable settings to always display ticket number and prefix
display_settings = Display_store.query.first()
display_settings.prefix = False
display_settings.always_show_ticket_number = False
db.session.commit()

tickets = Waiting.query.limit(8)\
.all()
current_ticket = Waiting_c.query.first()
Expand All @@ -264,14 +298,12 @@ def test_feed_stream_tickets(client):
assert response.status == '200 OK'
assert response.json.get('con') == current_ticket.oname
assert response.json.get('cott') == current_ticket.tname
assert response.json.get('cot') == getattr(current_ticket,
'name' if current_ticket.n
else 'ticket')
assert response.json.get('cot') == current_ticket.get_ticket_display_text()

for i, ticket in enumerate(tickets):
assert (ticket.name
if ticket.n else
ticket.number) in response.json.get(f'w{i + 1}')
assert ticket.name in response.json.get(f'w{i + 1}')
assert f'{ticket.office.prefix}.' not in response.json.get(f'w{i + 1}')
assert f'{ticket.number}' not in response.json.get(f'w{i + 1}')


def test_display_screen(client):
Expand Down
2 changes: 1 addition & 1 deletion todo_now.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- [x] Pre-load waiting tickets from `/feed` to reduce text-to-speech generation latency (2020-02-09)
- [x] Add option to disable all the transition effects and reddit-wallpapers (2020-02-10)
- [x] Pull random ticket from `tasks` or `offices` (2020-02-10)
- [ ] Option to display ticket number beside name on `display` screen
- [x] Option to display ticket number beside name on `display` screen (2020-02-12)
- [x] Put random ticket on-hold (2020-02-10)

- [ ] Multiple Display screen support **based on offices**
Expand Down