-
Notifications
You must be signed in to change notification settings - Fork 0
added student profile model, student profile page, student profile views #5
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
Open
torilov
wants to merge
4
commits into
master
Choose a base branch
from
student-profile
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b4b2d8c
added student profile model, student profile page, student profile views
torilov 58f965a
removed PUT request; moved set_profile method to view; changed querys…
torilov 947ca2d
removed not used import; changed try-catch to if statement in views
torilov 5600fcd
removed not used import
torilov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """Module for Ennead task model and corresponding helper classes""" | ||
|
|
||
| from typing import TYPE_CHECKING, List | ||
|
|
||
| from peewee import BooleanField, CharField, TextField, IntegerField, ForeignKeyField, DateField | ||
|
|
||
| from datetime import date | ||
| from ennead.models.user import User | ||
| from flask import Request | ||
|
|
||
|
|
||
| from ennead.models.base import BaseModel | ||
| if TYPE_CHECKING: | ||
| # pylint: disable=R0401 | ||
| from ennead.models.thread import Thread # noqa: F401 | ||
|
|
||
|
|
||
| class StudentProfile(BaseModel): | ||
| """Student questionnaire | ||
|
|
||
| Attributes: | ||
| grade: year of education | ||
| city: city of living | ||
| birth_date: date of birth | ||
| sex: sex (True if male) | ||
| allergy: human-readable list of allergies | ||
| communication: preferred communication type (vk/telegram profile) | ||
| telephone: student's telephone number | ||
| parent_information: human-readable name and contacts of one | ||
| """ | ||
|
|
||
| grade: int = IntegerField() | ||
| city: str = CharField(32) | ||
| birth_date: date = DateField() | ||
| sex: bool = BooleanField() | ||
| allergy: str = TextField() | ||
| communication: str = TextField() | ||
| telephone: str = CharField(20) | ||
| parent_information: str = TextField() | ||
|
|
||
| user: User = ForeignKeyField(User, backref='student_profiles') | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,7 @@ | |
| position: relative; | ||
| top: 0.05em; | ||
| } | ||
|
|
||
| textarea.student-profile-area { | ||
| height: 6em; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| {% extends 'base.html' %} | ||
|
|
||
| {% block title %}Ennead / Анкета ученика{% endblock %} | ||
|
|
||
| {% block body %} | ||
| <div class="row"> | ||
| <div class="col-4 offset-4"> | ||
| <form method="POST"> | ||
| <div class="form-group row"> | ||
| <label class="col-12" for="grade">Класс, который вы закончили:</label> | ||
| <input class="col-12 form-control" type="number" name="grade" id="grade" required value="{{ student_profile.grade }}"> | ||
| </div> | ||
| <div class="form-group row"> | ||
| <label class="col-12" for="city">Город, в котором вы живёте:</label> | ||
| <input class="col-12 form-control" name="city" id="city" required value="{{ student_profile.city }}"> | ||
| </div> | ||
| <div class="form-group row"> | ||
| <label class="col-12" for="birth_date">Дата вашего рождения:</label> | ||
| <input class="col-12 form-control" type="date" name="birth_date" id="birth_date" required value="{{ student_profile.birth_date }}"> | ||
| </div> | ||
| <div class="form-group row"> | ||
| <label class="col-12" for="sex">Ваш пол:</label> | ||
| <select class="col-12 form-control" name="sex" id="sex" required value="{{ student_profile.sex }}"> | ||
| <option value="1">Мужской</option> | ||
| <option value="0">Женский</option> | ||
| </select> | ||
| </div> | ||
| <div class="form-group row"> | ||
| <label class="col-12" for="allergy">Перечислите всё, на что у вас аллергия:</label> | ||
| <textarea class="col-12 form-control" type="textarea" name="allergy" id="allergy" required>{{ student_profile.allergy }}</textarea> | ||
| </div> | ||
| <div class="form-group row"> | ||
| <label class="col-12" for="communication">Ссылка на вас в социальных сетях (vk, telegram):</label> | ||
| <input class="col-12 form-control" name="communication" id="communication" required value="{{ student_profile.communication }}"> | ||
| </div> | ||
| <div class="form-group row"> | ||
| <label class="col-12" for="telephone">Ваш мобильный телефон:</label> | ||
| <input class="col-12 form-control" name="telephone" id="telephone" required value="{{ student_profile.telephone }}"> | ||
| </div> | ||
| <div class="form-group row"> | ||
| <label class="col-12" for="parent_information">Контактный телефон и имя вашего родителя:</label> | ||
| <textarea class="col-12 student-profile-area form-control" type="textarea" name="parent_information" id="parent_information" required >{{ student_profile.parent_information }}</textarea> | ||
| </div> | ||
| <input type="submit" class="btn btn-primary" value="Сохранить"> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """Views, used for student profiles""" | ||
|
|
||
| from datetime import date | ||
| from ennead.models.user import User | ||
|
|
||
| from flask import session, current_app, render_template, request, redirect, url_for, g | ||
| from werkzeug.wrappers import Response | ||
|
|
||
| from ennead.utils import require_logged_in | ||
| from ennead.models.user import User, UserGroup | ||
| from ennead.models.student_profile import StudentProfile | ||
|
|
||
|
|
||
| @require_logged_in | ||
| def read_student_profile() -> Response: | ||
| """GET /student_profile: read profile page""" | ||
|
|
||
| student_profile = None | ||
| try: | ||
|
||
| student_profile = g.user.student_profiles[0] | ||
| except: | ||
| student_profile = StudentProfile() | ||
|
|
||
| return render_template('student_profile.html', student_profile=student_profile) | ||
|
|
||
|
|
||
| @require_logged_in | ||
| def create_update_student_profile() -> Response: | ||
| """POST /student_profile: update student profile""" | ||
|
|
||
| student_profile = None | ||
| try: | ||
| student_profile = g.user.student_profiles[0] | ||
| except: | ||
| student_profile = StudentProfile() | ||
|
|
||
| for field in ('grade', 'city', 'birth_date', 'allergy', 'sex', | ||
| 'communication', 'parent_information'): | ||
| setattr(student_profile, field, request.form[field]) | ||
|
|
||
| # TODO: add telephone validation | ||
| student_profile.telephone = request.form['telephone'] | ||
|
|
||
| student_profile.user = g.user | ||
|
|
||
| student_profile.save() | ||
| return redirect(url_for('read_student_profile')) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А где ты его используешь?