Skip to content

Commit

Permalink
more styling changes to base.html & cleaned up validations in main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyneira committed Sep 2, 2017
1 parent 247c290 commit 33173e3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 52 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ __pycache__/
*.py[cod]
*$py.class

#VC Code
.vscode

# C extensions
*.so

Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"python.pythonPath": "/Users/lolaruggamuffin/miniconda3/envs/flask-env/bin/python",
"python.pythonPath": "C:/Users/Cortana/AppData/Local/conda/conda/envs/flask-env/python",
"python.linting.pylintEnabled": false
}
93 changes: 48 additions & 45 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,48 @@ def teacher_signup():
email_DB = Teacher.query.filter_by(email=email).first()

#### VALIDATION ####

err = False
# check for empty fields
if val.is_empty(first):
flash('Please fill in the first name')
return render_template('teacher_login.html', title = 'Signup', signup='active')
flash('Please fill in the first name', 'error')
err = True
elif val.is_empty(last):
flash('Please fill in the last name')
return render_template('teacher_login.html', title = 'Signup', signup='active')
flash('Please fill in the last name', 'error')
err = True
elif val.is_empty(email):
flash('Please fill in the email')
return render_template('teacher_login.html', title = 'Signup', signup='active')
flash('Please fill in the email', 'error')
err = True
elif val.is_empty(password):
flash('Please fill in the password')
return render_template('teacher_login.html', title = 'Signup', signup='active')
flash('Please fill in the password', 'error')
err = True

# check for spaces
if val.space(email):
flash('Email can\'t have space')
return render_template('teacher_login.html', title = 'Signup', signup='active')
flash('Email can\'t have space', 'error')
err = True

#check if email already exists
if email_DB:
if email_DB.email:
flash('Email already in use')
return render_template('teacher_login.html', title = 'Signup', signup='active')
flash('Email already in use', 'error')
err = True

# check for match
if password != confirm_pass:
flash('Passwords must match')
return render_template('teacher_login.html', title = 'Signup')
flash('Passwords must match', 'error')
err = True

# checks length is bigger than 3 characters.
if val.wrong_len(password) or val.wrong_len(confirm_pass):
flash('Password must be longer than 3 characters')
return render_template('teacher_login.html', title = 'Signup', signup='active')
flash('Password must be longer than 3 characters', 'error')
err = True

# Checks that email contains only one period after @ and only one @
if val.wrong_email(email):
flash('Email must contain only one @, one " . " after @')
flash('Email must contain only one @, one " . " after @', 'error')
err = True

if err == True:
return render_template('teacher_login.html', title = 'Signup', signup='active')

new_teacher = Teacher(first, last, email, password)
Expand All @@ -111,10 +114,9 @@ def teacher_login():
session['email'] = email
return redirect('/')
elif teacher and not check_hash(password, teacher.password):
flash("Wrong Password!")
return render_template('teacher_login.html', title = 'Login', login='active')
else:
return render_template('teacher_login.html', title = 'Login', login='active')
flash("Wrong Password!", 'error')

return render_template('teacher_login.html', title = 'Login', login='active')

@app.route('/start_day')
def start_day():
Expand All @@ -133,11 +135,11 @@ def start_day():
return redirect('/student_login')
else:
# the day's list has not been created
flash('Today\'s attendance hasn\'t been created yet.')
return render_template('index.html', title = 'Student Login')
flash('Today\'s attendance hasn\'t been created yet.', 'error')
return render_template('index.html', title = 'Attendance App')
else:
# the day's list already created
flash('Today\'s attendance already created')
flash('Today\'s attendance already created', 'error')
return render_template('index.html', title = 'Attendance App')


Expand All @@ -153,32 +155,33 @@ def student_login():
student_att = Attendance.query.filter_by(owner_id = student_id,
date_now = date.today()).first()


if not pin:
flash("Please enter your Pin!")
flash("Please enter your Pin!", 'error')
return render_template('student_login.html', title ='Student Login', students = students)
elif not pin.isdigit():
flash("Your Pin cannot have Letters!")
flash("Your Pin cannot have Letters!", 'error')
return render_template('student_login.html', title ='Student Login', students = students)
elif student and student.pin == 0 and student.pin == int(pin):
# Redirect student to change pin if it's the first time the sign in.
flash("Please change your pin")
flash("Please change your pin", 'error')
return redirect('/change_pin?id=' + student_id)
elif student and student.pin != int(pin):
flash("Wrong Pin!")
flash("Wrong Pin!", 'error')
return render_template('student_login.html', title ='Student Login', students = students)
else:
# no validation error
# make student present in attendance table
student_att.present = True
db.session.commit()
flash("{0} Signed in!".format(student.first_name.title()))
flash(student.first_name.title()+" Signed in!", 'info')
return render_template('student_login.html', title ='Student Login', students = students)
else:
attendance_exists = Attendance.query.filter_by(date_now = date.today()).first()

