Skip to content

Commit

Permalink
feat: phone number field on touch screen
Browse files Browse the repository at this point in the history
  • Loading branch information
mo2menelzeiny committed May 14, 2020
1 parent 4fd0b5d commit e4be89a
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class Serial(db.Model, TicketsMixin):
timestamp = db.Column(db.DateTime(), index=True, default=datetime.utcnow)
date = db.Column(db.Date(), default=datetime.utcnow().date)
name = db.Column(db.String(300), nullable=True)
phone = db.Column(db.String(11), nullable=True)
n = db.Column(db.Boolean)
p = db.Column(db.Boolean)
# stands for proccessed , which be modified after been processed
Expand All @@ -136,11 +137,12 @@ class Serial(db.Model, TicketsMixin):
task_id = db.Column(db.Integer, db.ForeignKey('tasks.id'))

def __init__(self, number=100, office_id=1, task_id=1,
name=None, n=False, p=False, pulledBy=0):
name=None, phone=None, n=False, p=False, pulledBy=0):
self.number = number
self.office_id = office_id
self.task_id = task_id
self.name = name
self.phone = phone
self.n = n
# fixing mass use tickets multi operators conflict
self.p = p
Expand Down
9 changes: 8 additions & 1 deletion app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from wtforms import SubmitField, PasswordField, SelectField
from wtforms import TextAreaField, IntegerField, BooleanField
from flask_wtf.file import FileAllowed
from wtforms.validators import InputRequired, Length, NumberRange, Optional
from wtforms.validators import InputRequired, Length, NumberRange, Optional, Regexp

import app.database as data
from app.middleware import gtranslator
Expand Down Expand Up @@ -481,6 +481,7 @@ def __init__(self, defLang='en', *args, **kwargs):

class Touch_name(FlaskForm):
name = StringField(" ")
phone = StringField(" ")
submit = SubmitField("Register")

def __init__(self, defLang='en', *args, **kwargs):
Expand All @@ -489,6 +490,12 @@ def __init__(self, defLang='en', *args, **kwargs):
(gtranslator.translate("Required not less than 5 nor more than 300 letters", 'en', [defLang])),
Length(3, 300)]

self.phone.validators = [
InputRequired(gtranslator.translate("Required not less than 11 digits", 'en', [defLang])),
Length(11, 11, gtranslator.translate("Field not less than 11 numbers", 'en', [defLang])),
Regexp(r'^[0-9]+$', 0, (gtranslator.translate("Only Numbers allowed", 'en', [defLang])))
]


# Download CSV form ------

Expand Down
3 changes: 2 additions & 1 deletion app/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def printer_failure_redirect(exception):
printed = not touch_screen_stings.n
numeric_ticket_form = ticket_settings.value == 2
name_or_number = form.name.data or None
phone = form.phone.data or None

if not task:
flash('Error: wrong entry, something went wrong', 'danger')
Expand Down Expand Up @@ -140,7 +141,7 @@ def printer_failure_redirect(exception):
return printer_failure_redirect(exception)

db.session.add(data.Serial(number=next_number, office_id=office.id, task_id=task.id,
name=name_or_number, n=not printed))
name=name_or_number, phone=phone, n=not printed))
db.session.commit()
return redirect(url_for('core.touch', a=1, office_id=office_id))

