Browse Source

minor code and style edits

trophies
Lephe 3 months ago
parent
commit
05b9328888

+ 7
- 7
app/forms/account.py View File

@@ -6,7 +6,7 @@ from flask_wtf.file import FileField # Cuz' wtforms' FileField is shitty
6 6
 import app.utils.validators as vd
7 7
 
8 8
 class RegistrationForm(FlaskForm):
9
-    username = StringField('Pseudonyme', validators=[DataRequired(), vd.name])
9
+    username = StringField('Pseudonyme', validators=[DataRequired(), vd.name_valid, vd.name_available])
10 10
     email = StringField('Adresse Email', validators=[DataRequired(), Email(), vd.email])
11 11
     password = PasswordField('Mot de passe', validators=[DataRequired(), vd.password])
12 12
     password2 = PasswordField('Répéter le mot de passe', validators=[DataRequired(), EqualTo('password')])
@@ -16,8 +16,8 @@ class RegistrationForm(FlaskForm):
16 16
 
17 17
 class UpdateAccountForm(FlaskForm):
18 18
     avatar = FileField('Avatar', validators=[Optional(), vd.avatar])
19
-    email = StringField('Adresse Email', validators=[Optional(), Email(), vd.email, vd.old_password])
20
-    password = PasswordField('Mot de passe :', validators=[Optional(), vd.password, vd.old_password])
19
+    email = StringField('Adresse email', validators=[Optional(), Email(), vd.email, vd.old_password])
20
+    password = PasswordField('Mot de passe', validators=[Optional(), vd.password, vd.old_password])
21 21
     password2 = PasswordField('Répéter le mot de passe', validators=[Optional(), EqualTo('password')])
22 22
     old_password = PasswordField('Mot de passe actuel', validators=[Optional()])
23 23
     birthday = DateField('Anniversaire', validators=[Optional()])
@@ -33,10 +33,10 @@ class DeleteAccountForm(FlaskForm):
33 33
 
34 34
 
35 35
 class AdminUpdateAccountForm(FlaskForm):
36
-    username = StringField('Pseudonyme', validators=[DataRequired(), vd.name])
36
+    username = StringField('Pseudonyme', validators=[Optional(), vd.name_valid])
37 37
     avatar = FileField('Avatar', validators=[Optional(), vd.avatar])
38
-    email = StringField('Adresse Email', validators=[Optional(), Email(), vd.email])
39
-    password = PasswordField('Mot de passe :', validators=[Optional(), vd.password])
38
+    email = StringField('Adresse email', validators=[Optional(), Email(), vd.email])
39
+    password = PasswordField('Mot de passe', validators=[Optional(), vd.password])
40 40
     xp = DecimalField('XP', validators=[Optional()])
41 41
     innovation = DecimalField('Innovation', validators=[Optional()])
42 42
     birthday = DateField('Anniversaire', validators=[Optional()])
@@ -47,4 +47,4 @@ class AdminUpdateAccountForm(FlaskForm):
47 47
 
48 48
 class AdminDeleteAccountForm(FlaskForm):
49 49
     delete = BooleanField('Confirmer la suppression', validators=[DataRequired()], description='Attention, cette opération est irréversible !')
50
-    submit = SubmitField('Supprimer le compte')
50
+    submit = SubmitField('Supprimer le compte')

+ 8
- 3
app/routes/admin.py View File

@@ -73,21 +73,26 @@ def adm_groups():
73 73
 
74 74
     users  = Member.query.all()
75 75
     groups = Group.query.all()
76
+
76 77
     return render('admin/groups_privileges.html', users=users, groups=groups,
77 78
         form=form)
78 79
 
79 80
 @app.route('/admin/edit-account/<user_id>', methods=['GET', 'POST'])
80 81
 @priv_required('edit-account')
81 82
 def adm_edit_account(user_id):
82
-    user = Member.query.filter_by(id=user_id).first()
83
-    if not user:
84
-        abort(404)
83
+    user = Member.query.filter_by(id=user_id).first_or_404()
84
+
85 85
     form = AdminUpdateAccountForm()
86 86
     if request.method == "POST":
87 87
         if form.validate_on_submit():
88 88
             if form.avatar.data:
89 89
                 f = form.avatar.data
90 90
                 f.save("./app/static/"+user.avatar)
