Browse Source

Add rating and notes field to teams

Thomas Ross 4 years ago
parent
commit
420a910af0

+ 33
- 0
teams/forms.py View File

@@ -1,4 +1,5 @@
1 1
 from django import forms
2
+from django.core import validators
2 3
 
3 4
 from FRCScoutWeb.config import CURRENT_FRC_YEAR, ALLOWED_YEARS
4 5
 from FRCScoutWeb.widgets import MultipleCheckboxes, MaterialCheckboxInput
@@ -25,6 +26,22 @@ class NewTeamForm(forms.Form):
25 26
                                            widget=MultipleCheckboxes,
26 27
                                            required=False)
27 28
 
29
+    notes = forms.CharField(label="Notes",
30
+                            required=False,
31
+                            widget=forms.Textarea(attrs={"class": "mdc-textfield__input mdc-typography",
32
+                                                         "cols": 25}))
33
+
34
+    rating = forms.IntegerField(label="Rating",
35
+                                required=False,
36
+                                widget=forms.NumberInput(attrs={"class": "mdc-textfield__input mdc-typography",
37
+                                                                "max": 10,
38
+                                                                "min": 0}),
39
+                                validators=[
40
+                                    validators.MaxValueValidator(10),
41
+                                    validators.MinValueValidator(0)
42
+                                ],
43
+                                help_text="Rating from 0 (worst) to 10 (best)")
44
+
28 45
     favorite = forms.BooleanField(label="Favorite", widget=MaterialCheckboxInput, required=False)
29 46
 
30 47
     def prepare_tasks(self, year=None):
@@ -49,6 +66,22 @@ class EditTeamForm(forms.Form):
49 66
                                            widget=MultipleCheckboxes,
50 67
                                            required=False)
51 68
 
69
+    notes = forms.CharField(label="Notes",
70
+                            required=False,
71
+                            widget=forms.Textarea(attrs={"class": "mdc-textfield__input mdc-typography",
72
+                                                         "cols": 25}))
73
+
74
+    rating = forms.IntegerField(label="Rating",
75
+                                required=False,
76
+                                widget=forms.NumberInput(attrs={"class": "mdc-textfield__input mdc-typography",
77
+                                                                "max": 10,
78
+                                                                "min": 0}),
79
+                                validators=[
80
+                                    validators.MaxValueValidator(10),
81
+                                    validators.MinValueValidator(0)
82
+                                ],
83
+                                help_text="Rating from 0 (worst) to 10 (best)")
84
+
52 85
     favorite = forms.BooleanField(label="Favorite", widget=MaterialCheckboxInput, required=False)
53 86
 
54 87
     def prepare_tasks(self, year=None):

+ 18
- 2
teams/jinja2/teams/edit_team.html View File

@@ -28,6 +28,7 @@
28 28
                             {% set div_attrs %}
29 29
                                 class="mdc-textfield" data-mdc-auto-init="MDCTextfield"
30 30
                             {% endset %}
31
+
31 32
                             {% set label_class = "mdc-textfield__label" %}
32 33
 
33 34
                             {% if field.value() != "" and field.value() != None %}
@@ -35,25 +36,39 @@
35 36
                             {% endif %}
36 37
 
37 38
                             {% set helptext_class = "mdc-textfield-helptext" %}
39
+                        {% elif widget_type == "Textarea" %}
40
+                            {% set div_attrs %}
41
+                                class="mdc-textfield mdc-textfield--multiline" data-mdc-auto-init="MDCTextfield"
42
+                            {% endset %}
43
+
44
+                            {% set label_class = "mdc-textfield__label" %}
45
+
46
+                            {% if field.value() != "" and field.value() != None %}
47
+                                {% set label_class = label_class + " mdc-textfield__label--float-above" %}
48
+                            {% endif %}
38 49
                         {% elif widget_type == "MultipleCheckboxes" %}
39 50
                             {% set div_attrs %}
40 51
                                 class="mdc-form-field mdc-form-field--align-end field-column"
41 52
                             {% endset %}
53
+
42 54
                             {% set label_class = "field-label" %}
55
+
43 56
                             {% set helptext_class = "field-helptext" %}
44 57
                         {% elif widget_type == "MaterialCheckboxInput" %}
