trivial: apply isort & pyupgrade

This commit is contained in:
Frédéric Péters 2021-07-13 11:41:18 +02:00
parent 36c0e69cb1
commit 250ef2e74a
63 changed files with 159 additions and 254 deletions

View File

@ -1,15 +1,14 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import sys
from setuptools.command.install_lib import install_lib as _install_lib
from distutils.cmd import Command
from distutils.command.build import build as _build
from distutils.command.sdist import sdist
from distutils.cmd import Command
from setuptools import setup, find_packages
from setuptools import find_packages, setup
from setuptools.command.install_lib import install_lib as _install_lib
class eo_sdist(sdist):
@ -29,7 +28,7 @@ def get_version():
tag exists, take 0.0- and add the length of the commit log.
"""
if os.path.exists('VERSION'):
with open('VERSION', 'r') as v:
with open('VERSION') as v:
return v.read()
if os.path.exists('.git'):
p = subprocess.Popen(

View File

@ -14,8 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import django_webtest
import pytest
@pytest.fixture

View File

@ -14,11 +14,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from unittest import mock
import httmock
import mock
import pytest
import requests
from django.contrib.contenttypes.models import ContentType
from django.core.files.base import ContentFile

View File

@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from django.core.management import call_command
from django.core.management.base import CommandError

View File

@ -14,14 +14,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import httmock
import json
import requests
from webtest import Upload
import httmock
import requests
from django.contrib.contenttypes.models import ContentType
from django.core.files.base import ContentFile
from django.utils.encoding import force_text
from webtest import Upload
from welco.sources.mail.models import Mail

View File

@ -14,10 +14,10 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import httmock
import mock
import pytest
from unittest import mock
import httmock
import pytest
from django.contrib.contenttypes.models import ContentType
from django.core.files.base import ContentFile
@ -201,7 +201,7 @@ def test_menu_json_view(app, user, mail_group, phone_group, counter_group, kb_gr
app.set_user(user.username)
resp = app.get('/menu.json', status=200)
assert resp.content_type == 'application/json'
assert sorted([x['label'] for x in resp.json]) == ['Call Center', 'Counter', 'Knowledge Base', 'Mails']
assert sorted(x['label'] for x in resp.json) == ['Call Center', 'Counter', 'Knowledge Base', 'Mails']
resp = app.get('/menu.json?callback=foo', status=200)
assert resp.content_type == 'application/javascript'

View File

@ -14,9 +14,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import mock
import pytest
from unittest import mock
import pytest
from django.test import override_settings
from welco.forms import QualificationForm

View File

@ -17,14 +17,12 @@
import json
import pytest
from django.contrib.auth.models import User
from django.utils.encoding import force_text
from httmock import urlmatch, HTTMock
from httmock import HTTMock, urlmatch
class BaseMock(object):
class BaseMock:
def __init__(self, netloc):
self.netloc = netloc
self.clear()
@ -177,8 +175,10 @@ PDF_MOCK = b'%PDF-1.4 ...'
def test_feed(settings, app, maarch, wcs, user):
import base64
from django.core.management import call_command
from django.contrib.contenttypes.models import ContentType
from django.core.management import call_command
from welco.sources.mail.models import Mail
app.set_user(user.username)

View File

@ -18,9 +18,8 @@ import json
import re
import pytest
from django.urls import reverse
from django.test import override_settings
from django.urls import reverse
from django.utils import six
from django.utils.encoding import force_text
from django.utils.timezone import now, timedelta
@ -166,10 +165,10 @@ def test_current_calls(user, client):
assert response['content-type'] == 'application/json'
payload = response.json()
assert isinstance(payload, dict)
assert set(payload.keys()) == set(['err', 'data'])
assert set(payload.keys()) == {'err', 'data'}
assert payload['err'] == 0
data = payload['data']
assert set(data.keys()) == set(['calls', 'lines', 'all-lines'])
assert set(data.keys()) == {'calls', 'lines', 'all-lines'}
assert isinstance(data['calls'], list)
assert isinstance(data['lines'], list)
assert isinstance(data['all-lines'], list)
@ -177,14 +176,14 @@ def test_current_calls(user, client):
assert len(data['lines']) == 5
assert len(data['all-lines']) == 10
for call in data['calls']:
assert set(call.keys()) <= set(['caller', 'callee', 'start', 'data'])
assert isinstance(call['caller'], six.string_types)
assert isinstance(call['callee'], six.string_types)
assert isinstance(call['start'], six.string_types)
assert set(call.keys()) <= {'caller', 'callee', 'start', 'data'}
assert isinstance(call['caller'], str)
assert isinstance(call['callee'], str)
assert isinstance(call['start'], str)
if 'data' in call:
assert isinstance(call['data'], dict)
assert len([call for call in data['lines'] if isinstance(call, six.string_types)]) == 5
assert len([call for call in data['all-lines'] if isinstance(call, six.string_types)]) == 10
assert len([call for call in data['lines'] if isinstance(call, str)]) == 5
assert len([call for call in data['all-lines'] if isinstance(call, str)]) == 10
# unregister user to all remaining lines
for number in range(0, 5):
@ -194,9 +193,9 @@ def test_current_calls(user, client):
assert response['content-type'] == 'application/json'
payload = response.json()
assert isinstance(payload, dict)
assert set(payload.keys()) == set(['err', 'data'])
assert set(payload.keys()) == {'err', 'data'}
assert payload['err'] == 0
assert set(payload['data'].keys()) == set(['calls', 'lines', 'all-lines'])
assert set(payload['data'].keys()) == {'calls', 'lines', 'all-lines'}
assert len(payload['data']['calls']) == 0
assert len(payload['data']['lines']) == 0
assert len(payload['data']['all-lines']) == 10

View File

@ -15,8 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django import forms
from django.utils.translation import ugettext_lazy as _, pgettext_lazy
from django.utils.translation import pgettext_lazy
from django.utils.translation import ugettext_lazy as _
DEFAULT_TITLE_CHOICES = (
('', ''),

View File

@ -17,9 +17,9 @@
import json
import logging
import random
import requests
import time
import requests
from django import template
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
@ -27,14 +27,14 @@ from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView, FormView
from django.views.generic import FormView, TemplateView
from welco.utils import get_wcs_data, sign_url
from .forms import ContactAddForm
class HomeZone(object):
class HomeZone:
def __init__(self, request):
self.request = request
@ -47,7 +47,7 @@ class ContactsZone(TemplateView):
template_name = 'contacts/zone.html'
def get_context_data(self, **kwargs):
context = super(ContactsZone, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['source_pk'] = self.request.GET.get('source_pk')
if 'source_pk' in self.request.GET:
source_class = ContentType.objects.get(id=self.request.GET['source_type']).model_class()
@ -68,7 +68,7 @@ zone = csrf_exempt(ContactsZone.as_view())
def search_json(request):
user_groups = set([x.name for x in request.user.groups.all()])
user_groups = {x.name for x in request.user.groups.all()}
for channel in settings.CHANNEL_ROLES:
channel_groups = set(settings.CHANNEL_ROLES[channel])
if user_groups.intersection(channel_groups):
@ -104,7 +104,7 @@ class ContactDetailFragmentView(TemplateView):
template_name = 'contacts/contact_detail_fragment.html'
def get_context_data(self, **kwargs):
context = super(ContactDetailFragmentView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
user_id = self.kwargs.get('slug').split('-')[-1]
user_details = get_wcs_data('api/users/%s/' % user_id)

View File

@ -24,7 +24,7 @@ class QualificationForm(forms.Form):
formdef_reference = forms.CharField(label=_('Associated Form'))
def __init__(self, user, *args, **kwargs):
super(QualificationForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
params = {'backoffice-submission': 'on'}
if hasattr(user, 'saml_identifiers') and user.saml_identifiers.exists():
params['NameID'] = user.saml_identifiers.first().name_id

View File

@ -38,4 +38,4 @@ class PageForm(forms.ModelForm):
i += 1
slug = '%s-%s' % (base_slug, i)
self.instance.slug = slug
return super(PageForm, self).save(commit=commit)
return super().save(commit=commit)

View File

@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import ckeditor.fields
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import taggit.managers
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -14,11 +14,10 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.urls import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _
from ckeditor.fields import RichTextField
from django.db import models
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from taggit.managers import TaggableManager

View File

@ -17,7 +17,6 @@
import html
from django.utils.html import strip_tags
from haystack import indexes
from .models import Page

View File

@ -20,20 +20,19 @@ from django import template
from django.conf import settings
from django.contrib.auth.decorators import login_required, user_passes_test
from django.core.exceptions import PermissionDenied
from django.urls import reverse_lazy
from django.db.models import Count
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.urls import reverse_lazy
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import DetailView, CreateView, UpdateView, ListView, DeleteView, TemplateView
from django.views.generic import CreateView, DeleteView, DetailView, ListView, TemplateView, UpdateView
from haystack.forms import SearchForm
from haystack.generic_views import SearchView
from haystack.query import SearchQuerySet
from taggit.models import Tag
from .models import Page
from .forms import PageForm
from .models import Page
def check_user_perms(user, access=False):
@ -42,7 +41,7 @@ def check_user_perms(user, access=False):
allowed_roles.extend(settings.KB_ACCESS_ROLES)
if settings.KB_ROLE:
allowed_roles.append(settings.KB_ROLE) # legacy
user_groups = set([x.name for x in user.groups.all()])
user_groups = {x.name for x in user.groups.all()}
return user_groups.intersection(allowed_roles)
@ -56,10 +55,10 @@ class PageListView(ListView):
def dispatch(self, request, *args, **kwargs):
check_request_perms(request, access=True)
return super(PageListView, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(PageListView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['form'] = SearchForm()
context['can_manage'] = check_user_perms(self.request.user)
return context
@ -74,7 +73,7 @@ class PageAddView(CreateView):
def dispatch(self, request, *args, **kwargs):
check_request_perms(request)
return super(PageAddView, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
page_add = login_required(PageAddView.as_view())
@ -86,7 +85,7 @@ class PageEditView(UpdateView):
def dispatch(self, request, *args, **kwargs):
check_request_perms(request)
return super(PageEditView, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
page_edit = login_required(PageEditView.as_view())
@ -97,10 +96,10 @@ class PageDetailView(DetailView):
def dispatch(self, request, *args, **kwargs):
check_request_perms(request, access=True)
return super(PageDetailView, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(PageDetailView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['can_manage'] = check_user_perms(self.request.user)
return context
@ -122,7 +121,7 @@ class PageDeleteView(DeleteView):
def dispatch(self, request, *args, **kwargs):
check_request_perms(request)
return super(PageDeleteView, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
page_delete = login_required(PageDeleteView.as_view())
@ -134,7 +133,7 @@ class PageSearchView(SearchView):
def dispatch(self, request, *args, **kwargs):
check_request_perms(request, access=True)
return super(PageSearchView, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
page_search = login_required(PageSearchView.as_view())
@ -144,7 +143,7 @@ class KbZone(TemplateView):
template_name = 'kb/zone.html'
def get_context_data(self, **kwargs):
context = super(KbZone, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['source_pk'] = self.request.GET.get('source_pk')
context['form'] = SearchForm()
context['tags'] = (
@ -190,7 +189,7 @@ def page_search_json(request):
return response
class HomeZone(object):
class HomeZone:
def __init__(self, request):
self.request = request

View File

@ -14,16 +14,15 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.urls import reverse
import ckeditor.widgets
from django.forms.utils import flatatt
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.encoding import force_text
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from django.utils.translation import get_language
import ckeditor.widgets
def ckeditor_render(self, name, value, attrs=None, renderer=None):
if value is None:

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -14,13 +14,13 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.urls import reverse
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from welco.utils import get_wcs_formdef_details, push_wcs_formdata, get_wcs_services
from welco.utils import get_wcs_formdef_details, get_wcs_services, push_wcs_formdata
class Association(models.Model):

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
"""
Django settings for welco project.
@ -11,6 +9,7 @@ https://docs.djangoproject.com/en/1.7/ref/settings/
"""
import os
from django.conf import global_settings
from django.utils.translation import ugettext_lazy as _

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -18,17 +18,17 @@ import json
from django import template
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.contenttypes.models import ContentType
from django.http import HttpResponse
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.views.generic import TemplateView
from .models import CounterPresence
class Home(object):
class Home:
source_key = 'counter'
def __init__(self, request, **kwargs):
@ -46,7 +46,7 @@ class CounterZone(TemplateView):
template_name = 'welco/counter_home.html'
def get_context_data(self, **kwargs):
context = super(CounterZone, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['source_type'] = ContentType.objects.get_for_model(CounterPresence)
new_source = CounterPresence()
new_source.save()

View File

@ -26,9 +26,10 @@ class AppConfig(django.apps.AppConfig):
return urls.urlpatterns
def ready(self):
from welco.qualif.models import Association
from django.db.models import signals
from welco.qualif.models import Association
signals.post_save.connect(self.association_post_save, sender=Association)
def association_post_save(self, sender, instance, **kwargs):

View File

@ -15,8 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
class MailQualificationForm(forms.Form):

View File

@ -16,11 +16,10 @@
import base64
import requests
from dateutil.parser import parse as parse_datetime
from django.utils import six
from django.utils.six.moves.urllib import parse as urlparse
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
@ -29,7 +28,7 @@ class MaarchError(Exception):
pass
class MaarchCourrier(object):
class MaarchCourrier:
url = None
username = None
password = None
@ -44,7 +43,7 @@ class MaarchCourrier(object):
def __repr__(self):
return '<MaarchCourrier url:%s>' % self.url
class Courrier(object):
class Courrier:
content = None
format = None
status = None
@ -89,7 +88,7 @@ class MaarchCourrier(object):
data = {key: self.__dict__[key] for key in self.__dict__ if key not in excluded_keys}
if data:
for key, value in data.items():
if isinstance(value, six.string_types):
if isinstance(value, str):
d.append({'column': key, 'value': value, 'type': 'string'})
elif isinstance(value, int):
d.append({'column': key, 'value': str(value), 'type': 'int'})

View File

@ -14,8 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from optparse import make_option
import os
from optparse import make_option
from django.core.files import File
from django.core.management.base import BaseCommand, CommandError

View File

@ -14,12 +14,12 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from optparse import make_option
import os
from optparse import make_option
from django.conf import settings
from django.core.files.base import ContentFile
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.db import transaction
from ...models import Mail

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -15,16 +15,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
import requests
import subprocess
import requests
from django.conf import settings
from django.contrib.contenttypes.fields import GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from welco.qualif.models import Association

View File

@ -16,7 +16,7 @@
from django.conf.urls import url
from .views import viewer, feeder, qualification_save, edit_note, note, reject, mail_count, mail_response
from .views import edit_note, feeder, mail_count, mail_response, note, qualification_save, reject, viewer
urlpatterns = [
url('viewer/$', viewer, name='mail-viewer'),

View File

@ -32,7 +32,7 @@ class WelcoMaarchCourrier(MaarchCourrier):
grc_response_status,
batch_size=10,
):
super(WelcoMaarchCourrier, self).__init__(url, username, password)
super().__init__(url, username, password)
self.grc_status = grc_status
self.grc_received_status = grc_received_status
self.grc_send_status = grc_send_status

View File

@ -18,27 +18,25 @@ import json
import logging
from django import template
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.contenttypes.models import ContentType
from django.contrib import messages
from django.urls import reverse
from django.template import RequestContext
from django.db.transaction import atomic
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView
from django.db.transaction import atomic
from rest_framework import authentication, serializers, permissions, status
from rest_framework import authentication, permissions, serializers, status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from welco.utils import response_for_json
from .models import Mail
from .forms import MailQualificationForm
from .utils import get_maarch, MaarchError
from .models import Mail
from .utils import MaarchError, get_maarch
logger = logging.getLogger(__name__)
@ -64,7 +62,7 @@ class Feeder(TemplateView):
feeder = login_required(csrf_exempt(Feeder.as_view()))
class Home(object):
class Home:
source_key = 'mail'
display_filter = True
allow_reject = True
@ -112,7 +110,7 @@ class EditNote(TemplateView):
template_name = 'welco/mail_edit_note.html'
def get_context_data(self, **kwargs):
context = super(EditNote, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['mail'] = Mail.objects.get(id=self.request.GET['mail'])
return context

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.utils.timezone import utc
from django.utils.timezone import now
import datetime
from django.conf import settings
from django.db import migrations, models
from django.utils.timezone import now, utc
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -18,10 +18,10 @@ import logging
from django.conf import settings
from django.contrib.contenttypes.fields import GenericRelation
from django.urls import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse
from django.utils.timezone import now, timedelta
from django.utils.translation import ugettext_lazy as _
from welco.qualif.models import Association

View File

@ -19,20 +19,20 @@ import logging
from django import template
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseBadRequest, HttpResponse
from django.contrib.contenttypes.models import ContentType
from django.http import HttpResponse, HttpResponseBadRequest
from django.template import RequestContext
from django.utils import six
from django.utils.encoding import force_text
from django.utils.timezone import now
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView
from .models import PhoneCall, PhoneLine
class Home(object):
class Home:
source_key = 'phone'
def __init__(self, request, **kwargs):
@ -60,7 +60,7 @@ class PhoneZone(TemplateView):
username = username[0].split('@', 1)[0][:80] # remove realm
if username:
PhoneLine.take(callee=username, user=self.request.user)
context = super(PhoneZone, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['source_type'] = ContentType.objects.get_for_model(PhoneCall)
context['phonelines'] = PhoneLine.objects.filter(users__id=self.request.user.id)
context['phonecalls'] = PhoneCall.get_current_calls(self.request.user)
@ -87,15 +87,18 @@ def call_event(request):
try:
payload = json.loads(force_text(request.body))
assert isinstance(payload, dict), 'payload is not a JSON object'
assert set(payload.keys()) <= set(
['event', 'caller', 'callee', 'data']
), 'payload keys must be "event", "caller", "callee" and optionnaly "data"'
assert set(['event', 'caller', 'callee']) <= set(
assert set(payload.keys()) <= {
'event',
'caller',
'callee',
'data',
}, 'payload keys must be "event", "caller", "callee" and optionnaly "data"'
assert {'event', 'caller', 'callee'} <= set(
payload.keys()
), 'payload keys must be "event", "caller", "callee" and optionnaly "data"'
assert payload['event'] in ('start', 'stop'), 'event must be "start" or "stop"'
assert isinstance(payload['caller'], six.string_types), 'caller must be a string'
assert isinstance(payload['callee'], six.string_types), 'callee must be a string'
assert isinstance(payload['caller'], str), 'caller must be a string'
assert isinstance(payload['callee'], str), 'callee must be a string'
if 'data' in payload:
assert isinstance(payload['data'], dict), 'data must be a JSON object'
except (TypeError, ValueError, AssertionError) as e:
@ -208,7 +211,7 @@ def take_line(request):
json.dumps({'err': 1, 'msg': force_text(e)}), content_type='application/json'
)
PhoneLine.take(payload['callee'], request.user)
logger.info(u'user %s took line %s', request.user, payload['callee'])
logger.info('user %s took line %s', request.user, payload['callee'])
return HttpResponse(json.dumps({'err': 0}), content_type='application/json')
@ -229,5 +232,5 @@ def release_line(request):
json.dumps({'err': 1, 'msg': force_text(e)}), content_type='application/json'
)
PhoneLine.release(payload['callee'], request.user)
logger.info(u'user %s released line %s', request.user, payload['callee'])
logger.info('user %s released line %s', request.user, payload['callee'])
return HttpResponse(json.dumps({'err': 0}), content_type='application/json')

View File

@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from ckeditor import views as ckeditor_views
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
@ -21,16 +22,13 @@ from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.decorators.cache import never_cache
from ckeditor import views as ckeditor_views
import welco.contacts.views
import welco.kb.views
import welco.views
from . import apps
from .kb.views import kb_manager_required
import welco.views
import welco.contacts.views
import welco.kb.views
urlpatterns = [
url(r'^$', welco.views.home, name='home'),
url(r'^mail/$', welco.views.home_mail, name='home-mail'),

View File

@ -16,18 +16,18 @@
import base64
import datetime
import hmac
import hashlib
import hmac
import json
import random
import re
import requests
import requests
from django.conf import settings
from django.core.cache import cache
from django.http import HttpResponse, HttpResponseBadRequest
from django.utils.encoding import smart_bytes
from django.utils.http import urlencode, quote
from django.utils.http import quote, urlencode
from django.utils.six.moves.urllib import parse as urlparse

View File

@ -16,17 +16,17 @@
import json
from django import template
from django.conf import settings
from django.contrib.auth import logout as auth_logout
from django.contrib.auth import views as auth_views
from django.contrib.auth.decorators import login_required
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied
from django.urls import reverse
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import resolve_url
from django import template
from django.template import RequestContext
from django.urls import reverse
from django.utils.encoding import force_text
from django.utils.http import quote
from django.utils.translation import ugettext_lazy as _
@ -38,13 +38,14 @@ if 'mellon' in settings.INSTALLED_APPS:
else:
get_idps = lambda: []
from .sources.mail.views import Home as MailHome
from .sources.phone.views import Home as PhoneHome
from .sources.counter.views import Home as CounterHome
from .qualif.models import Association
from .kb.views import HomeZone as KbHomeZone, check_user_perms as check_kb_user_perms
from .contacts.views import HomeZone as ContactsHomeZone
from .forms import QualificationForm
from .kb.views import HomeZone as KbHomeZone
from .kb.views import check_user_perms as check_kb_user_perms
from .qualif.models import Association
from .sources.counter.views import Home as CounterHome
from .sources.mail.views import Home as MailHome
from .sources.phone.views import Home as PhoneHome
class LoginView(auth_views.LoginView):
@ -59,7 +60,7 @@ class LoginView(auth_views.LoginView):
except KeyError:
return HttpResponseBadRequest('invalid value for "next" parameter')
return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' + quoted_next_url)
return super(LoginView, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
login = LoginView.as_view()
@ -80,7 +81,7 @@ class Qualification(TemplateView):
template_name = 'welco/qualification_no_validation.html'
def get_context_data(self, **kwargs):
context = super(Qualification, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['form'] = QualificationForm(self.request.user)
context['source_type'] = self.request.GET['source_type']
source_type = ContentType.objects.get(id=self.request.GET['source_type'])
@ -112,21 +113,21 @@ class ChannelHome(TemplateView):
source_klass = MailHome
def check_user_ok(self):
user_groups = set([x.name for x in self.request.user.groups.all()])
user_groups = {x.name for x in self.request.user.groups.all()}
channel_groups = set(settings.CHANNEL_ROLES[self.source_klass.source_key])
return user_groups.intersection(channel_groups)
def get_context_data(self, **kwargs):
if not self.check_user_ok():
raise PermissionDenied()
context = super(ChannelHome, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['panels'] = [{'key': x, 'zone_url': x + '-zone'} for x in settings.SCREEN_PANELS]
context['source'] = self.source_klass(self.request, **kwargs)
context['kb'] = KbHomeZone(self.request)
context['contacts'] = ContactsHomeZone(self.request)
context['channels'] = []
user_groups = set([x.name for x in self.request.user.groups.all()])
user_groups = {x.name for x in self.request.user.groups.all()}
for channel in settings.CHANNEL_ROLES:
channel_groups = set(settings.CHANNEL_ROLES[channel])
if user_groups.intersection(channel_groups):
@ -136,7 +137,7 @@ class ChannelHome(TemplateView):
@login_required
def home(request):
user_groups = set([x.name for x in request.user.groups.all()])
user_groups = {x.name for x in request.user.groups.all()}
for channel in settings.CHANNEL_ROLES:
channel_groups = set(settings.CHANNEL_ROLES[channel])
if user_groups.intersection(channel_groups):
@ -209,7 +210,7 @@ def create_formdata(request, *args, **kwargs):
@login_required
def menu_json(request):
response = HttpResponse(content_type='application/json')
user_groups = set([x.name for x in request.user.groups.all()])
user_groups = {x.name for x in request.user.groups.all()}
menu = []
labels = {
'mail': _('Mails'),