Skip to content

Commit

Permalink
Merge pull request #70 from mrf345/testing
Browse files Browse the repository at this point in the history
Add pull random ticket. And small housekeeping.
  • Loading branch information
mrf345 authored Feb 9, 2020
2 parents 4e11244 + fbbcbfc commit 82ad6e4
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,9 @@ installiation/

# editor
.vscode/

# database
data.sqlite

# audio files
*.mp3
1 change: 1 addition & 0 deletions app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def pull(self, office_id):
self.pulledBy = getattr(current_user, 'id', None)
self.office_id = office_id

db.session.add(self)
db.session.commit()


Expand Down
30 changes: 30 additions & 0 deletions app/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,36 @@ def operators_not_allowed():
return general_redirection


@core.route('/pull_unordered/<ticket_id>/<redirect_to>', defaults={'office_id': None})
@core.route('/pull_unordered/<ticket_id>/<redirect_to>/<office_id>')
@login_required
@refill_waiting_list
def pull_unordered(ticket_id, redirect_to, office_id=None):
office = data.Office.get(office_id)
ticket = data.Serial.query.filter_by(id=ticket_id).first()
strict_pulling = data.Settings.get().strict_pulling
show_prefix = data.Display_store.get().prefix

if not ticket:
flash('Error: wrong entry, something went wrong', 'danger')
return redirect(url_for('core.root'))

if is_operator() and not (is_office_operator(ticket.office_id)
if strict_pulling else
is_common_task_operator(ticket.task_id)):
flash('Error: operators are not allowed to access the page ', 'danger')
return redirect(url_for('core.root'))

office = office or ticket.office

data.Waiting_c.assume(ticket, office, ticket.task, show_prefix)
ticket.pull(office.id)
data.Waiting.drop([ticket])

flash('Notice: Ticket has been pulled ..', 'info')
return redirect(f'{redirect_to}'.replace('(', '/'))


