diff --git a/servicePoints/templates/tutor.html b/servicePoints/templates/tutor.html index 158dd1c7bf0c5a4fd0797ea6eb2564a584c4bcd8..963aac255b15361489e2b506a053b5895674005b 100644 --- a/servicePoints/templates/tutor.html +++ b/servicePoints/templates/tutor.html @@ -58,7 +58,7 @@ } .su { - float: right; + text-align:center; } /* Clear floats */ @@ -74,10 +74,6 @@ <a href="/">Home</a> <title>ServicePoints</title> - <div class="su"> - <button onclick="document.getElementById('id01').style.display='block'" style="width:auto; right: 35px">Sign Up</button> - </div> - <div id="id01" class="modal"> <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span> <form class="modal-content" action="/accounts/tutorsu/" method="post"> @@ -95,8 +91,11 @@ <input type="text" placeholder="Enter Times" name="time" required> <div class="clearfix"> + <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button> - <button type="submit" class="signup">Sign Up</button> + <form action="/accounts/tutor/" method="post"> + <input type="submit" class="signup" name="sign" value="Sign Up" /> + </form> </div> </div> </form> @@ -106,8 +105,24 @@ <h1>Welcome to the Service Points Tutoring page!</h1> + {% if registered == 0 %} + <p>Search through our database of current tutors or sign up to have your name and information listed.</p> + <div class="su"> + <button onclick="document.getElementById('id01').style.display='block'" style="width:auto; right: 35px">Sign Up</button> + </div> + + {% endif %} + + {% if registered == 1 %} + <p>Search through our database of current tutors or edit your listed information.</p> + <div class="su"> + <button onclick="document.getElementById('id01').style.display='block'" style="width:auto; right: 35px">Edit Information</button> + <button value='delete' type="submit" class="signup">Delete Profile</button> + </div> + {% endif %} + <h3>Name, Subject(s), Time, Email</h3> <p> {% for tutor, user in zip(tutors, tutorsN) %} diff --git a/servicePoints/views/__pycache__/accounts.cpython-36.pyc b/servicePoints/views/__pycache__/accounts.cpython-36.pyc index 13c2c31e5423a4b2afbad9734437419e5b288607..57b6e372af7265460e6b3531d1e6299db79c7aff 100644 Binary files a/servicePoints/views/__pycache__/accounts.cpython-36.pyc and b/servicePoints/views/__pycache__/accounts.cpython-36.pyc differ diff --git a/servicePoints/views/accounts.py b/servicePoints/views/accounts.py index 85ebb15dc22d320d3220b8c97d6e93401ea827e5..0a345c36f5393228149449d313e73138e3f58062 100644 --- a/servicePoints/views/accounts.py +++ b/servicePoints/views/accounts.py @@ -437,32 +437,43 @@ def images(filename): def tutorsu(): if flask.request.method == 'POST': - - flask.session['subjects'] = flask.request.form['subjects'] - flask.session['time'] = flask.request.form['time'] - cursor = servicePoints.model.get_db().cursor() - name = str(flask.session['username']) + if 'sign' in flask.request.form: + flask.session['subjects'] = flask.request.form['subjects'] + flask.session['time'] = flask.request.form['time'] + cursor = servicePoints.model.get_db().cursor() + name = str(flask.session['username']) - to_add = (name,) - cursor.execute('SELECT * FROM tutors WHERE username=?', to_add) - if cursor.fetchone() is not None: - return flask.redirect(flask.url_for('duplicateTutor')) + # If a user tries to sign up with any empty fields + if flask.session['time'] == '': + return flask.redirect(flask.url_for('incompleteForm', prev="tutorsu")) + if flask.session['subjects'] == '': + return flask.redirect(flask.url_for('incompleteForm', prev="tutorsu")) - # If a user tries to sign up with any empty fields - if flask.session['time'] == '': - return flask.redirect(flask.url_for('incompleteForm', prev="tutorsu")) - if flask.session['subjects'] == '': - return flask.redirect(flask.url_for('incompleteForm', prev="tutorsu")) + data = (flask.session['username'], flask.session['subjects'], + flask.session['time']) - data = (flask.session['username'], flask.session['subjects'], - flask.session['time']) - cur = servicePoints.model.get_db() - cur.execute("INSERT INTO tutors(username, subject, time) VALUES (?, ?, ?)", data) - return flask.redirect(flask.url_for('index')) + to_add = (name,) + cursor.execute('SELECT * FROM tutors WHERE username=?', to_add) + if cursor.fetchone() is not None: + cur = servicePoints.model.get_db() + cur.execute("UPDATE tutors SET username = ?, subject=?, time=?", data) + else: + cur = servicePoints.model.get_db() + cur.execute("INSERT INTO tutors(username, subject, time) VALUES (?, ?, ?)", data) - cursor = servicePoints.model.get_db() + return flask.redirect(flask.url_for('tutorsu')) + cursor = servicePoints.model.get_db().cursor() + name = str(flask.session['username']) + to_add = (name,) + cursor.execute('SELECT * FROM tutors WHERE username=?', to_add) + if cursor.fetchone() is not None: + registered = 1 + else: + registered = 0 + + cursor = servicePoints.model.get_db() cur = cursor.execute("SELECT subject, time FROM tutors") tutors = cur.fetchall() @@ -470,7 +481,7 @@ def tutorsu(): tutorsN = cur2.fetchall() # Add database info to context - context = {"tutors": tutors, "tutorsN": tutorsN} + context = {"tutors": tutors, "tutorsN": tutorsN, "registered": registered} return flask.render_template("tutor.html", **context,zip=zip) @servicePoints.app.route('/accounts/submitPoints/', methods=['GET', 'POST']) diff --git a/var/servicePoints.sqlite3 b/var/servicePoints.sqlite3 index 6783b9ce0615ff90dab41579c79b0393d4f22b88..3e4b0e87de5e2fe100d435fa76bb2e40a3a408f1 100644 Binary files a/var/servicePoints.sqlite3 and b/var/servicePoints.sqlite3 differ