diff --git a/smash/web/forms/forms.py b/smash/web/forms/forms.py index f18aed03d562e672fdb35b14702db6f9b33b0fd7..92088a283f2579b97eaa399a20937231ed855d74 100644 --- a/smash/web/forms/forms.py +++ b/smash/web/forms/forms.py @@ -375,6 +375,12 @@ class FlyingTeamAddForm(ModelForm): fields = "__all__" +class FlyingTeamEditForm(ModelForm): + class Meta: + model = FlyingTeam + fields = "__all__" + + class HolidayAddForm(ModelForm): datetime_start = forms.DateTimeField(widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS), initial=datetime.datetime.now().replace(hour=8, minute=0), diff --git a/smash/web/templates/equipment_and_rooms/flying_teams/edit.html b/smash/web/templates/equipment_and_rooms/flying_teams/edit.html new file mode 100644 index 0000000000000000000000000000000000000000..a94f80cc7783e6500b2a16f933da50511175312d --- /dev/null +++ b/smash/web/templates/equipment_and_rooms/flying_teams/edit.html @@ -0,0 +1,62 @@ +{% extends "_base.html" %} +{% load static %} +{% load filters %} + +{% block styles %} + {{ block.super }} + <link rel="stylesheet" href="{% static 'AdminLTE/plugins/awesomplete/awesomplete.css' %}"/> +{% endblock styles %} + +{% block ui_active_tab %}'equipment_and_rooms'{% endblock ui_active_tab %} +{% block page_header %}Edit flying team{% endblock page_header %} +{% block page_description %}{% endblock page_description %} + +{% block title %}{{ block.super }} - Edit flying team{% endblock %} + +{% block breadcrumb %} + {% include "equipment_and_rooms/flying_teams/breadcrumb.html" %} +{% endblock breadcrumb %} + +{% block maincontent %} + + <div class="box box-info"> + <div class="box-header with-border"> + <a href="{% url 'web.views.equipment_and_rooms.flying_teams' %}" class="btn btn-block btn-default">Go back (without changes)</a> + </div> + + <form method="post" action="" class="form-horizontal"> + {% csrf_token %} + + <div class="box-body"> + <div class="col-sm-6"> + {% for field in form %} + <div class="form-group {% if field.errors %}has-error{% endif %}"> + <label for="{# TODO #}" class="col-sm-4 control-label"> + {{ field.label }} + </label> + + <div class="col-sm-8"> + {{ field|add_class:'form-control' }} + </div> + + {% if field.errors %} + <span class="help-block"> + {{ field.errors }} + </span> + {% endif %} + </div> + {% endfor %} + </div> + </div><!-- /.box-body --> + + <div class="box-footer"> + <div class="col-sm-6"> + <button type="submit" class="btn btn-block btn-success">Save</button> + </div> + <div class="col-sm-6"> + <a href="{% url 'web.views.equipment_and_rooms.flying_teams' %}" class="btn btn-block btn-default">Cancel</a> + </div> + </div><!-- /.box-footer --> + </form> + </div> + {% endblock %} diff --git a/smash/web/templates/equipment_and_rooms/flying_teams/index.html b/smash/web/templates/equipment_and_rooms/flying_teams/index.html index fce5e97641fd0c78f3a971585821f40da2de2b39..4a55f8953d80f6144bb0112cebbebee8f1412882 100644 --- a/smash/web/templates/equipment_and_rooms/flying_teams/index.html +++ b/smash/web/templates/equipment_and_rooms/flying_teams/index.html @@ -29,6 +29,7 @@ <tr> <th>No.</th> <th>Location</th> + <th>Edit</th> </tr> </thead> <tbody> @@ -36,6 +37,10 @@ <tr> <td>{{ forloop.counter }}</td> <td>{{ flying_team.place }}</td> + <td> + <a href="{% url 'web.views.equipment_and_rooms.flying_teams_edit' flying_team.id %}" type="button" + class="btn btn-block btn-default">Change</a></td> + </td> </tr> {% endfor %} diff --git a/smash/web/tests/view/test_flying_teams.py b/smash/web/tests/view/test_flying_teams.py index 3848d77fdce773b000dea0f360789139315a2ae5..0e8e11eefac1f026098a0624b19103902fbd2e30 100644 --- a/smash/web/tests/view/test_flying_teams.py +++ b/smash/web/tests/view/test_flying_teams.py @@ -21,16 +21,22 @@ class FlyingTeamTests(LoggedInTestCase): self.assertEqual(response.status_code, 200) def test_flyingteam_add(self): + # TODO return """ # It supposedly doesn't work like this page = reverse('web.views.equipment_and_rooms.flying_teams_add') data = { 'id_place': self.generate_more_or_less_random_name() } - response = self.client.post(page, data) + response = self.client.post(page, data) # <== it doesn't post the + # data at the correct place self.assertEqual(response.status_code, 200) freshly_created = FlyingTeam.objects.filter(place=data['id_place']) self.assertEqual(len(freshly_created), 1) freshly_created.delete() """ + + def test_flyingteam_edit(self): + # TODO + return diff --git a/smash/web/urls.py b/smash/web/urls.py index fb959eaf2996bade503305575991cf490e0fb5bc..7b1137c65d321436acb0ae4f3bc84cef7be342e3 100644 --- a/smash/web/urls.py +++ b/smash/web/urls.py @@ -130,6 +130,7 @@ urlpatterns = [ views.kit.kit_requests_send_mail, name='web.views.kit_requests_send_mail'), url(r'^equipment_and_rooms/flying_teams$', views.flying_teams.flying_teams, name='web.views.equipment_and_rooms.flying_teams'), url(r'^equipment_and_rooms/flying_teams/add$', views.flying_teams.flying_teams_add, name='web.views.equipment_and_rooms.flying_teams_add'), + url(r'^equipment_and_rooms/flying_teams/edit/(?P<flying_team_id>\d+)$', views.flying_teams.flying_teams_edit, name='web.views.equipment_and_rooms.flying_teams_edit'), #################### # MAIL # diff --git a/smash/web/views/flying_teams.py b/smash/web/views/flying_teams.py index 0070339dc65fc5aaeed5428fa642721bb1903bb2..42d1400b1a8b7c11d074d98dd3a09b062d8b3d60 100644 --- a/smash/web/views/flying_teams.py +++ b/smash/web/views/flying_teams.py @@ -1,9 +1,9 @@ # coding=utf-8 -from django.shortcuts import redirect +from django.shortcuts import redirect, get_object_or_404 from . import wrap_response from ..models import FlyingTeam -from ..forms.forms import FlyingTeamAddForm +from ..forms.forms import FlyingTeamAddForm, FlyingTeamEditForm def flying_teams(request): @@ -27,3 +27,16 @@ def flying_teams_add(request): form = FlyingTeamAddForm() return wrap_response(request, 'equipment_and_rooms/flying_teams/add.html', {'form': form}) + + +def flying_teams_edit(request, flying_team_id): + the_flying_team = get_object_or_404(FlyingTeam, id=flying_team_id) + if request.method == 'POST': + form = FlyingTeamEditForm(request.POST, instance=the_flying_team) + if form.is_valid(): + form.save() + return redirect('web.views.equipment_and_rooms.flying_teams') + else: + form = FlyingTeamEditForm(instance=the_flying_team) + + return wrap_response(request, 'equipment_and_rooms/flying_teams/edit.html', {'form': form})