Skip to content

Commit fea89b4

Browse files
committed
Use a select field for universities
1 parent 5838b43 commit fea89b4

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

ramp-database/ramp_database/model/user.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def __init__(self, name, hashed_password, lastname, firstname, email,
147147
access_level='user', hidden_notes='', linkedin_url='',
148148
twitter_url='', facebook_url='', google_url='', github_url='',
149149
website_url='', bio='', is_want_news=True,
150-
universities_id=None):
150+
universities_id=None, graduation_year=None):
151151
self.name = name
152152
self.hashed_password = hashed_password
153153
self.lastname = lastname
@@ -164,9 +164,8 @@ def __init__(self, name, hashed_password, lastname, firstname, email,
164164
self.website_url = website_url
165165
self.bio = bio
166166
self.is_want_news = is_want_news
167-
if universities_id is not None:
168-
self.university = University.query.filter_by(
169-
id=universities_id).one_or_none()
167+
self.universities_id = universities_id
168+
self.graduation_year = graduation_year
170169

171170
@property
172171
def is_active(self):

ramp-database/ramp_database/tools/user.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
def add_user(session, name, password, lastname, firstname, email,
2222
access_level='user', hidden_notes='', linkedin_url='',
2323
twitter_url='', facebook_url='', google_url='', github_url='',
24-
website_url='', bio='', is_want_news=True):
24+
website_url='', bio='', is_want_news=True,
25+
universities_id=None, university=None, graduation_year=None):
2526
"""Add a new user in the database.
2627
2728
Parameters
@@ -58,6 +59,12 @@ def add_user(session, name, password, lastname, firstname, email,
5859
User biography.
5960
is_want_news : bool, default is True
6061
User wish to receive some news.
62+
universities_id: int, default None
63+
The id of the university
64+
university: University
65+
The university object
66+
graduation_year: int, default=None
67+
Graduation year for students
6168
6269
Returns
6370
-------
@@ -74,7 +81,8 @@ def add_user(session, name, password, lastname, firstname, email,
7481
linkedin_url=linkedin_url, twitter_url=twitter_url,
7582
facebook_url=facebook_url, google_url=google_url,
7683
github_url=github_url, website_url=website_url, bio=bio,
77-
is_want_news=is_want_news)
84+
is_want_news=is_want_news, universities_id=universities_id,
85+
graduation_year=graduation_year)
7886

7987
# Creating default team with the same name as the user
8088
# user is admin of his/her own team

ramp-frontend/ramp_frontend/forms.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
from wtforms import ValidationError
1818
from wtforms.widgets import CheckboxInput
1919
from wtforms.widgets import ListWidget
20+
from wtforms.ext.sqlalchemy.fields import QuerySelectField
21+
22+
from ramp_database.model import University
2023

2124

2225
def _space_check(form, field):
@@ -92,7 +95,10 @@ class UserUpdateProfileForm(FlaskForm):
9295
validators.DataRequired(),
9396
validators.NumberRange(min=2010, max=2040)
9497
])
95-
university = StringField('university', [validators.DataRequired()])
98+
university = QuerySelectField(
99+
query_factory=lambda: University.query.all(),
100+
get_label=lambda x: f"{x.name} ({x.country})",
101+
)
96102
is_want_news = BooleanField()
97103

98104

ramp-frontend/ramp_frontend/templates/sign_up.html

+1-6
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,7 @@ <h4 class="modal-title" id="myModalLabel">{{ category }}</h4>
8080
</div>
8181
<div class="form-group">
8282
<label>University</label> <br />
83-
{{ form.university(placeholder="university", list="university-list") }}
84-
<datalist id="university-list">
85-
{% for el in university_names %}
86-
<option value="{{ el[0] }}">
87-
{% endfor %}
88-
</datalist>
83+
{{ form.university(placeholder="university", style="width: 500px;") }}
8984
{% for error in form.website_url.errors %}
9085
<span style="color: red;">[{{ error }}]</span>
9186
{% endfor %}

ramp-frontend/ramp_frontend/views/auth.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def sign_up():
144144
bio=form.bio.data,
145145
is_want_news=form.is_want_news.data,
146146
access_level='not_confirmed',
147-
graduation_year=form.graduation_year,
147+
universities_id=form.university.data.id,
148+
graduation_year=form.graduation_year.data,
148149
)
149150
except NameClashError as e:
150151
flash(str(e))

0 commit comments

Comments
 (0)