@core.route('/feed')
def feed():
''' stream list of waiting tickets and current ticket. '''
Expand Down
7 changes: 7 additions & 0 deletions gt_cached.json
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,13 @@
"fr": "Trait\u00e9",
"it": "Processed"
},
"Pull": {
"ar": "\u0633\u062d\u0628. \u0634\u062f",
"en": "Pull",
"es": "Halar",
"fr": "Tirer",
"it": "Tirare"
},
"Pull a ticket": {
"ar": "\u0633\u062d\u0628 \u062a\u0630\u0643\u0631\u0629",
"en": "Pull a ticket",
Expand Down
24 changes: 19 additions & 5 deletions templates/all_offices.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ <h2 class="text text-center"><strong> {{ translate('All tickets', 'en', [defLang
</div>
<div class="panel-body">
<div class="row text-center ar2 h3 text-muted hidden-xs">
<div class="col-xs-2">
<div class="col-xs-1">
({{ translate('Ticket', 'en', [defLang]) }})
</div>
<div class="col-xs-2">
({{ translate('Issued', 'en', [defLang]) }})
</div>
<div class="col-xs-3">
<div class="col-xs-2">
({{ translate('pulled', 'en', [defLang]) }})
</div>
<div class="col-xs-3">
Expand All @@ -82,17 +82,20 @@ <h2 class="text text-center"><strong> {{ translate('All tickets', 'en', [defLang
<div class="col-xs-2">
({{ translate('Ticket type', 'en', [defLang]) }})
</div>
<div class="col-xs-2">
({{ translate('Actions', 'en', [defLang]) }})
</div>
</div>
{% for o in officesp %}

<div class="row well {% if o.p %} text-primary {% else %} text-danger {% endif %} h4 text-center">
<div class="col-xs-12 col-sm-2">
<div class="col-xs-12 col-sm-1">
<b> {{ o.office.prefix }}{{ o.number }}.</b>
</div>
<div class="col-xs-12 col-sm-2">
{{ moment(o.timestamp).format('L') }}
</div>
<div class="col-xs-12 col-sm-3">
<div class="col-xs-12 col-sm-2">
{% if o.p %} <u>{{ o.puller_name }} / {{ moment(o.pdt).fromNow() }}</u>
{% else %} <u>{{ translate('Waiting', 'en', [defLang]) }}</u> {% endif %}
</div>
Expand All @@ -101,7 +104,18 @@ <h2 class="text text-center"><strong> {{ translate('All tickets', 'en', [defLang
</div>
<div class="col-xs-12 col-sm-2">
<u> {% if o.n %} {{ translate('Registered', 'en', [defLang]) }} {% else %} {{ translate('Printed', 'en', [defLang]) }} {% endif %} </u>
</div>
</div>
<div class="col-xs-12 col-sm-2">
{% if not o.p %}
<a href="{{ url_for('core.pull_unordered', ticket_id=o.id, redirect_to=current_path.replace('/', '(')) }}"
data-toggle="tooltip" title="{{ translate('Pull', 'en', [defLang]) }}"
>
<span class="fa fa-minus text-primary"></span>
</a>
{% else %}
<u>{{ translate('None', 'en', [defLang]) }}</u>
{% endif %}
</div>
</div>

{% endfor %}
Expand Down
24 changes: 19 additions & 5 deletions templates/offices.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ <h2 class="text text-center">
</div>
<div class="panel-body">
<div class="row text-center h3 text-muted hidden-xs ar2">
<div class="col-xs-2">
<div class="col-xs-1">
({{ translate('Ticket', 'en', [defLang]) }})
</div>
<div class="col-xs-2">
({{ translate('Issued', 'en', [defLang]) }})
</div>
<div class="col-xs-3">
<div class="col-xs-2">
({{ translate('Pulled', 'en', [defLang]) }})
</div>
<div class="col-xs-3">
Expand All @@ -116,17 +116,20 @@ <h2 class="text text-center">
<div class="col-xs-2">
({{ translate('Ticket type', 'en', [defLang]) }})
</div>
<div class="col-xs-2">
({{ translate('Actions', 'en', [defLang]) }})
</div>
</div>
{% for o in officesp %}

<div class="row well {% if o.p %} text-primary {% else %} text-danger {% endif %} h4 ar1 text-center">
<div class="col-xs-12 col-sm-2">
<div class="col-xs-12 col-sm-1">
<b> {{ ooid.prefix }}{{ o.number }}.</b>
</div>
<div class="col-xs-12 col-sm-2">
<u>{{ moment(o.timestamp).format('L') }}</u>
</div>
<div class="col-xs-12 col-sm-3">
<div class="col-xs-12 col-sm-2">
{% if o.p %} <u>{{ users.filter_by(id=o.pulledBy).first().name }} / {{ moment(o.pdt).fromNow() }}</u>
{% else %} <u>{{ translate('Waiting', 'en', [defLang]) }}</u> {% endif %}
</div>
Expand All @@ -136,7 +139,18 @@ <h2 class="text text-center">
</div>
<div class="col-xs-12 col-sm-2">
<u> {% if o.n %} {{ translate('Registered', 'en', [defLang]) }} {% else %} {{ translate('Printed', 'en', [defLang]) }} {% endif %} </u>
</div>
</div>
<div class="col-xs-12 col-sm-2">
{% if not o.p %}
<a href="{{ url_for('core.pull_unordered', office_id=ooid.id, ticket_id=o.id, redirect_to=current_path.replace('/', '(')) }}"
data-toggle="tooltip" title="{{ translate('Pull', 'en', [defLang]) }}"
>
<span class="fa fa-minus text-primary"></span>
</a>
{% else %}
<u>{{ translate('None', 'en', [defLang]) }}</u>
{% endif %}
</div>
</div>

{% endfor %}
Expand Down
24 changes: 19 additions & 5 deletions templates/tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ <h2 class="text text-center">
</div>
<div class="panel-body">
<div class="row text-center h3 text-muted hidden-xs ar2">
<div class="col-xs-2">
<div class="col-xs-1">
({{ translate('Ticket', 'en', [defLang]) }})
</div>
<div class="col-xs-2">
({{ translate('Issued', 'en', [defLang]) }})
</div>
<div class="col-xs-3">
<div class="col-xs-2">
({{ translate('Pulled', 'en', [defLang]) }})
</div>
<div class="col-xs-3">
Expand All @@ -89,17 +89,20 @@ <h2 class="text text-center">
<div class="col-xs-2">
({{ translate('Ticket type', 'en', [defLang]) }})
</div>
<div class="col-xs-2">
({{ translate('Actions', 'en', [defLang]) }})
</div>
</div>
{% for o in tasksp %}

<div class="row well {% if o.p %} text-primary {% else %} text-danger {% endif %} ar1 h4 text-center">
<div class="col-xs-12 col-sm-2">
<div class="col-xs-12 col-sm-1">
<b> {% for oo in o.offices %} {{ oo.prefix }} {% endfor %} {# offices.filter_by(id=o.office_id).first().prefix #}{{ o.number }}.</b>
</div>
<div class="col-xs-12 col-sm-2">
<u>{{ moment(o.timestamp).format('L') }}</u>
</div>
<div class="col-xs-12 col-sm-3">
<div class="col-xs-12 col-sm-2">
{% if o.p %} <u>{{ users.filter_by(id=o.pulledBy).first().name }} / {{ moment(o.pdt).fromNow() }}</u>
{% else %}
<u>{{ translate('Waiting', 'en', [defLang]) }}</u>
Expand All @@ -112,7 +115,18 @@ <h2 class="text text-center">
</div>
<div class="col-xs-12 col-sm-2">
<u> {% if o.n %} {{ translate('Registered', 'en', [defLang]) }} {% else %} {{ translate('Printed', 'en', [defLang]) }} {% endif %} </u>
</div>
</div>
<div class="col-xs-12 col-sm-2">
{% if not o.p %}
<a href="{{ url_for('core.pull_unordered', office_id=ofc_id, ticket_id=o.id, redirect_to=current_path.replace('/', '(')) }}"
data-toggle="tooltip" title="{{ translate('Pull', 'en', [defLang]) }}"
>
<span class="fa fa-minus text-primary"></span>
</a>
{% else %}
<u>{{ translate('None', 'en', [defLang]) }}</u>
{% endif %}
</div>
</div>

{% endfor %}
Expand Down
14 changes: 14 additions & 0 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ def test_pull_tickets_from_all(_, client):
assert Waiting.query.count() == (10 if in_waiting else 11) # NOTE: last ticket pulled deducted


@pytest.mark.parametrize('_', range(TEST_REPEATS))
def test_pull_random_ticket(_, client):
with client.application.app_context():
ticket = choice(Serial.query.filter_by(n=False)\
.limit(10)\
.all())
office = choice(ticket.task.offices)

response = client.get(f'/pull_unordered/{ticket.id}/testing/{office.id}')

assert Serial.query.filter_by(id=ticket.id).first().p == True
assert Waiting.query.filter_by(number=ticket.number).first() is None


@pytest.mark.parametrize('_', range(TEST_REPEATS))
def test_pull_tickets_from_common_task(_, client):
with client.application.app_context():
Expand Down
2 changes: 1 addition & 1 deletion todo_now.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- [x] Add migration setup with `flask-migrate` to avoid dropping tables with each release (2020-02-09)
- [x] Pre-load waiting tickets from `/feed` to reduce text-to-speech generation latency (2020-02-09)
- [ ] Add option to disable all the transition effects and reddit-wallpapers
- [ ] Pull random ticket from `tasks` or `offices`
- [x] Pull random ticket from `tasks` or `offices` (2020-02-10)
- [ ] Option to display ticket number beside name on `display` screen
- [ ] Put random ticket on-hold

Expand Down

0 comments on commit 82ad6e4

Please sign in to comment.