general: add counter endpoints, to be used by agent portal (#8689)
This commit is contained in:
parent
8eddbf88ab
commit
35bbbfcc17
|
@ -17,7 +17,8 @@
|
|||
from django.conf.urls import patterns, url
|
||||
|
||||
from .views import (dgs, dga, copies, copies_ajax, table_info, table_avis,
|
||||
table_mandatory_avis, table_waiting)
|
||||
table_mandatory_avis, table_waiting, count_dgs, count_dga, count_info,
|
||||
count_avis, count_mandatory_avis)
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url('^dgs/$', dgs, name='alfortville-dgs'),
|
||||
|
@ -28,4 +29,10 @@ urlpatterns = patterns('',
|
|||
url('^table/avis/$', table_avis, name='alfortville-table-avis'),
|
||||
url('^table/avis-requis/$', table_mandatory_avis, name='alfortville-table-mandatory-avis'),
|
||||
url('^table/en-attente-de-validation/$', table_waiting, name='alfortville-table-waiting'),
|
||||
|
||||
url(r'^ajax/count/dgs/$', count_dgs, name='alfortville-count-dgs'),
|
||||
url(r'^ajax/count/dga/$', count_dga, name='alfortville-count-dga'),
|
||||
url(r'^ajax/count/info/$', count_info, name='alfortville-count-info'),
|
||||
url(r'^ajax/count/avis/$', count_avis, name='alfortville-count-avis'),
|
||||
url(r'^ajax/count/avis-requis/$', count_mandatory_avis, name='alfortville-count-avis-requis'),
|
||||
)
|
||||
|
|
|
@ -29,7 +29,7 @@ from .models import Inbox
|
|||
from welco.sources.mail.models import Mail
|
||||
from welco.sources.mail.views import Home as MailHome
|
||||
from welco.qualif.models import Association
|
||||
from welco.utils import get_wcs_data, get_wcs_options
|
||||
from welco.utils import get_wcs_data, get_wcs_options, response_for_json
|
||||
from welco.views import Home as HomeScreen
|
||||
|
||||
|
||||
|
@ -221,3 +221,35 @@ class TableWaiting(TemplateView):
|
|||
return context
|
||||
|
||||
table_waiting = login_required(TableWaiting.as_view())
|
||||
|
||||
|
||||
@login_required
|
||||
def count_dgs(request, *args, **kwargs):
|
||||
count = DgsMailHome(request).get_queryset().count()
|
||||
return response_for_json(request, {'count': count})
|
||||
|
||||
@login_required
|
||||
def count_dga(request, *args, **kwargs):
|
||||
count = DgaMailHome(request).get_queryset().count()
|
||||
return response_for_json(request, {'count': count})
|
||||
|
||||
@login_required
|
||||
def count_info(request, *args, **kwargs):
|
||||
table = TableInfo()
|
||||
table.request = request
|
||||
count = table.get_context_data().get('objects').count()
|
||||
return response_for_json(request, {'count': count})
|
||||
|
||||
@login_required
|
||||
def count_avis(request, *args, **kwargs):
|
||||
table = TableAvis()
|
||||
table.request = request
|
||||
count = table.get_context_data().get('objects').count()
|
||||
return response_for_json(request, {'count': count})
|
||||
|
||||
@login_required
|
||||
def count_mandatory_avis(request, *args, **kwargs):
|
||||
table = TableMandatoryAvis()
|
||||
table.request = request
|
||||
count = table.get_context_data().get('objects').count()
|
||||
return response_for_json(request, {'count': count})
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
from .views import viewer, feeder, qualification_save, edit_note, note, reject
|
||||
from .views import (viewer, feeder, qualification_save, edit_note, note,
|
||||
reject, mail_count)
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url('viewer/$', viewer, name='mail-viewer'),
|
||||
|
@ -25,4 +26,5 @@ urlpatterns = patterns('',
|
|||
url(r'^ajax/qualification-mail-save$', qualification_save, name='qualif-mail-save'),
|
||||
url(r'^ajax/mail/edit-note/$', edit_note, name='mail-edit-note'),
|
||||
url(r'^ajax/mail/note/(?P<pk>\w+)$', note, name='mail-note'),
|
||||
url(r'^ajax/count/mail/$', mail_count, name='mail-count'),
|
||||
)
|
||||
|
|
|
@ -29,6 +29,8 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from welco.utils import response_for_json
|
||||
|
||||
from .models import Mail
|
||||
from .forms import MailQualificationForm
|
||||
|
||||
|
@ -121,3 +123,9 @@ def note(request, *args, **kwargs):
|
|||
def reject(request, *args, **kwargs):
|
||||
Mail.objects.filter(id=request.POST['source_pk']).delete()
|
||||
return HttpResponse()
|
||||
|
||||
|
||||
@login_required
|
||||
def mail_count(request, *args, **kwargs):
|
||||
count = Mail.objects.exclude(status__startswith='done-').count()
|
||||
return response_for_json(request, {'count': count})
|
||||
|
|
|
@ -20,12 +20,14 @@ import hmac
|
|||
import hashlib
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import requests
|
||||
import urllib
|
||||
import urlparse
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.http import HttpResponse, HttpResponseBadRequest
|
||||
|
||||
def sign_url(url, key, algo='sha256', timestamp=None, nonce=None):
|
||||
parsed = urlparse.urlparse(url)
|
||||
|
@ -158,3 +160,18 @@ def get_wcs_data(endpoint, params=None):
|
|||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def response_for_json(request, data):
|
||||
json_str = json.dumps(data)
|
||||
for variable in ('jsonpCallback', 'callback'):
|
||||
if variable in request.GET:
|
||||
identifier = request.GET[variable]
|
||||
if not re.match(r'^[$A-Za-z_][0-9A-Za-z_$]*$', identifier):
|
||||
return HttpResponseBadRequest('invalid JSONP callback name')
|
||||
json_str = '%s(%s);' % (identifier, json_str)
|
||||
response = HttpResponse(content_type='application/javascript')
|
||||
break
|
||||
else:
|
||||
response = HttpResponse(content_type='application/json')
|
||||
response.write(json_str)
|
||||
return response
|
||||
|
|
Loading…
Reference in New Issue