45
-                            {# FIXME: This is really hack-y #}
46
-                            <hr style="margin-top: 1em; border: 1px solid var(--mdc-theme-text-hint-on-light, rgba(0,0,0,.38));">
47 58
                             {% set div_attrs %}
48 59
                                 class="mdc-form-field"
49 60
                             {% endset %}
61
+
50 62
                             {% set label_class = "mdc-switch-label" %}
63
+
51 64
                             {% set helptext_class = "field-helptext" %}
52 65
                         {% else %}
53 66
                             {% set div_attrs %}
54 67
                                 class="mdc-form-field"
55 68
                             {% endset %}
69
+
56 70
                             {% set label_class = "field-label" %}
71
+
57 72
                             {% set helptext_class = "field-helptext" %}
58 73
                         {% endif %}
59 74
 
@@ -65,6 +80,7 @@
65 80
                         {% for error in field.errors %}
66 81
                             <span class="field-error">{{ error }}</span>
67 82
                         {% endfor %}
83
+
68 84
                         {% if field.help_text %}
69 85
                             <p class="{{ helptext_class|safe }}" aria-hidden="true">{{ field.help_text }}</p>
70 86
                         {% endif %}

+ 18
- 2
teams/jinja2/teams/new_team.html View File

@@ -26,6 +26,7 @@
26 26
                             {% set div_attrs %}
27 27
                                 class="mdc-textfield" data-mdc-auto-init="MDCTextfield"
28 28
                             {% endset %}
29
+
29 30
                             {% set label_class = "mdc-textfield__label" %}
30 31
 
31 32
                             {% if field.value() != "" and field.value() != None %}
@@ -33,25 +34,39 @@
33 34
                             {% endif %}
34 35
 
35 36
                             {% set helptext_class = "mdc-textfield-helptext" %}
37
+                        {% elif widget_type == "Textarea" %}
38
+                            {% set div_attrs %}
39
+                                class="mdc-textfield mdc-textfield--multiline" data-mdc-auto-init="MDCTextfield"
40
+                            {% endset %}
41
+
42
+                            {% set label_class = "mdc-textfield__label" %}
43
+
44
+                            {% if field.value() != "" and field.value() != None %}
45
+                                {% set label_class = label_class + " mdc-textfield__label--float-above" %}
46
+                            {% endif %}
36 47
                         {% elif widget_type == "MultipleCheckboxes" %}
37 48
                             {% set div_attrs %}
38 49
                                 class="mdc-form-field mdc-form-field--align-end field-column"
39 50
                             {% endset %}
51
+
40 52
                             {% set label_class = "field-label" %}
53
+
41 54
                             {% set helptext_class = "field-helptext" %}
42 55
                         {% elif widget_type == "MaterialCheckboxInput" %}
43
-                            {# FIXME: This is really hack-y #}
44
-                            <hr style="margin-top: 1em; border: 1px solid var(--mdc-theme-text-hint-on-light, rgba(0,0,0,.38));">
45 56
                             {% set div_attrs %}
46 57
                                 class="mdc-form-field"
47 58
                             {% endset %}
59
+
48 60
                             {% set label_class = "mdc-switch-label" %}
61
+
49 62
                             {% set helptext_class = "field-helptext" %}
50 63
                         {% else %}
51 64
                             {% set div_attrs %}
52 65
                                 class="mdc-form-field"
53 66
                             {% endset %}
67
+
54 68
                             {% set label_class = "field-label" %}
69
+
55 70
                             {% set helptext_class = "field-helptext" %}
56 71
                         {% endif %}
57 72
 
@@ -63,6 +78,7 @@
63 78
                         {% for error in field.errors %}
64 79
                             <span class="field-error">{{ error }}</span>
65 80
                         {% endfor %}
81
+
66 82
                         {% if field.help_text %}
67 83
                             <p class="{{ helptext_class|safe }}" aria-hidden="true">{{ field.help_text }}</p>
68 84
                         {% endif %}

+ 25
- 0
teams/migrations/0007_auto_20170406_2220.py View File

@@ -0,0 +1,25 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.10.6 on 2017-04-06 22:20
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('teams', '0006_auto_20170212_0429'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AddField(
16
+            model_name='team',
17
+            name='notes',
18
+            field=models.CharField(blank=True, default='', max_length=5000),
19
+        ),
20
+        migrations.AddField(
21
+            model_name='team',
22
+            name='rating',
23
+            field=models.IntegerField(default=0),
24
+        ),
25
+    ]

+ 4
- 0
teams/models.py View File

@@ -15,6 +15,10 @@ class Team(models.Model):
15 15
 
16 16
     favorite = models.BooleanField(default=False)
17 17
 
18
+    notes = models.CharField(max_length=5000, blank=True, default="")
19
+
20
+    rating = models.IntegerField(default=0)
21
+
18 22
     class Meta:
19 23
         unique_together = ("team_number", "year")
20 24
 

+ 14
- 0
teams/views.py View File

@@ -32,12 +32,18 @@ def new_team(request):
32 32
                 auto_points = form.cleaned_data["auto_points"] or 0
33 33
                 tasks = form.cleaned_data["tasks"]
34 34
 
35
+                notes = form.cleaned_data["notes"] or ""
36
+
37
+                rating = form.cleaned_data["rating"] or 0
38
+
35 39
                 favorite = form.cleaned_data["favorite"] or False
36 40
 
37 41
                 team = Team(team_number=team_number)
38 42
 
39 43
                 team.name = name
40 44
                 team.auto_points = auto_points
45
+                team.notes = notes
46
+                team.rating = rating
41 47
                 team.favorite = favorite
42 48
 
43 49
                 team.save()
@@ -82,10 +88,16 @@ def edit_team(request, team_number):
82 88
             auto_points = form.cleaned_data["auto_points"] or 0
83 89
             tasks = form.cleaned_data["tasks"]
84 90
 
91
+            notes = form.cleaned_data["notes"] or ""
92
+
93
+            rating = form.cleaned_data["rating"] or 0
94
+
85 95
             favorite = form.cleaned_data["favorite"] or False
86 96
 
87 97
             team.name = name
88 98
             team.auto_points = auto_points
99
+            team.notes = notes
100
+            team.rating = rating
89 101
             team.favorite = favorite
90 102
 
91 103
             team.save()
@@ -114,6 +126,8 @@ def edit_team(request, team_number):
114 126
         initial = {"team_name": team.name,
115 127
                    "auto_points": team.auto_points,
116 128
                    "tasks": team.tasks.all(),
129
+                   "notes": team.notes,
130
+                   "rating": team.rating,
117 131
                    "favorite": team.favorite}
118 132
 
119 133
         form = EditTeamForm(initial)