# Validate if today's date exists in database
if attendance_exists is None:
flash('Please create today\'s attendance list first (Press \'START DAY\' button)')
flash('Please create today\'s attendance list first (Press \'START DAY\' button)' , 'error')
return render_template('index.html', title = 'Attendance App')

return render_template('student_login.html', title = 'Student Login', students = students)
Expand All @@ -202,30 +205,30 @@ def change_pin():
pin = request.form['pin']
confirm_pin = request.form['confirm_pin']

# Validation
### Validation ###
err = False
if val.is_empty(pin) or val.is_empty(confirm_pin):
flash('Please enter a pin')
return render_template('change_pin.html',student = student,
title = 'Change Pin')
flash('Please enter a pin', 'error')
err = True
elif pin != confirm_pin:
flash('Pins must match')
return render_template('change_pin.html',student = student,
title = 'Change Pin')
flash('Pins must match', 'error')
err = True
elif len(pin) != 4 or not pin.isdigit():
flash('Pin must be 4 digits long and can only contain integers')
return render_template('change_pin.html',student = student,
title = 'Change Pin')
flash('Pin must be 4 digits long and can only contain integers', 'error')
err = True
elif int(pin) == 0:
flash('Your pin can\'t be 0')
return render_template('change_pin.html',student = student,
title = 'Change Pin')
flash('Your pin can\'t be 0', 'error')
err = True

if err == True:
return render_template('change_pin.html',student = student, title = 'Change Pin')

# change pin in the user table
student.pin = pin
# sign in students for the day, attendance table
student_att.present = True
db.session.commit()
flash(student.first_name.title() + ' Logged in!')
flash(student.first_name.title() +' Signed in!', 'info')
return redirect('/student_login')

@app.route("/attendance", methods=['GET', 'POST'])
Expand Down
25 changes: 19 additions & 6 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
nav .brand-logo{
font-size: 1.75rem;
}
nav li a{
font-weight: 700;
text-transform: uppercase;
}
.dropdown-content li>span{
color: #344A5F !important;
}
Expand All @@ -49,7 +53,7 @@
background-color: #F0400F !important;
}
.dropdown-content{
min-width: 165px;
min-width: 190px;
}
.page-footer .footer-copyright{
background-color: rgba(51,51,51,0.1) !important;
Expand Down Expand Up @@ -97,9 +101,18 @@
.btn:hover{
background-color: #F0400F !important;
}
.error{
background-color: #F0400F !important;
}
.info{
background-color: seagreen !important;
}
.lc-blue-text{
color: #344A5F !important;
}
nav li a.lc-blue-text:hover{
color: #5C93CE !important;
}
.lc-blue{
background-color: #344A5F;
}
Expand All @@ -124,9 +137,9 @@
// Initialize options
$('select').material_select();
// Flash Messages Toasts
{% with messages = get_flashed_messages() %}
{% for message in messages %}
Materialize.toast('{{ message }}', 4000);
{% with messages = get_flashed_messages(with_categories=True) %}
{% for class, message in messages %}
Materialize.toast('{{ message }}', 4000, '{{ class }}');
{% endfor %}
{% endwith %}
});
Expand All @@ -137,10 +150,10 @@
<div class="navbar-fixed">
<nav>
<div class="nav-wrapper white">
<a href="/" class="brand-logo center lc-blue-text">LaunchCode <img src="https://www.launchcode.org/assets/launchcode-7e70c69adb4c3c1aa6d5aa15eba45fac.ico" alt="LC"> Attendance</a>
<a href="/" class="brand-logo center lc-blue-text"><img src="https://www.launchcode.org/assets/dabomb-28b8ab97074a9227f8bdf7c2fc61daf2.svg" alt="LC"></a>
{% if session['email'] %}
<ul class="left">
<li><a class="dropdown-button waves-effect waves-light lc-blue-text" href="#!" data-activates="dropdown"><i class="material-icons">menu</i></a></li>
<li><a class="dropdown-button waves-effect waves-light lc-blue-text" href="#!" data-activates="dropdown"><i class="material-icons">menu</i></a></li>
</ul>
<a href="#" data-activates="mobile-demo" class="button"></a>
<ul class="dropdown-content lc-light-orange" id="dropdown">
Expand Down

0 comments on commit 33173e3

Please sign in to comment.