91
+
92
+            newname = form.username.data
93
+            names = list(Member.query.filter(Member.id != user.id).values(Member.name))
94
+            if newname in names:
95
+                raise Exception(f'{data["name"]} is not available')
91 96
             user.update(
92 97
                 name = form.username.data or None,
93 98
                 email = form.email.data or None,

+ 1
- 1
app/static/css/container.css View File

@@ -24,6 +24,6 @@ section h2 {
24 24
 
25 25
 section .avatar {
26 26
 	display: block;
27
-	border-radius: 100%;
27
+	border-radius: 2px;
28 28
 	width: 150px; height: 150px;
29 29
 }

+ 9
- 7
app/static/css/form.css View File

@@ -1,11 +1,9 @@
1 1
 .form .avatar {
2
-	display: inline-block; vertical-align: middle;
3
-	border-radius: 100%;
4 2
 	width: 150px; height: 150px;
5 3
 }
6 4
 
7 5
 .form .avatar + input[type="file"] {
8
-	display: inline-block; margin-left: 20px;
6
+  margin: 16px 0 0 0;
9 7
 	vertical-align: middle;
10 8
 }
11 9
 
@@ -28,15 +26,19 @@
28 26
 .form input[type='password'],
29 27
 .form textarea {
30 28
 	display: block;
31
-	width: 100%; padding: 6px 2.5%;
32
-	border: 1px solid #abcdef;
29
+	width: 100%; padding: 6px 8px;
30
+	border: 1px solid #c0c0c0;
31
+
32
+	/* Transitions when resizing with the mouse produces apparent lag */
33
+	transition: all .15s ease, width 0s, height 0s;
33 34
 }
34 35
 .form input[type='text']:focus,
35 36
 .form input[type='email']:focus,
36 37
 .form input[type='date']:focus,
37 38
 .form input[type='password']:focus,
38 39
 .form textarea:focus {
39
-	box-shadow: 0 0 4px rgba(0, 102, 255, .9);
40
+	border-color: #91bfef;
41
+  box-shadow: 0 0 0 3px rgba(87, 143, 228, 0.42);
40 42
 }
41 43
 
42 44
 .form input[type="submit"] {
@@ -47,4 +49,4 @@
47 49
 	color: red;
48 50
 	font-weight: 400;
49 51
 	margin-top: 5px;
50
-}
52
+}

+ 2
- 1
app/static/css/global.css View File

@@ -10,6 +10,8 @@
10 10
 
11 11
 * {
12 12
 	box-sizing: border-box;
13
+	/* This transition value is replicated everywhere transitions are customized,
14
+	   make sure to track them when editing */
13 15
 	transition: .15s ease;
14 16
 }
15 17
 
@@ -71,7 +73,6 @@ input[type="submit"] {
71 73
 	padding: 6px 10px; border-radius: 2px;
72 74
 	cursor: pointer;
73 75
 	font-family: 'DejaVu Sans', sans-serif; font-weight: 400;
74
-	cursor: pointer;
75 76
 }
76 77
 input[type="button"]:hover,
77 78
 input[type="submit"]:hover,

+ 3
- 2
app/static/css/light.css View File

@@ -134,7 +134,7 @@
134 134
 	margin: 5px 0;
135 135
 }
136 136
 
137
-@media all and (max-width: 550px) {
137
+@media all and (max-width: 549px) {
138 138
 	#light-menu, #spacer-menu {
139 139
 		height: 40px;
140 140
 	}
@@ -188,7 +188,8 @@ header {
188 188
 }
189 189
 
190 190
 section {
191
-	margin: 10px;
191
+	width: unset;
192
+	margin: 16px;
192 193
 }
193 194
 .home-title {
194 195
 	padding: 10px;

+ 1
- 1
app/static/css/navbar.css View File

@@ -143,7 +143,7 @@ nav a:focus {
143 143
 	width: 42px; vertical-align: middle;
144 144
 }
145 145
 #menu h2 img {
146
-	width: 64px; border-radius: 50%; vertical-align: middle; margin-right: 10px;
146
+	width: 64px; border-radius: 2px; vertical-align: middle; margin-right: 10px;
147 147
 }
148 148
 #menu h2 a:hover,
149 149
 #menu h2 a:focus {

+ 5
- 13
app/static/css/responsive.css View File

@@ -1,28 +1,20 @@
1
-/*
2
-	Responsives rules
3
-*/
4
-
5 1
 @media all and (max-width: 1399px) {
6
-	body {
2
+	body, input {
7 3
 		font-size: 13px;
8 4
 	}
9 5
 
10
-	/*header form {
11
-		border-bottom: 1px solid #adb0b4;
12
-	}*/
13 6
 	header input[type="search"] {
14 7
 		font-size: 14px;
15 8
 	}
16 9
 
17 10
 	#menu li {
18
-	font-size: 10px;
11
+		font-size: 10px;
19 12
 	}
20 13
 	#menu a {
21 14
 		font-size: 13px;
22 15
 	}
23 16
 }
24 17
 
25
-
26 18
 @media all and (min-width: 1400px) {
27 19
 	body, input {
28 20
 		font-size: 13px;
@@ -40,13 +32,13 @@
40 32
 	}
41 33
 }
42 34
 
43
-
44
-@media screen and (max-width: 1100px) {
35
+@media screen and (max-width: 1099px) {
45 36
 	.home-pinned-content article:nth-child(5) {
46 37
 		display: none;
47 38
 	}
48 39
 }
49
-@media screen and (max-width: 800px) {
40
+
41
+@media screen and (max-width: 799px) {
50 42
 	.home-pinned-content article:nth-child(4) {
51 43
 		display: none;
52 44
 	}

+ 1
- 1
app/static/css/table.css View File

@@ -12,7 +12,7 @@ table th {
12 12
   border-color: #d0d0d0;
13 13
   border-style: solid;
14 14
   border-width: 1px 0;
15
-  padding: 2px;
15
+  padding: 2px 6px;
16 16
 }
17 17
 table td {
18 18
 	padding: 4px 6px;

+ 1
- 2
app/templates/base/footer.html View File

@@ -1,5 +1,4 @@
1 1
 <footer>
2
-	<p>Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.</p>
2
+	<p>Planète Casio est un site communautaire non affilié à CASIO. Toute reproduction de Planète Casio, même partielle, est interdite.</p>
3 3
 	<p>Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou des copyrights.</p>
4
-	<p>CASIO est une marque déposée par CASIO Computer Co., Ltd.</p>
5 4
 </footer>

+ 3
- 2
app/utils/validators.py View File

@@ -2,10 +2,11 @@ from flask_login import current_user
2 2
 from wtforms.validators import ValidationError
3 3
 from app.models.users import User, Member
4 4
 
5
-def name(form, name):
5
+def name_valid(form, name):
6 6
     if not User.valid_name(name.data):
7 7
         raise ValidationError("Nom d'utilisateur invalide.")
8
-    # last check: do not ask db if useless
8
+
9
+def name_available(form, name):
9 10
     member = Member.query.filter_by(name=name.data).first()
10 11
     if member is not None:
11 12
         raise ValidationError('Pseudo indisponible.')

Loading…
Cancel
Save