Expand Down
17 changes: 17 additions & 0 deletions gt_cached.json
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,10 @@
"fr": "Effet de fondu",
"it": "Effetto dissolvenza"
},
"Field not less than 11 numbers": {
"ar": "\u0648\u0644\u064a\u0633 \u0623\u0642\u0644 \u0645\u0646 11 \u0623\u0631\u0642\u0627\u0645",
"en": "Field not less than 11 numbers"
},
"First Template": {
"ar": "\u0623\u0648\u0644 \u0642\u0627\u0644\u0628",
"en": "First Template",
Expand Down Expand Up @@ -1877,6 +1881,10 @@
"fr": "Une fois",
"it": "Una volta"
},
"Only Numbers allowed": {
"ar": "\u0623\u0631\u0642\u0627\u0645 \u0627\u0644\u0648\u062d\u064a\u062f\u0629 \u0633\u0645\u062d\u062a",
"en": "Only Numbers allowed"
},
"Only allowed range of numbers 1-9999": {
"ar": "\u064a\u0633\u0645\u062d \u0641\u0642\u0637 \u0645\u062c\u0645\u0648\u0639\u0629 \u0645\u0646 \u0627\u0644\u0623\u0631\u0642\u0627\u0645 1-9999",
"en": "Only allowed range of numbers 1-9999",
Expand Down Expand Up @@ -1947,6 +1955,7 @@
"en": "Please, enter the nick name to be registered along with your ticket"
},
"Please, enter the number to be registered along with your ticket": {
"ar": "\u0645\u0646 \u0641\u0636\u0644\u0643\u060c \u0623\u062f\u062e\u0644 \u0631\u0642\u0645 \u062a\u0633\u062c\u064a\u0644\u0647\u0627 \u062c\u0646\u0628\u0627 \u0625\u0644\u0649 \u062c\u0646\u0628 \u0645\u0639 \u062a\u0630\u0643\u0631\u062a\u0643",
"en": "Please, enter the number to be registered along with your ticket"
},
"Preferences": {
Expand Down Expand Up @@ -2205,6 +2214,14 @@
"fr": "R\u00e9p\u00e9ter l'annonce",
"it": "Ripeti l'annuncio"
},
"Required not less than 11 digits": {
"ar": "\u0645\u0637\u0644\u0648\u0628 \u0645\u0627 \u0644\u0627 \u064a\u0642\u0644 \u0639\u0646 11 \u0631\u0642\u0645\u0627",
"en": "Required not less than 11 digits"
},
"Required not less than 11 numbers": {
"ar": "\u0645\u0637\u0644\u0648\u0628 \u0645\u0627 \u0644\u0627 \u064a\u0642\u0644 \u0639\u0646 11 \u0623\u0631\u0642\u0627\u0645",
"en": "Required not less than 11 numbers"
},
"Required not less than 5 nor more than 200 letters": {
"ar": "\u0645\u0637\u0644\u0648\u0628 \u0644\u0627 \u064a\u0642\u0644 \u0639\u0646 5 \u0648\u0644\u0627 \u064a\u0632\u064a\u062f \u0639\u0646 200 \u062d\u0631\u0641",
"en": "Required not less than 5 nor more than 200 letters",
Expand Down
27 changes: 27 additions & 0 deletions migrations/versions/6a6b7f682e91_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
""" Adding `phone` field to serials
Revision ID: 6a6b7f682e91
Revises: d37b1524c3fc
Create Date: 2020-05-14 00:29:17.301582
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '6a6b7f682e91'
down_revision = 'd37b1524c3fc'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('serials', sa.Column('phone', sa.String(11), nullable=True))
pass


def downgrade():
with op.batch_alter_table('serials') as batch:
batch.drop_column('phone')
pass
6 changes: 6 additions & 0 deletions templates/touch.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
</p>
{% endif %}
{{ render_field(form.name, class="form-control mt-1 mb-2") }}

<p class="h2 ar1 text-center mt-2 text-danger">
| {{ translate('Please, enter the ' + alias.number + ' to be registered along with your ticket', 'en', [defLang]) }} |
</p>

{{ render_field(form.phone, class="form-control mt-1 mb-2") }}
<center>
<button class="btn btn-lg btn-danger ar1" type="submit">{{ translate('Register', 'en', [defLang]) }}</button>
</center>
Expand Down
7 changes: 5 additions & 2 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ def test_new_registered_ticket(c):
.order_by(Serial.number.desc()).first()

name = 'TESTING REGISTERED TICKET'
phone = '00000000000'
response = c.post(f'/serial/{task.id}', data={
'name': name
'name': name, 'phone': phone
}, follow_redirects=True)
new_ticket = Serial.query.filter_by(task_id=task.id)\
.order_by(Serial.number.desc()).first()

assert response.status == '200 OK'
assert last_ticket.number != new_ticket.number
assert new_ticket.name == name
assert new_ticket.phone == phone


@pytest.mark.usefixtures('c')
Expand Down Expand Up @@ -121,8 +123,9 @@ def test_generate_new_tickets(_, c):
random_task = choice(Task.query.all())

name = choice(NAMES)
phone = '00000000000'
response = c.post(f'/serial/{random_task.id}', data={
'name': name
'name': name, 'phone': phone
}, follow_redirects=True)

assert response.status == '200 OK'
Expand Down

0 comments on commit e4be89a

Please sign in to comment.