Commit e9e66d9cc131358c1bc5902c1c209637d6884215

Authored by fbormann
1 parent 50c09a62

choice field now has initial data and support topics, still has to configure opt…

…ional fields and submit form
reports/forms.py
... ... @@ -2,11 +2,23 @@ from django import forms
2 2 from django.utils.translation import ugettext_lazy as _
3 3 import datetime
4 4  
  5 +
  6 +
5 7 class CreateInteractionReportForm(forms.Form):
6   - topics = forms.ChoiceField(required=True)
  8 + topic = forms.ChoiceField(required=True, label= _("topics to select data from"))
7 9 init_date = forms.DateField(required=True)
8 10 end_date = forms.DateField(required=True)
9 11  
10 12 from_mural = forms.BooleanField()
11 13 from_messages = forms.BooleanField()
12 14  
  15 + class Meta:
  16 + fields = ('topic', 'init_date', 'end_date', 'from_mural' , 'from_messages')
  17 +
  18 + def __init__(self, *args, **kwargs):
  19 + super(CreateInteractionReportForm, self).__init__(*args, **kwargs)
  20 +
  21 + initial = kwargs['initial']
  22 + topics = list(initial['topic'])
  23 +
  24 + self.fields['topic'].choices = [(topic.id, topic.name) for topic in topics]
... ...
reports/templates/reports/_form.html 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +{% load widget_tweaks static i18n %}
  2 +
  3 +<form action="" method="post">{% csrf_token %}
  4 + {% for field in form %}
  5 + {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date' %}
  6 + <label> {{field.label}} </label>
  7 + {% render_field field class='form-control date-picker' %}
  8 +
  9 + {% else %}
  10 + <label> {{field.label}} </label>
  11 + {% render_field field class='form-control' %}
  12 + {% endif %}
  13 +
  14 + {% endfor %}
  15 + <div class="row text-center">
  16 + <input type="submit" value="Search" class="btn btn-success btn-raised" />
  17 + </div>
  18 +</form>
... ...
reports/templates/reports/report.html
... ... @@ -38,14 +38,8 @@
38 38 </ul>
39 39 </div>
40 40  
41   -<form action="" method="post">{% csrf_token %}
42   - {% for field in form %}
43   - <label> {{field.label}} </label>
44   - {% render_field field class='form-control' %}
45   - {% endfor %}
46   - <input type="submit" value="Send message" />
47   -</form>
48   -
  41 + {% include "reports/_form.html" %}
  42 +
49 43 {% for user, datum in data.items %}
50 44  
51 45  
... ...
reports/views.py
1 1 from django.shortcuts import render
2 2 from django.http import HttpResponse, JsonResponse
  3 +from django.utils.translation import ugettext_lazy as _
3 4  
  5 +from django import forms
4 6  
5 7 import django.views.generic as generic
6 8 from mural.models import SubjectPost, Comment, MuralVisualizations
... ... @@ -15,19 +17,16 @@ from log.models import Log
15 17 class ReportView(LoginRequiredMixin, generic.FormView):
16 18 template_name = "reports/report.html"
17 19 form_class = CreateInteractionReportForm
18   - success_url = "/teste"
  20 +
19 21 def get_initial(self):
20 22 """
21 23 Returns the initial data to use for forms on this view.
22 24 """
23 25  
24   - initial = super(ReportView, self).get_initial()
  26 + initial = {}
25 27 params = self.request.GET
26 28 subject = Subject.objects.get(id=params['subject_id'])
27   -
28   - initial['topics'] = subject.topic_subject.all()
29   -
  29 + topics = subject.topic_subject.all()
  30 + initial['topic'] = topics
  31 + initial['end_date'] = date.today()
30 32 return initial
31   -
32   -
33   -
... ...
subjects/templates/subjects/view.html
... ... @@ -56,7 +56,7 @@
56 56 </ul>
57 57 {% endif %}
58 58  
59   - <a href="" class="pull-right action_icon"><i class="fa fa-bar-chart" aria-hidden="true"></i></a>
  59 + <a href="{% url 'subjects:reports:create_interaction' %}?subject_id={{subject.id}}" class="pull-right action_icon"><i class="fa fa-bar-chart" aria-hidden="true"></i></a>
60 60 <a href="{% url 'notifications:view' subject.slug %}" class="pull-right action_icon">
61 61 <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
62 62 {% notifies_number subject request.user %}
... ...