Project

General

Profile

0002-misc-remove-validation-steps-31454.patch

Frédéric Péters, 16 Mar 2019 10:18 AM

Download (5.64 KB)

View differences:

Subject: [PATCH 2/2] misc: remove validation steps (#31454)

 welco/settings.py                        | 10 ------
 welco/templates/welco/qualification.html | 26 ---------------
 welco/urls.py                            |  1 -
 welco/views.py                           | 42 +-----------------------
 4 files changed, 1 insertion(+), 78 deletions(-)
 delete mode 100644 welco/templates/welco/qualification.html
welco/settings.py
185 185

  
186 186
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
187 187

  
188
# Add validation circuit on specific sources, example:
189
# VALIDATION_STEPS = {'mail': ['done-qualif', 'done-dgs', 'done-dga']}
190
# VALIDATION_STEP_LABELS = {
191
#     'done-qualif': _('Send to DGS'),
192
#     'done-dgs': _('Send to DGA'),
193
#     'done-dga': _('Send to service')}
194

  
195
VALIDATION_STEPS = {}
196
VALIDATION_STEP_LABELS = {}
197

  
198 188
# mapping of channel to group/role *names*
199 189
CHANNEL_ROLES = {
200 190
    'mail': [],
welco/templates/welco/qualification.html
1
{% load i18n %}
2
<div {% if not source_pk %}class="inactive"{% endif %}>
3
{% if source_pk %}
4
<form>
5
	{% if associations|length %}
6
	<ul>
7
		{% for association in associations %}
8
		<li>{{association.formdef_name}}
9
			{% if not association.formdata_id %}
10
			(<a class="remove" href="{% url 'ajax-remove-association' pk=association.id %}">✖</a>)</li>
11
			{% endif %}
12
		{% endfor %}
13
		<li><a href="#" class="plus">{% trans 'Add another' %}</a></li>
14
	</ul>
15
	{% endif %}
16

  
17
	<div class="add-formdef-reference" {% if associations|length %}style="display: none"{% endif %}>
18
		<div>
19
		{{form.formdef_reference}}
20
		</div>
21
		<button class="add">{% trans 'Add' %}</button>
22
	</div>
23

  
24
</form>
25
{% endif %}
26
</div>
welco/urls.py
39 39
    url(r'^', include('welco.sources.phone.urls')),
40 40
    url(r'^', include('welco.sources.counter.urls')),
41 41
    url(r'^ajax/qualification$', welco.views.qualification, name='qualif-zone'),
42
    url(r'^ajax/qualification-done$', welco.views.qualification_done, name='qualif-done'),
43 42
    url(r'^ajax/remove-association/(?P<pk>\w+)$',
44 43
        welco.views.remove_association, name='ajax-remove-association'),
45 44
    url(r'^ajax/create-formdata/(?P<pk>\w+)$',
welco/views.py
67 67

  
68 68

  
69 69
class Qualification(TemplateView):
70
    def get_template_names(self):
71
        source_type = ContentType.objects.get(id=self.request.GET['source_type'])
72
        validation_steps = settings.VALIDATION_STEPS.get(source_type.model.lower())
73
        if validation_steps:
74
            return ['welco/qualification.html']
75
        else:
76
            return ['welco/qualification_no_validation.html']
70
    template_name = 'welco/qualification_no_validation.html'
77 71

  
78 72
    def get_context_data(self, **kwargs):
79 73
        context = super(Qualification, self).get_context_data(**kwargs)
......
86 80
            context['associations'] = Association.objects.filter(
87 81
                    source_type=ContentType.objects.get(id=self.request.GET['source_type']),
88 82
                    source_pk=self.request.GET['source_pk']).order_by('id')
89
        validation_steps = settings.VALIDATION_STEPS.get(source_type.model.lower()) or []
90
        context['validation_steps'] = [
91
                {'id': x, 'label': settings.VALIDATION_STEP_LABELS[x]} for x in validation_steps]
92 83
        return context
93 84

  
94 85
    def post(self, request, *args, **kwargs):
......
157 148
home_counter = login_required(HomeCounter.as_view())
158 149

  
159 150

  
160

  
161
@csrf_exempt
162
def qualification_done(request):
163
    source_class = ContentType.objects.get(
164
            id=request.POST['source_type']).model_class()
165
    source_object = source_class.objects.get(id=request.POST['source_pk'])
166
    validation_steps = settings.VALIDATION_STEPS.get(source_class.__name__.lower())
167
    if request.GET.get('step'):
168
        source_object.status = validation_steps[validation_steps.index(request.GET.get('step'))]
169
    else:
170
        if source_object.status:
171
            source_object.status = validation_steps[
172
                    validation_steps.index(source_object.status)+1]
173
        else:
174
            source_object.status = validation_steps[0]
175
    if source_object.status == validation_steps[-1]:
176
        for association in Association.objects.filter(
177
                source_type=request.POST['source_type'],
178
                source_pk=request.POST['source_pk']):
179
            try:
180
                association.push(request)
181
            except Exception, e:
182
                response = HttpResponse(content_type='application/json')
183
                json.dump({'err': '1', 'msg': str(e)}, response, indent=2)
184
                return response
185
    source_object.save()
186
    response = HttpResponse(content_type='application/json')
187
    json.dump({'result': 'ok'}, response, indent=2)
188
    return response
189

  
190

  
191 151
@login_required
192 152
def wcs_summary(request, *args, **kwargs):
193 153
    source_class = ContentType.objects.get(id=kwargs.get('source_type')).model_class()
194
-