From 32137b6523e8af8211758e269346f7c8379720fd Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 16 Aug 2014 09:25:18 +0200 Subject: [PATCH] Use python3 python3.3 and python3.4 are supported --- .travis.yml | 11 +++-- CHANGELOG | 5 ++ README.rst | 22 +++------ docs/conf.py | 1 - docs/extensions/autoimage.py | 1 - extras/benchmark/bench.py | 2 - extras/openslides_gui/gui.py | 2 - extras/scripts/export_list_of_speakers.py | 2 - extras/scripts/test_data.py | 2 - extras/win32-portable/prepare_portable.py | 1 - fabfile.py | 1 - manage.py | 1 - openslides/__init__.py | 7 ++- openslides/__main__.py | 5 +- openslides/account/__init__.py | 2 - openslides/account/widgets.py | 2 - openslides/agenda/__init__.py | 2 - openslides/agenda/csv_import.py | 7 ++- openslides/agenda/forms.py | 4 +- openslides/agenda/main_menu.py | 2 - openslides/agenda/models.py | 8 ++-- openslides/agenda/personal_info.py | 2 - openslides/agenda/search_indexes.py | 2 - openslides/agenda/signals.py | 2 - openslides/agenda/slides.py | 2 - openslides/agenda/urls.py | 2 - openslides/agenda/views.py | 5 +- openslides/agenda/widgets.py | 2 - openslides/assignment/__init__.py | 2 - openslides/assignment/forms.py | 2 - openslides/assignment/main_menu.py | 2 - openslides/assignment/models.py | 14 +++--- openslides/assignment/personal_info.py | 2 - openslides/assignment/search_indexes.py | 2 - openslides/assignment/signals.py | 2 - openslides/assignment/slides.py | 2 - openslides/assignment/template.py | 2 - openslides/assignment/urls.py | 2 - openslides/assignment/views.py | 20 ++++---- openslides/assignment/widgets.py | 2 - openslides/config/__init__.py | 2 - openslides/config/api.py | 2 - openslides/config/exceptions.py | 2 - openslides/config/main_menu.py | 2 - openslides/config/middleware.py | 2 - openslides/config/models.py | 2 - openslides/config/signals.py | 2 - openslides/config/urls.py | 2 - openslides/config/views.py | 2 - openslides/core/__init__.py | 2 - openslides/core/chatbox.py | 2 - openslides/core/forms.py | 2 - openslides/core/main_menu.py | 2 - openslides/core/management/commands/syncdb.py | 2 - openslides/core/models.py | 2 +- openslides/core/signals.py | 2 - openslides/core/slides.py | 2 - openslides/core/templates/core/search.html | 8 ++-- openslides/core/templatetags/tags.py | 2 - openslides/core/urls.py | 2 - openslides/core/views.py | 2 - openslides/core/widgets.py | 2 - openslides/global_settings.py | 7 +-- openslides/mediafile/__init__.py | 2 - openslides/mediafile/forms.py | 2 - openslides/mediafile/main_menu.py | 2 - openslides/mediafile/models.py | 4 +- openslides/mediafile/search_indexes.py | 2 - openslides/mediafile/slides.py | 1 - openslides/mediafile/template.py | 2 - openslides/mediafile/urls.py | 2 - openslides/mediafile/views.py | 2 - openslides/mediafile/widgets.py | 2 - openslides/motion/__init__.py | 2 - openslides/motion/csv_import.py | 9 ++-- openslides/motion/exceptions.py | 2 - openslides/motion/forms.py | 2 - openslides/motion/main_menu.py | 2 - openslides/motion/models.py | 28 +++++------ openslides/motion/pdf.py | 16 +++---- openslides/motion/personal_info.py | 2 - openslides/motion/search_indexes.py | 2 - openslides/motion/signals.py | 2 - openslides/motion/slides.py | 2 - openslides/motion/urls.py | 2 - openslides/motion/views.py | 4 +- openslides/motion/widgets.py | 2 - openslides/participant/__init__.py | 2 - openslides/participant/api.py | 2 - openslides/participant/csv_import.py | 8 ++-- openslides/participant/forms.py | 2 - openslides/participant/main_menu.py | 2 - openslides/participant/middleware.py | 2 - openslides/participant/models.py | 8 ++-- openslides/participant/pdf.py | 6 +-- openslides/participant/search_indexes.py | 2 - openslides/participant/signals.py | 2 - openslides/participant/slides.py | 2 - openslides/participant/urls.py | 2 - openslides/participant/views.py | 2 - openslides/participant/widgets.py | 2 - openslides/poll/forms.py | 2 - openslides/poll/models.py | 4 +- openslides/poll/views.py | 2 - openslides/projector/__init__.py | 2 - openslides/projector/api.py | 4 +- openslides/projector/exceptions.py | 3 -- openslides/projector/models.py | 2 - openslides/projector/projector.py | 2 - openslides/projector/signals.py | 1 - openslides/projector/urls.py | 2 - openslides/projector/views.py | 2 - openslides/projector/widgets.py | 2 - openslides/urls.py | 2 - openslides/utils/auth/AnonymousAuth.py | 2 - openslides/utils/auth/__init__.py | 4 +- openslides/utils/csv_ext.py | 2 - openslides/utils/dispatch.py | 6 +-- openslides/utils/exceptions.py | 3 -- openslides/utils/forms.py | 2 - openslides/utils/main.py | 47 ++++++------------- openslides/utils/main_menu.py | 13 ++--- openslides/utils/models.py | 2 - openslides/utils/pdf.py | 2 - openslides/utils/person/__init__.py | 2 - openslides/utils/person/api.py | 6 +-- openslides/utils/person/forms.py | 2 - openslides/utils/person/models.py | 9 ++-- openslides/utils/person/signals.py | 2 - openslides/utils/personal_info.py | 7 +-- openslides/utils/plugins.py | 2 - openslides/utils/settings.py.tpl | 4 +- openslides/utils/signals.py | 2 - openslides/utils/test.py | 2 - openslides/utils/tornado_webserver.py | 9 ++-- openslides/utils/utils.py | 2 - openslides/utils/views.py | 14 +++--- openslides/utils/widgets.py | 15 +++--- requirements.txt | 2 - requirements_production.txt | 20 ++++---- setup.py | 3 +- tests/account/test_widgets.py | 2 - tests/agenda/models.py | 2 - tests/agenda/test_list_of_speakers.py | 3 +- tests/agenda/tests.py | 13 +++-- tests/assignment/test_models.py | 2 - tests/assignment/test_pdf.py | 1 - tests/assignment/test_views.py | 24 +++++++++- tests/config/test_config.py | 38 +++++++-------- tests/core/test_template_tags_filters.py | 2 - tests/core/test_views.py | 3 +- tests/forms/test_clean_html.py | 2 - tests/mediafile/tests.py | 24 +++++----- tests/motion/test_csv_import.py | 17 +++---- tests/motion/test_models.py | 2 - tests/motion/test_pdf.py | 1 - tests/motion/test_views.py | 2 - tests/participant/test_csv.py | 23 +++++++++ tests/participant/test_models.py | 12 ++--- tests/participant/test_umlaut_user.py | 2 - tests/participant/test_utils.py | 2 - tests/participant/test_views.py | 7 +-- tests/person_api/__init__.py | 2 - tests/person_api/tests.py | 10 ++-- tests/plugin_api/test_plugin_api.py | 8 ++-- tests/plugin_api/test_plugin_one/__init__.py | 2 - tests/plugin_api/urls.py | 7 --- tests/projector/test_api.py | 4 +- tests/projector/test_overlays.py | 6 +-- tests/projector/test_signals.py | 4 +- tests/projector/test_views.py | 4 +- tests/settings.py | 5 +- tests/test_init.py | 36 +++++++------- tests/utils/test_dispatch.py | 18 +++---- tests/utils/test_main.py | 4 +- tests/utils/test_main_menu.py | 8 ++-- tests/utils/test_models.py | 2 - tests/utils/test_personal_info.py | 2 - tests/utils/test_utils.py | 2 - tests/utils/test_views.py | 12 ++--- tests/utils/test_widgets.py | 2 - tests/utils/urls.py | 2 - 182 files changed, 291 insertions(+), 609 deletions(-) create mode 100644 tests/participant/test_csv.py delete mode 100644 tests/plugin_api/urls.py diff --git a/.travis.yml b/.travis.yml index 13aa08de0..576c75c5b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: python python: - - "2.6" - - "2.7" -install: "pip install --allow-external argparse -r requirements.txt" -script: "fab travis_ci" + - "3.3" + - "3.4" +install: "pip install -r requirements.txt" +script: + - "DJANGO_SETTINGS_MODULE='tests.settings' coverage run ./manage.py django test" + - "coverage report -m --fail-under=80" + - "flake8 --max-line-length=150 --statistics openslides tests" diff --git a/CHANGELOG b/CHANGELOG index fc619bbd0..b3a708f15 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,11 @@ http://openslides.org +Version 2.0.0 (unreleased) +========================== + +- Changed supported Python version to >= 3.3 + Version 1.6.1 (unreleased) ========================== [https://github.com/OpenSlides/OpenSlides/issues?milestone=16] diff --git a/README.rst b/README.rst index f44936f0f..19b57a34d 100644 --- a/README.rst +++ b/README.rst @@ -26,12 +26,12 @@ Installation on GNU/Linux or Mac OS X 1. Check requirements - Make sure that you have installed Python Programming Language 2 (>= 2.6.9) + Make sure that you have installed Python Programming Language 3 (>= 3.3) on your system. You will also need the Python development headers. For example for Ubuntu run:: - $ sudo apt-get install python-dev + $ sudo apt-get install python3-dev 2. Setup a virtual environment with Virtual Python Environment builder (optional) @@ -49,7 +49,7 @@ Installation on GNU/Linux or Mac OS X $ mkdir OpenSlides $ cd OpenSlides - $ virtualenv .virtualenv + $ virtualenv -p /usr/bin/python3 .virtualenv $ source .virtualenv/bin/activate 3. Install OpenSlides @@ -67,11 +67,6 @@ Installation on GNU/Linux or Mac OS X OpenSlides will install all required python packages (see requirements_production.txt). - If you use Python 2.6.x, you have to add the option `--allow-external - argparse` to the pip command:: - - $ pip install --allow-external argparse openslides - Installation on Windows ----------------------- @@ -82,18 +77,18 @@ portable version you should observe the following install steps.* 1. Check requirements - Make sure that you have installed Python Programming Language 2 (>= 2.6.9) + Make sure that you have installed Python Programming Language 3 (>= 3.3) and Setuptools on your system. a. Download and run the `Python 32-bit MSI installer - `_. Note + `_. Note that the 32-bit MSI installer is required even on a 64-bit Windows system. If you use the 64-bit MSI installer, step 3 of this instruction will fail unless you installed the package reportlab manually. b. Add python directories to PATH (via Control Panel > System > - Advanced): ``";C:\\Python27;C:\\Python27\\Scripts"``. Note that the path + Advanced): ``";C:\\Python34;C:\\Python34\\Scripts"``. Note that the path can differ if you customized the install of Python in the first step. c. Download and run (via double click) the last `install script @@ -214,11 +209,6 @@ Installation and start of the development version $ pip install -r requirements.txt - If you use Python 2.6.x, you have to add the option `--allow-external - argparse` to the pip command:: - - $ pip install --allow-external argparse -r requirements.txt - For Windows run:: > easy_install # Insert all packages from requirements.txt and requirements_production.txt here diff --git a/docs/conf.py b/docs/conf.py index a287c169e..c5b8ee0d5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # OpenSlides documentation build configuration file, created by # sphinx-quickstart on Mon Mar 12 08:08:56 2012. diff --git a/docs/extensions/autoimage.py b/docs/extensions/autoimage.py index 3177f1ccf..bd510bf90 100644 --- a/docs/extensions/autoimage.py +++ b/docs/extensions/autoimage.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Extension for Sphinx to add new directive 'autoimage' which works as subclass # of the internal Image directive. diff --git a/extras/benchmark/bench.py b/extras/benchmark/bench.py index ce23dde65..af8ea57aa 100755 --- a/extras/benchmark/bench.py +++ b/extras/benchmark/bench.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import argparse import multiprocessing import random diff --git a/extras/openslides_gui/gui.py b/extras/openslides_gui/gui.py index d91861025..f7019e9c6 100644 --- a/extras/openslides_gui/gui.py +++ b/extras/openslides_gui/gui.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from __future__ import unicode_literals import Queue diff --git a/extras/scripts/export_list_of_speakers.py b/extras/scripts/export_list_of_speakers.py index 77427e943..d46befe9f 100644 --- a/extras/scripts/export_list_of_speakers.py +++ b/extras/scripts/export_list_of_speakers.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import sys import csv import argparse diff --git a/extras/scripts/test_data.py b/extras/scripts/test_data.py index 42d5a9f08..16b8b1b7e 100644 --- a/extras/scripts/test_data.py +++ b/extras/scripts/test_data.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from random import randint, choice # Import the openslide settings. Has has to be done before any other openslides diff --git a/extras/win32-portable/prepare_portable.py b/extras/win32-portable/prepare_portable.py index baf8f852b..11f6b97c4 100755 --- a/extras/win32-portable/prepare_portable.py +++ b/extras/win32-portable/prepare_portable.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import errno import glob diff --git a/fabfile.py b/fabfile.py index 1b8c17eef..e18a34d06 100644 --- a/fabfile.py +++ b/fabfile.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import os import sys diff --git a/manage.py b/manage.py index d9fc1d071..27d6ee2d0 100755 --- a/manage.py +++ b/manage.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import sys diff --git a/openslides/__init__.py b/openslides/__init__.py index b219db0b8..1e30421a1 100644 --- a/openslides/__init__.py +++ b/openslides/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - VERSION = (2, 0, 0, 'alpha', 1) # During development it is the next release RELEASE = False @@ -38,9 +36,10 @@ def get_git_commit_id(): try: git_head = open('.git/HEAD', 'r').read().rstrip() if git_head[:5] == 'ref: ': + # The file is a reference. We have to follow it to get the commit id git_commit_id = open('.git/%s' % git_head[5:], 'r').read().rstrip() else: git_commit_id = git_head + return git_commit_id except IOError: - git_commit_id = 'unknown' - return str(git_commit_id) + return 'unknown' diff --git a/openslides/__main__.py b/openslides/__main__.py index 3e2a10755..a7df86b3e 100644 --- a/openslides/__main__.py +++ b/openslides/__main__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import argparse import os @@ -13,7 +12,6 @@ from openslides import get_version from openslides.utils.main import ( detect_openslides_type, ensure_settings, - filesystem2unicode, get_browser_url, get_database_path_from_settings, get_default_settings_path, @@ -244,10 +242,9 @@ def syncdb(settings, args): Run syncdb to create or update the database. """ ensure_settings(settings, args) - # TODO: Check use of filesystem2unicode here. db_file = get_database_path_from_settings() if db_file is not None: - db_dir = filesystem2unicode(os.path.dirname(db_file)) + db_dir = os.path.dirname(db_file) if not os.path.exists(db_dir): os.makedirs(db_dir) if not os.path.exists(db_file): diff --git a/openslides/account/__init__.py b/openslides/account/__init__.py index 6aef35e80..a1c0c869e 100644 --- a/openslides/account/__init__.py +++ b/openslides/account/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import widgets # noqa diff --git a/openslides/account/widgets.py b/openslides/account/widgets.py index 11f384d6d..09fb46d23 100644 --- a/openslides/account/widgets.py +++ b/openslides/account/widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib.auth.models import AnonymousUser from django.utils.translation import ugettext_lazy diff --git a/openslides/agenda/__init__.py b/openslides/agenda/__init__.py index f8db99882..9e426cdbe 100644 --- a/openslides/agenda/__init__.py +++ b/openslides/agenda/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import main_menu, personal_info, signals, slides, widgets # noqa diff --git a/openslides/agenda/csv_import.py b/openslides/agenda/csv_import.py index e270c8ed9..c0a75cfaf 100644 --- a/openslides/agenda/csv_import.py +++ b/openslides/agenda/csv_import.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import csv import re @@ -23,14 +21,15 @@ def import_agenda_items(csvfile): else: csvfile.seek(0) # Check dialect - dialect = csv.Sniffer().sniff(csvfile.readline()) + dialect = csv.Sniffer().sniff(csvfile.readline().decode('utf8')) dialect = csv_ext.patchup(dialect) csvfile.seek(0) # Parse CSV file with transaction.commit_on_success(): success_lines = [] error_lines = [] - for (line_no, line) in enumerate(csv.reader(csvfile, dialect=dialect)): + for (line_no, line) in enumerate(csv.reader( + (line.decode('utf8') for line in csvfile.readlines()), dialect=dialect)): if line_no == 0: # Do not read the header line continue diff --git a/openslides/agenda/forms.py b/openslides/agenda/forms.py index a503d6b93..fd6ad1e7e 100644 --- a/openslides/agenda/forms.py +++ b/openslides/agenda/forms.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import re from ckeditor.widgets import CKEditorWidget @@ -77,5 +75,5 @@ class AppendSpeakerForm(CssClassMixin, forms.Form): if Speaker.objects.filter(person=speaker, item=self.item, begin_time=None).exists(): raise forms.ValidationError(ugettext_lazy( '%s is already on the list of speakers.' - % unicode(speaker))) + % str(speaker))) return speaker diff --git a/openslides/agenda/main_menu.py b/openslides/agenda/main_menu.py index cee93ab96..a90ef18c3 100644 --- a/openslides/agenda/main_menu.py +++ b/openslides/agenda/main_menu.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.main_menu import MainMenuEntry diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index 459b50547..2efe091ba 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from datetime import datetime from django.contrib.auth.models import AnonymousUser @@ -133,7 +131,7 @@ class Item(SlideMixin, AbsoluteUrlMixin, MPTTModel): raise ValidationError(_('Organizational items can not have agenda items as child elements.')) return super(Item, self).clean() - def __unicode__(self): + def __str__(self): return self.get_title() def get_absolute_url(self, link='detail'): @@ -397,8 +395,8 @@ class Speaker(AbsoluteUrlMixin, models.Model): super(Speaker, self).delete(*args, **kwargs) self.check_and_update_projector() - def __unicode__(self): - return unicode(self.person) + def __str__(self): + return str(self.person) def get_absolute_url(self, link='detail'): if link == 'detail': diff --git a/openslides/agenda/personal_info.py b/openslides/agenda/personal_info.py index f70356c78..8d132045e 100644 --- a/openslides/agenda/personal_info.py +++ b/openslides/agenda/personal_info.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.personal_info import PersonalInfo diff --git a/openslides/agenda/search_indexes.py b/openslides/agenda/search_indexes.py index 3c23865f5..48325529f 100644 --- a/openslides/agenda/search_indexes.py +++ b/openslides/agenda/search_indexes.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from haystack import indexes from .models import Item diff --git a/openslides/agenda/signals.py b/openslides/agenda/signals.py index cb03c14ad..d1f65c4cf 100644 --- a/openslides/agenda/signals.py +++ b/openslides/agenda/signals.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from datetime import datetime from django import forms diff --git a/openslides/agenda/slides.py b/openslides/agenda/slides.py index c47db478e..7c702a566 100644 --- a/openslides/agenda/slides.py +++ b/openslides/agenda/slides.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.template.loader import render_to_string from openslides.config.api import config diff --git a/openslides/agenda/urls.py b/openslides/agenda/urls.py index 218e3148f..9072e7406 100644 --- a/openslides/agenda/urls.py +++ b/openslides/agenda/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf.urls import patterns, url from . import views diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index 5133755d0..95b078ea1 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # TODO: Rename all views and template names from datetime import datetime, timedelta @@ -394,7 +393,7 @@ class SpeakerAppendView(SingleObjectMixin, RedirectView): else: try: Speaker.objects.add(item=self.object, person=request.user) - except OpenSlidesError, e: + except OpenSlidesError as e: messages.error(request, e) else: messages.success(request, _('You were successfully added to the list of speakers.')) @@ -627,7 +626,7 @@ class CurrentListOfSpeakersView(RedirectView): if self.request.user.has_perm('agenda.can_be_speaker'): try: Speaker.objects.add(self.request.user, item) - except OpenSlidesError, e: + except OpenSlidesError as e: messages.error(request, e) else: messages.success(request, _('You were successfully added to the list of speakers.')) diff --git a/openslides/agenda/widgets.py b/openslides/agenda/widgets.py index f3de6de6d..9493f4aaf 100644 --- a/openslides/agenda/widgets.py +++ b/openslides/agenda/widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.widgets import Widget diff --git a/openslides/assignment/__init__.py b/openslides/assignment/__init__.py index 8b1da0397..f800d423c 100644 --- a/openslides/assignment/__init__.py +++ b/openslides/assignment/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import main_menu, personal_info, signals, slides, template, widgets # noqa diff --git a/openslides/assignment/forms.py b/openslides/assignment/forms.py index 8787c7a5a..e40b594f4 100644 --- a/openslides/assignment/forms.py +++ b/openslides/assignment/forms.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from django.utils.translation import ugettext_lazy diff --git a/openslides/assignment/main_menu.py b/openslides/assignment/main_menu.py index b5a17393a..b2dc464ad 100644 --- a/openslides/assignment/main_menu.py +++ b/openslides/assignment/main_menu.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.main_menu import MainMenuEntry diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index ca855777d..a6f89a46c 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib.contenttypes.models import ContentType from django.core.urlresolvers import reverse from django.db import models @@ -32,8 +30,8 @@ class AssignmentCandidate(RelatedModelMixin, models.Model): class Meta: unique_together = ("assignment", "person") - def __unicode__(self): - return unicode(self.person) + def __str__(self): + return str(self.person) def get_related_model(self): """ @@ -69,7 +67,7 @@ class Assignment(SlideMixin, AbsoluteUrlMixin, models.Model): ordering = ('name',) verbose_name = ugettext_noop('Election') - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self, link='detail'): @@ -289,8 +287,8 @@ class AssignmentOption(BaseOption): candidate = PersonField() vote_class = AssignmentVote - def __unicode__(self): - return unicode(self.candidate) + def __str__(self): + return str(self.candidate) class AssignmentPoll(SlideMixin, RelatedModelMixin, CollectDefaultVotesMixin, @@ -306,7 +304,7 @@ class AssignmentPoll(SlideMixin, RelatedModelMixin, CollectDefaultVotesMixin, max_length=79, null=True, blank=True, verbose_name=ugettext_lazy("Comment on the ballot paper")) - def __unicode__(self): + def __str__(self): return _("Ballot %d") % self.get_ballot() def get_absolute_url(self, link='update'): diff --git a/openslides/assignment/personal_info.py b/openslides/assignment/personal_info.py index ecebdcab3..1ba394469 100644 --- a/openslides/assignment/personal_info.py +++ b/openslides/assignment/personal_info.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.personal_info import PersonalInfo diff --git a/openslides/assignment/search_indexes.py b/openslides/assignment/search_indexes.py index 4cc668936..f9d434645 100644 --- a/openslides/assignment/search_indexes.py +++ b/openslides/assignment/search_indexes.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from haystack import indexes from .models import Assignment diff --git a/openslides/assignment/signals.py b/openslides/assignment/signals.py index 03df83d45..ca71339fa 100644 --- a/openslides/assignment/signals.py +++ b/openslides/assignment/signals.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from django.dispatch import receiver from django.utils.translation import ugettext as _ diff --git a/openslides/assignment/slides.py b/openslides/assignment/slides.py index edfa347ef..d3627c109 100644 --- a/openslides/assignment/slides.py +++ b/openslides/assignment/slides.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.projector.api import register_slide_model from .models import Assignment, AssignmentPoll diff --git a/openslides/assignment/template.py b/openslides/assignment/template.py index 8e4fb6c4c..0df923112 100644 --- a/openslides/assignment/template.py +++ b/openslides/assignment/template.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.dispatch import receiver from openslides.utils.signals import template_manipulation diff --git a/openslides/assignment/urls.py b/openslides/assignment/urls.py index 1f14fafcc..efb46177d 100644 --- a/openslides/assignment/urls.py +++ b/openslides/assignment/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf.urls import patterns, url from . import views diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index aa35f712b..845bfa873 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib import messages from django.core.urlresolvers import reverse from django.shortcuts import redirect @@ -68,7 +66,7 @@ class AssignmentDetail(DetailView): user = form.cleaned_data['candidate'] try: self.object.run(user, self.request.user) - except NameError, e: + except NameError as e: messages.error(self.request, e) else: messages.success(self.request, _( @@ -106,7 +104,7 @@ class AssignmentSetStatusView(SingleObjectMixin, RedirectView): if status is not None: try: self.object.set_status(status) - except ValueError, e: + except ValueError as e: messages.error(self.request, e) else: messages.success( @@ -124,7 +122,7 @@ class AssignmentRunView(SingleObjectMixin, PermissionMixin, View): assignment = self.get_object() try: assignment.run(self.request.user, self.request.user) - except NameError, e: + except NameError as e: messages.error(self.request, e) else: messages.success( @@ -142,7 +140,8 @@ class AssignmentRunDeleteView(SingleObjectMixin, RedirectView): "assignment.can_manage_assignment"): try: self.object.delrun(self.request.user, blocked=True) - except Exception, e: + except Exception as e: + # TODO: only catch relevant exception messages.error(self.request, e) else: messages.success(self.request, _( @@ -168,7 +167,8 @@ class AssignmentRunOtherDeleteView(SingleObjectMixin, QuestionView): self._get_person_information() try: self.object.delrun(self.person, blocked=False) - except Exception, e: + except Exception as e: + # TODO: only catch relevant exception self.error = e else: self.error = False @@ -400,7 +400,7 @@ class AssignmentPDF(PDFView): # Add result rows elected_candidates = list(assignment.elected) - for candidate, poll_list in vote_results.iteritems(): + for candidate, poll_list in vote_results.items(): row = [] candidate_string = candidate.clean_name @@ -595,7 +595,7 @@ class AssignmentPollPDF(PDFView): cell.append(Spacer(0, 1.3 * cm)) # print ballot papers - for user in xrange(number / 2): + for user in range(number // 2): if len(options) > 13: data.append([cellcolumnA, cell]) else: @@ -629,7 +629,7 @@ class AssignmentPollPDF(PDFView): cell.append(Spacer(0, 0.75 * cm)) # print ballot papers - for user in xrange(number / 2): + for user in range(number // 2): if len(options) > 22: data.append([cellcolumnA, cell]) else: diff --git a/openslides/assignment/widgets.py b/openslides/assignment/widgets.py index c59f5aff6..678a20605 100644 --- a/openslides/assignment/widgets.py +++ b/openslides/assignment/widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.widgets import Widget diff --git a/openslides/config/__init__.py b/openslides/config/__init__.py index d42c22903..8d15e06d4 100644 --- a/openslides/config/__init__.py +++ b/openslides/config/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import main_menu # noqa diff --git a/openslides/config/api.py b/openslides/config/api.py index 9e8e3a1f1..331b000fe 100644 --- a/openslides/config/api.py +++ b/openslides/config/api.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from .exceptions import ConfigError, ConfigNotFound from .models import ConfigStore from .signals import config_signal diff --git a/openslides/config/exceptions.py b/openslides/config/exceptions.py index df7341283..5c8ee69e2 100644 --- a/openslides/config/exceptions.py +++ b/openslides/config/exceptions.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.utils.exceptions import OpenSlidesError diff --git a/openslides/config/main_menu.py b/openslides/config/main_menu.py index e7402ef9d..10332844a 100644 --- a/openslides/config/main_menu.py +++ b/openslides/config/main_menu.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.main_menu import MainMenuEntry diff --git a/openslides/config/middleware.py b/openslides/config/middleware.py index d11a924c7..05275637b 100644 --- a/openslides/config/middleware.py +++ b/openslides/config/middleware.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.config.api import config diff --git a/openslides/config/models.py b/openslides/config/models.py index 31f7b62cf..c5dfd841e 100644 --- a/openslides/config/models.py +++ b/openslides/config/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.db import models from django.utils.translation import ugettext_noop diff --git a/openslides/config/signals.py b/openslides/config/signals.py index d782ac3af..87232c5c0 100644 --- a/openslides/config/signals.py +++ b/openslides/config/signals.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.dispatch import Signal config_signal = Signal(providing_args=[]) diff --git a/openslides/config/urls.py b/openslides/config/urls.py index 2821df267..f7b636911 100644 --- a/openslides/config/urls.py +++ b/openslides/config/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf.urls import patterns, url from openslides.utils.views import RedirectView diff --git a/openslides/config/views.py b/openslides/config/views.py index 82e03dfc5..5be725b97 100644 --- a/openslides/config/views.py +++ b/openslides/config/views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from django.contrib import messages from django.core.urlresolvers import reverse diff --git a/openslides/core/__init__.py b/openslides/core/__init__.py index c57e8c26e..a5dd689db 100644 --- a/openslides/core/__init__.py +++ b/openslides/core/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import main_menu, signals, slides, widgets # noqa diff --git a/openslides/core/chatbox.py b/openslides/core/chatbox.py index be5d0b728..6b5e3ccf6 100644 --- a/openslides/core/chatbox.py +++ b/openslides/core/chatbox.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from datetime import datetime from django.conf import settings diff --git a/openslides/core/forms.py b/openslides/core/forms.py index cdd2357c3..208a9de4a 100644 --- a/openslides/core/forms.py +++ b/openslides/core/forms.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from openslides.utils.forms import CssClassMixin diff --git a/openslides/core/main_menu.py b/openslides/core/main_menu.py index 3b409e5b1..f3dc8789a 100644 --- a/openslides/core/main_menu.py +++ b/openslides/core/main_menu.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.main_menu import MainMenuEntry diff --git a/openslides/core/management/commands/syncdb.py b/openslides/core/management/commands/syncdb.py index 986716a3c..928d2fc4f 100644 --- a/openslides/core/management/commands/syncdb.py +++ b/openslides/core/management/commands/syncdb.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.core.management.commands.syncdb import Command as _Command from openslides.core.signals import post_database_setup diff --git a/openslides/core/models.py b/openslides/core/models.py index a40e9d0c1..4fb41b227 100644 --- a/openslides/core/models.py +++ b/openslides/core/models.py @@ -27,7 +27,7 @@ class CustomSlide(SlideMixin, AbsoluteUrlMixin, models.Model): ('can_use_chat', ugettext_noop('Can use the chat')), ) - def __unicode__(self): + def __str__(self): return self.title def get_absolute_url(self, link='update'): diff --git a/openslides/core/signals.py b/openslides/core/signals.py index bd0a1addd..4cf36ae16 100644 --- a/openslides/core/signals.py +++ b/openslides/core/signals.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from django.dispatch import receiver, Signal from django.utils.translation import ugettext as _ diff --git a/openslides/core/slides.py b/openslides/core/slides.py index c1d515116..1a6e4e948 100644 --- a/openslides/core/slides.py +++ b/openslides/core/slides.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.projector.api import register_slide_model from .models import CustomSlide diff --git a/openslides/core/templates/core/search.html b/openslides/core/templates/core/search.html index 5a91a6609..b296672c9 100644 --- a/openslides/core/templates/core/search.html +++ b/openslides/core/templates/core/search.html @@ -35,9 +35,11 @@ {% if forloop.first %}
    {% endif %} - {% with result_template=result.app_label|add:"-results.html" %} - {% include "search/"|add:result_template %} - {% endwith %} + {% if result.app_label %} + {% with result_template=result.app_label|add:"-results.html" %} + {% include "search/"|add:result_template %} + {% endwith %} + {% endif %} {% if forloop.last %}
{% endif %} diff --git a/openslides/core/templatetags/tags.py b/openslides/core/templatetags/tags.py index a35424e90..6367a8e4b 100644 --- a/openslides/core/templatetags/tags.py +++ b/openslides/core/templatetags/tags.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import template from django.utils.translation import ugettext as _ diff --git a/openslides/core/urls.py b/openslides/core/urls.py index 0fcde33b1..b1f3cb1a0 100644 --- a/openslides/core/urls.py +++ b/openslides/core/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf.urls import patterns, url from openslides.utils.views import RedirectView diff --git a/openslides/core/views.py b/openslides/core/views.py index b172a4279..b33b72774 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf import settings from django.contrib import messages from django.core.exceptions import PermissionDenied diff --git a/openslides/core/widgets.py b/openslides/core/widgets.py index db39f39ba..5b809f9cd 100644 --- a/openslides/core/widgets.py +++ b/openslides/core/widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.config.api import config diff --git a/openslides/global_settings.py b/openslides/global_settings.py index c52421340..0e1453feb 100644 --- a/openslides/global_settings.py +++ b/openslides/global_settings.py @@ -1,11 +1,8 @@ -# -*- coding: utf-8 -*- - import os import copy from django.utils.translation import ugettext_lazy -from openslides.utils.main import filesystem2unicode from openslides.utils.plugins import collect_plugins SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) @@ -36,7 +33,7 @@ USE_I18N = True USE_L10N = True LOCALE_PATHS = ( - filesystem2unicode(os.path.join(SITE_ROOT, 'locale')), + os.path.join(SITE_ROOT, 'locale'), ) # URL that handles the media served from MEDIA_ROOT. Make sure to use a @@ -46,7 +43,7 @@ MEDIA_URL = '/media/' # Absolute path to the directory that holds static media from ``collectstatic`` # Example: "/home/media/static.lawrence.com/" -STATIC_ROOT = filesystem2unicode(os.path.join(SITE_ROOT, '../collected-site-static')) +STATIC_ROOT = os.path.join(SITE_ROOT, '../collected-site-static') # URL that handles the media served from STATIC_ROOT. Make sure to use a # trailing slash if there is a path component (optional in other cases). diff --git a/openslides/mediafile/__init__.py b/openslides/mediafile/__init__.py index 0a79488ec..a308af592 100644 --- a/openslides/mediafile/__init__.py +++ b/openslides/mediafile/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import main_menu, slides, template, widgets # noqa diff --git a/openslides/mediafile/forms.py b/openslides/mediafile/forms.py index 86ba4c443..90010832b 100644 --- a/openslides/mediafile/forms.py +++ b/openslides/mediafile/forms.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.forms import ModelForm from openslides.utils.forms import CssClassMixin diff --git a/openslides/mediafile/main_menu.py b/openslides/mediafile/main_menu.py index 157a3fa36..c99e6c496 100644 --- a/openslides/mediafile/main_menu.py +++ b/openslides/mediafile/main_menu.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.main_menu import MainMenuEntry diff --git a/openslides/mediafile/models.py b/openslides/mediafile/models.py index 555cc4f3d..a9a159b33 100644 --- a/openslides/mediafile/models.py +++ b/openslides/mediafile/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import mimetypes from django.core.urlresolvers import reverse @@ -53,7 +51,7 @@ class Mediafile(SlideMixin, AbsoluteUrlMixin, models.Model): ('can_upload', ugettext_noop('Can upload files')), ('can_manage', ugettext_noop('Can manage files')),) - def __unicode__(self): + def __str__(self): """ Method for representation. """ diff --git a/openslides/mediafile/search_indexes.py b/openslides/mediafile/search_indexes.py index 3ce0a7cef..894448997 100644 --- a/openslides/mediafile/search_indexes.py +++ b/openslides/mediafile/search_indexes.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from haystack import indexes from .models import Mediafile diff --git a/openslides/mediafile/slides.py b/openslides/mediafile/slides.py index b5d2ae386..da1b8feab 100644 --- a/openslides/mediafile/slides.py +++ b/openslides/mediafile/slides.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- from django.template.loader import render_to_string diff --git a/openslides/mediafile/template.py b/openslides/mediafile/template.py index 6bd55d6c9..6d4c61bf2 100644 --- a/openslides/mediafile/template.py +++ b/openslides/mediafile/template.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.dispatch import receiver from openslides.utils.signals import template_manipulation diff --git a/openslides/mediafile/urls.py b/openslides/mediafile/urls.py index 222442dab..deaaaeec1 100644 --- a/openslides/mediafile/urls.py +++ b/openslides/mediafile/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf.urls import patterns, url from . import views diff --git a/openslides/mediafile/views.py b/openslides/mediafile/views.py index cfe27bd24..27ee77164 100644 --- a/openslides/mediafile/views.py +++ b/openslides/mediafile/views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.http import HttpResponse from openslides.config.api import config diff --git a/openslides/mediafile/widgets.py b/openslides/mediafile/widgets.py index a7ba64b59..b3c2a6127 100644 --- a/openslides/mediafile/widgets.py +++ b/openslides/mediafile/widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.widgets import Widget diff --git a/openslides/motion/__init__.py b/openslides/motion/__init__.py index f8db99882..9e426cdbe 100644 --- a/openslides/motion/__init__.py +++ b/openslides/motion/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import main_menu, personal_info, signals, slides, widgets # noqa diff --git a/openslides/motion/csv_import.py b/openslides/motion/csv_import.py index 9b07d3bd0..b1d83844b 100644 --- a/openslides/motion/csv_import.py +++ b/openslides/motion/csv_import.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # TODO: Rename the file to 'csv.py' when we drop python2 support. At the moment # the name csv has a conflict with the core-module. See: # http://docs.python.org/2/tutorial/modules.html#intra-package-references @@ -38,12 +36,13 @@ def import_motions(csvfile, default_submitter, override, importing_person=None): csvfile.seek(0) with transaction.commit_on_success(): - dialect = csv.Sniffer().sniff(csvfile.readline()) + dialect = csv.Sniffer().sniff(csvfile.readline().decode('utf8')) dialect = csv_ext.patchup(dialect) csvfile.seek(0) all_error_messages = [] all_warning_messages = [] - for (line_no, line) in enumerate(csv.reader(csvfile, dialect=dialect)): + for (line_no, line) in enumerate(csv.reader( + (line.decode('utf8') for line in csvfile.readlines()), dialect=dialect)): warning = [] if line_no < 1: # Do not read the header line @@ -92,7 +91,7 @@ def import_motions(csvfile, default_submitter, override, importing_person=None): person_found = False if submitter: for person in Persons(): - if person.clean_name == submitter.decode('utf8'): + if person.clean_name == submitter: if person_found: warning.append(_('Several suitable submitters found.')) person_found = False diff --git a/openslides/motion/exceptions.py b/openslides/motion/exceptions.py index 13a8c233e..eca36f427 100644 --- a/openslides/motion/exceptions.py +++ b/openslides/motion/exceptions.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.utils.exceptions import OpenSlidesError diff --git a/openslides/motion/forms.py b/openslides/motion/forms.py index 9ecae40a8..85d348c79 100644 --- a/openslides/motion/forms.py +++ b/openslides/motion/forms.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from django.utils.translation import ugettext_lazy diff --git a/openslides/motion/main_menu.py b/openslides/motion/main_menu.py index e84e64c57..b85c421a0 100644 --- a/openslides/motion/main_menu.py +++ b/openslides/motion/main_menu.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.main_menu import MainMenuEntry diff --git a/openslides/motion/models.py b/openslides/motion/models.py index 7f8351c51..c206ac536 100644 --- a/openslides/motion/models.py +++ b/openslides/motion/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.core.urlresolvers import reverse from django.db import models from django.db.models import Max @@ -84,7 +82,7 @@ class Motion(SlideMixin, AbsoluteUrlMixin, models.Model): ordering = ('identifier', ) verbose_name = ugettext_noop('Motion') - def __unicode__(self): + def __str__(self): """ Return a human readable name of this motion. """ @@ -125,7 +123,7 @@ class Motion(SlideMixin, AbsoluteUrlMixin, models.Model): # Solves the problem, that there can only be one motion with an empty # string as identifier. - if not self.identifier and isinstance(self.identifier, basestring): + if not self.identifier and isinstance(self.identifier, str): self.identifier = None super(Motion, self).save(*args, **kwargs) @@ -461,7 +459,7 @@ class Motion(SlideMixin, AbsoluteUrlMixin, models.Model): """ Return a title for the agenda. """ - return unicode(self) + return str(self) def get_agenda_title_supplement(self): """ @@ -551,7 +549,7 @@ class MotionVersion(AbsoluteUrlMixin, models.Model): class Meta: unique_together = ("motion", "version_number") - def __unicode__(self): + def __str__(self): """Return a string, representing this object.""" counter = self.version_number or ugettext_lazy('new') return "Motion %s, Version %s" % (self.motion_id, counter) @@ -587,9 +585,9 @@ class MotionSubmitter(RelatedModelMixin, models.Model): person = PersonField() """The person, who is the submitter.""" - def __unicode__(self): + def __str__(self): """Return the name of the submitter as string.""" - return unicode(self.person) + return str(self.person) def get_related_model(self): return self.motion @@ -604,9 +602,9 @@ class MotionSupporter(models.Model): person = PersonField() """The person, who is the supporter.""" - def __unicode__(self): + def __str__(self): """Return the name of the supporter as string.""" - return unicode(self.person) + return str(self.person) class Category(AbsoluteUrlMixin, models.Model): @@ -619,7 +617,7 @@ class Category(AbsoluteUrlMixin, models.Model): Used to build the identifier of a motion. """ - def __unicode__(self): + def __str__(self): return self.name def get_absolute_url(self, link='update'): @@ -661,7 +659,7 @@ class MotionLog(models.Model): class Meta: ordering = ['-time'] - def __unicode__(self): + def __str__(self): """ Return a string, representing the log message. """ @@ -721,7 +719,7 @@ class MotionPoll(SlideMixin, RelatedModelMixin, CollectDefaultVotesMixin, class Meta: unique_together = ("motion", "poll_number") - def __unicode__(self): + def __str__(self): """Return a string, representing the poll.""" return _('Vote %d') % self.poll_number @@ -808,7 +806,7 @@ class State(models.Model): If true, the motion does not get an identifier if the state change to this one, else it does.""" - def __unicode__(self): + def __str__(self): """Returns the name of the state.""" return self.name @@ -843,7 +841,7 @@ class Workflow(models.Model): first_state = models.OneToOneField(State, related_name='+', null=True) """A one-to-one relation to a state, the starting point for the workflow.""" - def __unicode__(self): + def __str__(self): """Returns the name of the workflow.""" return self.name diff --git a/openslides/motion/pdf.py b/openslides/motion/pdf.py index 39bcc8093..ef942ecd8 100644 --- a/openslides/motion/pdf.py +++ b/openslides/motion/pdf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from operator import attrgetter import random @@ -51,7 +49,7 @@ def motion_to_pdf(pdf, motion): cell1b = [] cell1b.append(Spacer(0, 0.2 * cm)) for submitter in motion.submitter.all(): - cell1b.append(Paragraph(unicode(submitter), stylesheet['Normal'])) + cell1b.append(Paragraph(str(submitter), stylesheet['Normal'])) motion_data.append([cell1a, cell1b]) # TODO: choose this in workflow @@ -74,7 +72,7 @@ def motion_to_pdf(pdf, motion): % _("Supporters"), stylesheet['Heading4'])) supporters = motion.supporter.all() for supporter in supporters: - cell3b.append(Paragraph(".  %s" % unicode(supporter), + cell3b.append(Paragraph(".  %s" % str(supporter), stylesheet['Normal'])) cell3b.append(Spacer(0, 0.2 * cm)) motion_data.append([cell3a, cell3b]) @@ -200,7 +198,7 @@ def convert_html_to_reportlab(pdf, text): text = soup.body.contents paragraph_number = 1 for paragraph in text: - paragraph = unicode(paragraph) + paragraph = str(paragraph) # ignore empty paragraphs (created by newlines/tabs of ckeditor) if paragraph == '\n' or paragraph == '\n\n' or paragraph == '\n\t': continue @@ -271,11 +269,11 @@ def motion_poll_to_pdf(pdf, poll): cell.append(Paragraph(_("%d. Vote") % poll.poll_number, stylesheet['Ballot_description'])) cell.append(Spacer(0, 0.5 * cm)) cell.append(Paragraph("%s %s" - % (circle, unicode(_("Yes"))), stylesheet['Ballot_option'])) + % (circle, _("Yes")), stylesheet['Ballot_option'])) cell.append(Paragraph("%s %s" - % (circle, unicode(_("No"))), stylesheet['Ballot_option'])) + % (circle, _("No")), stylesheet['Ballot_option'])) cell.append(Paragraph("%s %s" - % (circle, unicode(_("Abstention"))), stylesheet['Ballot_option'])) + % (circle, _("Abstention")), stylesheet['Ballot_option'])) data = [] # get ballot papers config values ballot_papers_selection = config["motion_pdf_ballot_papers_selection"] @@ -299,7 +297,7 @@ def motion_poll_to_pdf(pdf, poll): # print ballot papers if number > 0: # TODO: try [cell, cell] * (number / 2) - for user in xrange(number / 2): + for user in range(number / 2): data.append([cell, cell]) rest = number % 2 if rest: diff --git a/openslides/motion/personal_info.py b/openslides/motion/personal_info.py index a3a283841..147acbfcf 100644 --- a/openslides/motion/personal_info.py +++ b/openslides/motion/personal_info.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.config.api import config diff --git a/openslides/motion/search_indexes.py b/openslides/motion/search_indexes.py index bba40faa7..46a599d9f 100644 --- a/openslides/motion/search_indexes.py +++ b/openslides/motion/search_indexes.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from haystack import indexes from .models import Motion diff --git a/openslides/motion/signals.py b/openslides/motion/signals.py index aba69d1bb..6b030471d 100644 --- a/openslides/motion/signals.py +++ b/openslides/motion/signals.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from django.dispatch import receiver from django.utils.translation import ugettext as _ diff --git a/openslides/motion/slides.py b/openslides/motion/slides.py index 434cce969..ae4472e64 100644 --- a/openslides/motion/slides.py +++ b/openslides/motion/slides.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.projector.api import register_slide_model from .models import Motion, MotionPoll diff --git a/openslides/motion/urls.py b/openslides/motion/urls.py index af8085b03..96b5e27c3 100644 --- a/openslides/motion/urls.py +++ b/openslides/motion/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf.urls import patterns, url # TODO: define the Views inhere diff --git a/openslides/motion/views.py b/openslides/motion/views.py index 829421665..4c4fc1ae6 100644 --- a/openslides/motion/views.py +++ b/openslides/motion/views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib import messages from django.core.urlresolvers import reverse from django.http import Http404, HttpResponseRedirect @@ -121,7 +119,7 @@ class MotionEditMixin(object): active_slide = get_active_slide() active_slide_pk = active_slide.get('pk', None) if (active_slide['callback'] == 'motion' and - unicode(self.object.pk) == unicode(active_slide_pk)): + str(self.object.pk) == str(active_slide_pk)): update_projector() messages.success(self.request, self.get_success_message()) diff --git a/openslides/motion/widgets.py b/openslides/motion/widgets.py index 3873f3bd5..2d9d93f24 100644 --- a/openslides/motion/widgets.py +++ b/openslides/motion/widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.widgets import Widget diff --git a/openslides/participant/__init__.py b/openslides/participant/__init__.py index c57e8c26e..a5dd689db 100644 --- a/openslides/participant/__init__.py +++ b/openslides/participant/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import main_menu, signals, slides, widgets # noqa diff --git a/openslides/participant/api.py b/openslides/participant/api.py index a52875266..b95c39f8a 100644 --- a/openslides/participant/api.py +++ b/openslides/participant/api.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from random import choice from .models import Group, User diff --git a/openslides/participant/csv_import.py b/openslides/participant/csv_import.py index 55c16c2c4..5e52bcb22 100644 --- a/openslides/participant/csv_import.py +++ b/openslides/participant/csv_import.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import csv from django.db import transaction @@ -21,12 +19,12 @@ def import_users(csvfile): csvfile.seek(0) with transaction.commit_on_success(): - dialect = csv.Sniffer().sniff(csvfile.readline()) + dialect = csv.Sniffer().sniff(csvfile.readline().decode('utf-8')) dialect = csv_ext.patchup(dialect) csvfile.seek(0) - for (line_no, line) in enumerate(csv.reader(csvfile, - dialect=dialect)): + for (line_no, line) in enumerate(csv.reader( + (line.decode('utf8') for line in csvfile.readlines()), dialect=dialect)): if line_no: try: (title, first_name, last_name, gender, email, groups, diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index 7504110b7..3dbd426cb 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from django.conf import settings from django.contrib.auth.models import Permission diff --git a/openslides/participant/main_menu.py b/openslides/participant/main_menu.py index f6d5e0818..975b6f161 100644 --- a/openslides/participant/main_menu.py +++ b/openslides/participant/main_menu.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.main_menu import MainMenuEntry diff --git a/openslides/participant/middleware.py b/openslides/participant/middleware.py index a63dc2fe4..5a8530584 100644 --- a/openslides/participant/middleware.py +++ b/openslides/participant/middleware.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib.auth.middleware import AuthenticationMiddleware as _AuthenticationMiddleware from django.contrib.auth.models import AnonymousUser diff --git a/openslides/participant/models.py b/openslides/participant/models.py index d1bc080aa..51f4bdaee 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib.auth.models import Group as DjangoGroup from django.contrib.auth.models import User as DjangoUser from django.contrib.auth.models import Permission @@ -56,7 +54,7 @@ class User(SlideMixin, PersonMixin, Person, AbsoluteUrlMixin, DjangoUser): ) ordering = ('last_name',) - def __unicode__(self): + def __str__(self): if self.name_suffix: return u"%s (%s)" % (self.clean_name, self.name_suffix) return u"%s" % self.clean_name @@ -125,8 +123,8 @@ class Group(SlideMixin, PersonMixin, Person, AbsoluteUrlMixin, DjangoGroup): class Meta: ordering = ('name',) - def __unicode__(self): - return unicode(self.name) + def __str__(self): + return str(self.name) def get_absolute_url(self, link='detail'): """ diff --git a/openslides/participant/pdf.py b/openslides/participant/pdf.py index 32deaedc8..ddaa4b8c9 100644 --- a/openslides/participant/pdf.py +++ b/openslides/participant/pdf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext as _ from reportlab.graphics.barcode.qr import QrCodeWidget from reportlab.graphics.shapes import Drawing @@ -30,7 +28,7 @@ def participants_to_pdf(pdf): groups = '' for group in user.groups.all(): if group.pk != 2: - groups += "%s
" % unicode(_(group.name)) + groups += "%s
" % _(group.name) data.append([ counter, Paragraph(user.title, stylesheet['Tablecell']), @@ -82,7 +80,7 @@ def participants_passwords_to_pdf(pdf): qrcode_wlan_draw.add(qrcode_wlan) for user in User.objects.all().order_by(sort): - pdf.append(Paragraph(unicode(user), stylesheet['h1'])) + pdf.append(Paragraph(user, stylesheet['h1'])) pdf.append(Spacer(0, 1 * cm)) data = [] # WLAN access data diff --git a/openslides/participant/search_indexes.py b/openslides/participant/search_indexes.py index 5173cc9f6..f142f19a8 100644 --- a/openslides/participant/search_indexes.py +++ b/openslides/participant/search_indexes.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from haystack import indexes from .models import User diff --git a/openslides/participant/signals.py b/openslides/participant/signals.py index b21cfb7f9..cfa0a557e 100644 --- a/openslides/participant/signals.py +++ b/openslides/participant/signals.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType diff --git a/openslides/participant/slides.py b/openslides/participant/slides.py index 7bd0fabb4..5ee3edf28 100644 --- a/openslides/participant/slides.py +++ b/openslides/participant/slides.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.projector.api import register_slide_model from .models import Group, User diff --git a/openslides/participant/urls.py b/openslides/participant/urls.py index 242458de1..2595b33b4 100644 --- a/openslides/participant/urls.py +++ b/openslides/participant/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf.urls import patterns, url from . import views diff --git a/openslides/participant/views.py b/openslides/participant/views.py index aa02bbfad..ecd2f81e0 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib import messages from django.contrib.auth.decorators import login_required from django.contrib.auth.forms import PasswordChangeForm diff --git a/openslides/participant/widgets.py b/openslides/participant/widgets.py index 65b6879a7..4d8a2a942 100644 --- a/openslides/participant/widgets.py +++ b/openslides/participant/widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.utils.translation import ugettext_lazy from openslides.utils.widgets import Widget diff --git a/openslides/poll/forms.py b/openslides/poll/forms.py index fa3221ccf..031a1ef44 100644 --- a/openslides/poll/forms.py +++ b/openslides/poll/forms.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from openslides.utils.forms import CssClassMixin diff --git a/openslides/poll/models.py b/openslides/poll/models.py index 770bc585c..ca4d8b1fd 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import locale from django.core.exceptions import ObjectDoesNotExist @@ -52,7 +50,7 @@ class BaseVote(models.Model): class Meta: abstract = True - def __unicode__(self): + def __str__(self): return self.print_weight() def get_value(self): diff --git a/openslides/poll/views.py b/openslides/poll/views.py index f16806734..7de492cab 100644 --- a/openslides/poll/views.py +++ b/openslides/poll/views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.forms.models import modelform_factory from django.http import HttpResponseRedirect diff --git a/openslides/projector/__init__.py b/openslides/projector/__init__.py index a5101f887..05f9e673d 100644 --- a/openslides/projector/__init__.py +++ b/openslides/projector/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import signals, widgets # noqa diff --git a/openslides/projector/api.py b/openslides/projector/api.py index 8f5e906c7..1eb615cb4 100644 --- a/openslides/projector/api.py +++ b/openslides/projector/api.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from json import dumps from time import time @@ -49,7 +47,7 @@ def update_projector_overlay(overlay): """ if overlay is None: overlays = [item for item in get_overlays().values()] - elif isinstance(overlay, basestring): + elif isinstance(overlay, str): overlays = [get_overlays()[overlay]] else: overlays = [overlay] diff --git a/openslides/projector/exceptions.py b/openslides/projector/exceptions.py index 88bf6dc00..4ce9d1caf 100644 --- a/openslides/projector/exceptions.py +++ b/openslides/projector/exceptions.py @@ -1,5 +1,2 @@ -# -*- coding: utf-8 -*- - - class ProjectorExceptionWarning(RuntimeWarning): pass diff --git a/openslides/projector/models.py b/openslides/projector/models.py index a9de923c8..ca0d8fa40 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import reverse diff --git a/openslides/projector/projector.py b/openslides/projector/projector.py index b569284e7..418450d42 100644 --- a/openslides/projector/projector.py +++ b/openslides/projector/projector.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import warnings diff --git a/openslides/projector/signals.py b/openslides/projector/signals.py index 9a8bd325e..973c3737a 100644 --- a/openslides/projector/signals.py +++ b/openslides/projector/signals.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from time import time from django.contrib.staticfiles.templatetags.staticfiles import static diff --git a/openslides/projector/urls.py b/openslides/projector/urls.py index b266dc1d0..ec37c0937 100644 --- a/openslides/projector/urls.py +++ b/openslides/projector/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf.urls import patterns, url from . import views diff --git a/openslides/projector/views.py b/openslides/projector/views.py index 080d02284..87d6add69 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.config.api import config from openslides.mediafile.models import Mediafile from openslides.utils.tornado_webserver import ProjectorSocketHandler diff --git a/openslides/projector/widgets.py b/openslides/projector/widgets.py index 707567134..da02d94b5 100644 --- a/openslides/projector/widgets.py +++ b/openslides/projector/widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.core.context_processors import csrf from django.utils.translation import ugettext_lazy diff --git a/openslides/urls.py b/openslides/urls.py index a66ed17f0..521560278 100644 --- a/openslides/urls.py +++ b/openslides/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf import settings from django.conf.urls import include, patterns, url diff --git a/openslides/utils/auth/AnonymousAuth.py b/openslides/utils/auth/AnonymousAuth.py index 7ec2d9153..dd8b4ca06 100644 --- a/openslides/utils/auth/AnonymousAuth.py +++ b/openslides/utils/auth/AnonymousAuth.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib.auth.models import Permission from openslides.config.api import config diff --git a/openslides/utils/auth/__init__.py b/openslides/utils/auth/__init__.py index 88973bafe..5a568e305 100644 --- a/openslides/utils/auth/__init__.py +++ b/openslides/utils/auth/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - -from AnonymousAuth import * # noqa +from .AnonymousAuth import * # noqa diff --git a/openslides/utils/csv_ext.py b/openslides/utils/csv_ext.py index 4f31ea6f8..7d988369b 100644 --- a/openslides/utils/csv_ext.py +++ b/openslides/utils/csv_ext.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from csv import Dialect, excel, register_dialect diff --git a/openslides/utils/dispatch.py b/openslides/utils/dispatch.py index 35291ba0b..df74630bf 100644 --- a/openslides/utils/dispatch.py +++ b/openslides/utils/dispatch.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - class SignalConnectMetaClass(type): """ Metaclass to connect the children of a base class to a Django signal. @@ -30,8 +27,7 @@ class SignalConnectMetaClass(type): Example: - class Base(object): - __metaclass__ = SignalConnectMetaClass + class Base(object, metaclass=SignalConnectMetaClass): signal = django.dispatch.Signal() @classmethod def get_dispatch_uid(cls): diff --git a/openslides/utils/exceptions.py b/openslides/utils/exceptions.py index b6949d99a..a28801d2f 100644 --- a/openslides/utils/exceptions.py +++ b/openslides/utils/exceptions.py @@ -1,5 +1,2 @@ -# -*- coding: utf-8 -*- - - class OpenSlidesError(Exception): pass diff --git a/openslides/utils/forms.py b/openslides/utils/forms.py index 1dfe2404c..5db0d8c50 100644 --- a/openslides/utils/forms.py +++ b/openslides/utils/forms.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import bleach from django import forms from django.utils.translation import ugettext as _ diff --git a/openslides/utils/main.py b/openslides/utils/main.py index c3a189841..f8bda0967 100644 --- a/openslides/utils/main.py +++ b/openslides/utils/main.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import ctypes import os import socket @@ -9,9 +7,9 @@ import threading import time import webbrowser -from base64 import b64encode from django.core.exceptions import ImproperlyConfigured from django.conf import ENVIRONMENT_VARIABLE +from django.utils.crypto import get_random_string from django.utils.translation import activate, check_for_language, get_language from django.utils.translation import ugettext as _ @@ -32,28 +30,6 @@ class DatabaseInSettingsError(Exception): pass -def filesystem2unicode(path): - """ - Transforms a path string to unicode according to the filesystem's encoding. - """ - # TODO: Delete this function after switch to Python 3. - if not isinstance(path, unicode): - filesystem_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() - path = path.decode(filesystem_encoding) - return path - - -def unicode2filesystem(path): - """ - Transforms a path unicode to string according to the filesystem's encoding. - """ - # TODO: Delete this function after switch to Python 3. - if not isinstance(path, str): - filesystem_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() - path = path.encode(filesystem_encoding) - return path - - def detect_openslides_type(): """ Returns the type of this OpenSlides version. @@ -82,8 +58,8 @@ def get_default_settings_path(openslides_type): openslides.utils.main. """ if openslides_type == UNIX_VERSION: - parent_directory = filesystem2unicode(os.environ.get( - 'XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config'))) + parent_directory = os.environ.get( + 'XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config')) elif openslides_type == WINDOWS_VERSION: parent_directory = get_win32_app_data_path() elif openslides_type == WINDOWS_PORTABLE_VERSION: @@ -102,7 +78,7 @@ def setup_django_settings_module(settings_path): settings_module_name = ".".join(settings_file.split('.')[:-1]) if '.' in settings_module_name: raise ImproperlyConfigured("'.' is not an allowed character in the settings-file") - settings_module_dir = unicode2filesystem(os.path.dirname(settings_path)) # TODO: Use absolute path here or not? + settings_module_dir = os.path.dirname(settings_path) # TODO: Use absolute path here or not? sys.path.insert(0, settings_module_dir) os.environ[ENVIRONMENT_VARIABLE] = '%s' % settings_module_name @@ -117,7 +93,7 @@ def ensure_settings(settings, args): else: context = get_default_settings_context(args.user_data_path) write_settings(settings, **context) - print('Settings file at %s successfully created.' % unicode2filesystem(settings)) + print('Settings file at %s successfully created.' % settings) def get_default_settings_context(user_data_path=None): @@ -155,8 +131,8 @@ def get_default_user_data_path(openslides_type): in openslides.utils.main. """ if openslides_type == UNIX_VERSION: - default_user_data_path = filesystem2unicode(os.environ.get( - 'XDG_DATA_HOME', os.path.join(os.path.expanduser('~'), '.local', 'share'))) + default_user_data_path = os.environ.get( + 'XDG_DATA_HOME', os.path.join(os.path.expanduser('~'), '.local', 'share')) elif openslides_type == WINDOWS_VERSION: default_user_data_path = get_win32_app_data_path() elif openslides_type == WINDOWS_PORTABLE_VERSION: @@ -183,6 +159,7 @@ def get_win32_app_data_path(): buf = ctypes.create_unicode_buffer(MAX_PATH) res = SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, buf) if res != 0: + # TODO: Write other exception raise Exception("Could not determine Windows' APPDATA path") return buf.value @@ -195,7 +172,7 @@ def get_win32_portable_path(): # NOTE: sys.executable will be the path to openslides.exe # since it is essentially a small wrapper that embeds the # python interpreter - portable_path = filesystem2unicode(os.path.dirname(os.path.abspath(sys.executable))) + portable_path = os.path.dirname(os.path.abspath(sys.executable)) try: fd, test_file = tempfile.mkstemp(dir=portable_path) except OSError: @@ -223,7 +200,11 @@ def write_settings(settings_path, template=None, **context): if template is None: with open(os.path.join(os.path.dirname(__file__), 'settings.py.tpl')) as template_file: template = template_file.read() - context.setdefault('secret_key', b64encode(os.urandom(30))) + + # Create a random SECRET_KEY to put it in the settings. + # from django.core.management.commands.startproject + chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' + context.setdefault('secret_key', get_random_string(50, chars)) content = template % context settings_module = os.path.realpath(os.path.dirname(settings_path)) if not os.path.exists(settings_module): diff --git a/openslides/utils/main_menu.py b/openslides/utils/main_menu.py index 90a3fcb2b..400d9339b 100644 --- a/openslides/utils/main_menu.py +++ b/openslides/utils/main_menu.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.core.urlresolvers import reverse from django.dispatch import Signal, receiver @@ -7,14 +5,14 @@ from .dispatch import SignalConnectMetaClass from .signals import template_manipulation -class MainMenuEntry(object): +class MainMenuEntry(object, metaclass=SignalConnectMetaClass): """ Base class for a main menu entry. Every app which wants to add entries has to create a class subclassing from this base class. For the appearance the verbose_name, the pattern_name and the icon-css-class attribute have to be set. The - __metaclass__ attribute (SignalConnectMetaClass) does the rest of the + metaclass (SignalConnectMetaClass) does the rest of the magic. For the appearance there are some optional attributes and methods like @@ -22,7 +20,6 @@ class MainMenuEntry(object): check_permission, get_url, get_default_weight, get_icon_css_class, get_stylesheets and get_javascript_files. """ - __metaclass__ = SignalConnectMetaClass signal = Signal(providing_args=['request']) verbose_name = None required_permission = None @@ -43,12 +40,12 @@ class MainMenuEntry(object): """ self.request = request - def __unicode__(self): + def __str__(self): if self.verbose_name is None: raise NotImplementedError( 'The main menu entry class %s must provide a verbose_name ' - 'attribute or override the __unicode__ method.' % type(self).__name__) - return unicode(self.verbose_name) + 'attribute or override the __str__ method.' % type(self).__name__) + return str(self.verbose_name) @classmethod def get_dispatch_uid(cls): diff --git a/openslides/utils/models.py b/openslides/utils/models.py index bd1ccb50d..f430440fe 100644 --- a/openslides/utils/models.py +++ b/openslides/utils/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.db import models diff --git a/openslides/utils/pdf.py b/openslides/utils/pdf.py index 97712f5ff..8e492d5ca 100644 --- a/openslides/utils/pdf.py +++ b/openslides/utils/pdf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from datetime import datetime from os.path import join as path_join diff --git a/openslides/utils/person/__init__.py b/openslides/utils/person/__init__.py index 5c94653a1..5c0f0a86d 100644 --- a/openslides/utils/person/__init__.py +++ b/openslides/utils/person/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.utils.person.signals import receive_persons from openslides.utils.person.api import ( generate_person_id, get_person, Person, Persons) diff --git a/openslides/utils/person/api.py b/openslides/utils/person/api.py index 4e251cab2..27ff80b06 100644 --- a/openslides/utils/person/api.py +++ b/openslides/utils/person/api.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from .signals import receive_persons @@ -13,7 +11,7 @@ class Person(object): """ raise NotImplementedError('Any person object needs a person_id') - def __unicode__(self): + def __str__(self): """ Return a string for this person. """ @@ -32,7 +30,7 @@ class Person(object): """ Return the name of this person without a suffix """ - return unicode(self) + return str(self) @property def name_suffix(self): diff --git a/openslides/utils/person/forms.py b/openslides/utils/person/forms.py index 05f1496c7..18aa139aa 100644 --- a/openslides/utils/person/forms.py +++ b/openslides/utils/person/forms.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from openslides.utils.person.api import get_person, Persons diff --git a/openslides/utils/person/models.py b/openslides/utils/person/models.py index dee98916b..af25f73f2 100644 --- a/openslides/utils/person/models.py +++ b/openslides/utils/person/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.contrib.auth.models import AnonymousUser from django.db import models @@ -8,9 +7,7 @@ from .api import generate_person_id, get_person from .forms import PersonFormField -class PersonField(models.fields.Field): - __metaclass__ = models.SubfieldBase - +class PersonField(models.fields.Field, metaclass=models.SubfieldBase): def __init__(self, *args, **kwargs): kwargs['max_length'] = 255 super(PersonField, self).__init__(*args, **kwargs) @@ -45,7 +42,7 @@ class PersonField(models.fields.Field): if value is None: # For Fields with null=True return None - elif isinstance(value, basestring): + elif isinstance(value, str): # The object is already a a person_id return value @@ -70,7 +67,7 @@ class PersonMixin(object): raise AttributeError("%s has to have a attribute 'person_prefix'" % self) - def __unicode__(self): + def __str__(self): return self.person_id def prepare_database_save(self, field): diff --git a/openslides/utils/person/signals.py b/openslides/utils/person/signals.py index 4683150ef..a51511155 100644 --- a/openslides/utils/person/signals.py +++ b/openslides/utils/person/signals.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.dispatch import Signal receive_persons = Signal(providing_args=['person_prefix_filter', 'id_filter']) diff --git a/openslides/utils/personal_info.py b/openslides/utils/personal_info.py index 8075c6f0d..63d727249 100644 --- a/openslides/utils/personal_info.py +++ b/openslides/utils/personal_info.py @@ -1,11 +1,9 @@ -# -*- coding: utf-8 -*- - from django.dispatch import Signal from .dispatch import SignalConnectMetaClass -class PersonalInfo(object): +class PersonalInfo(object, metaclass=SignalConnectMetaClass): """ Base class for a personal info collection for the personal info widget on the dashboard. @@ -13,10 +11,9 @@ class PersonalInfo(object): Every app which wants to add info has to create a class subclassing from this base class. For the content the headline attribute, the default_weight attribute and the get_queryset method have to be set. - The __metaclass__ attribute (SignalConnectMetaClass) does the rest of + The metaclass (SignalConnectMetaClass) does the rest of the magic. """ - __metaclass__ = SignalConnectMetaClass signal = Signal(providing_args=['request']) headline = None default_weight = 0 diff --git a/openslides/utils/plugins.py b/openslides/utils/plugins.py index aa4185794..fd470dcc8 100644 --- a/openslides/utils/plugins.py +++ b/openslides/utils/plugins.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import os import pkgutil import sys diff --git a/openslides/utils/settings.py.tpl b/openslides/utils/settings.py.tpl index 10ad6dbb9..badcad0ff 100644 --- a/openslides/utils/settings.py.tpl +++ b/openslides/utils/settings.py.tpl @@ -42,8 +42,8 @@ HAYSTACK_CONNECTIONS['default']['PATH'] = os.path.join(OPENSLIDES_USER_DATA_PATH TEMPLATE_DIRS = ( os.path.join(OPENSLIDES_USER_DATA_PATH, 'templates'), - filesystem2unicode(os.path.join(SITE_ROOT, 'templates'))) + os.path.join(SITE_ROOT, 'templates')) STATICFILES_DIRS = ( os.path.join(OPENSLIDES_USER_DATA_PATH, 'static'), - filesystem2unicode(os.path.join(SITE_ROOT, 'static'))) + os.path.join(SITE_ROOT, 'static')) diff --git a/openslides/utils/signals.py b/openslides/utils/signals.py index 3c06db49f..cbe71c1f6 100644 --- a/openslides/utils/signals.py +++ b/openslides/utils/signals.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.dispatch import Signal diff --git a/openslides/utils/test.py b/openslides/utils/test.py index b8d79a33b..7fecf094d 100644 --- a/openslides/utils/test.py +++ b/openslides/utils/test.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.core.management import call_command from django.test import TestCase as _TestCase diff --git a/openslides/utils/tornado_webserver.py b/openslides/utils/tornado_webserver.py index 2b4ff9092..2df4a1b82 100644 --- a/openslides/utils/tornado_webserver.py +++ b/openslides/utils/tornado_webserver.py @@ -1,8 +1,6 @@ -# -*- coding: utf-8 -*- - import os import posixpath -from urllib import unquote +from urllib.parse import unquote from django.conf import settings from django.core.handlers.wsgi import WSGIHandler as Django_WSGIHandler @@ -27,7 +25,7 @@ class DjangoStaticFileHandler(StaticFileHandler): """Overwrite some attributes.""" # NOTE: root is never actually used and default_filename is not # supported (must always be None) - self.root = u'' + self.root = '' self.default_filename = None @classmethod @@ -77,7 +75,8 @@ def run_tornado(addr, port): url_string = _("the machine's local ip address") else: url_string = 'http://%s:%s' % (addr, port) - print _("Starting OpenSlides' tornado webserver listening to %(url_string)s") % {'url_string': url_string} + # TODO: don't use print, use django logging + print(_("Starting OpenSlides' tornado webserver listening to %(url_string)s") % {'url_string': url_string}) # Setup WSGIContainer app = WSGIContainer(Django_WSGIHandler()) diff --git a/openslides/utils/utils.py b/openslides/utils/utils.py index d509c7a41..5bf3859b7 100644 --- a/openslides/utils/utils.py +++ b/openslides/utils/utils.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import difflib import roman diff --git a/openslides/utils/views.py b/openslides/utils/views.py index 6bf5b983e..7a9f92b02 100644 --- a/openslides/utils/views.py +++ b/openslides/utils/views.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- - import json -from cStringIO import StringIO +from io import BytesIO from django.conf import settings from django.contrib import messages @@ -352,7 +350,7 @@ class QuestionView(RedirectView): """ Returns the question. """ - return unicode(self.question_message) + return str(self.question_message) def get_answer_options(self): """ @@ -369,7 +367,7 @@ class QuestionView(RedirectView): """ option_fields = "\n".join([ '' - % (option[0], unicode(option[1])) + % (option[0], str(option[1])) for option in self.get_answer_options()]) messages.warning( self.request, @@ -546,7 +544,7 @@ class PDFView(PermissionMixin, View): def get_document_title(self): if self.document_title: - return unicode(self.document_title) + return str(self.document_title) else: return '' @@ -562,10 +560,10 @@ class PDFView(PermissionMixin, View): def render_to_response(self, filename): response = HttpResponse(content_type='application/pdf') - filename = u'filename=%s.pdf;' % self.get_filename() + filename = 'filename=%s.pdf;' % self.get_filename() response['Content-Disposition'] = filename.encode('utf-8') - buffer = StringIO() + buffer = BytesIO() pdf_document = self.get_template(buffer) pdf_document.title = self.get_document_title() story = [Spacer(1, self.get_top_space() * cm)] diff --git a/openslides/utils/widgets.py b/openslides/utils/widgets.py index 115c49a83..61c662341 100644 --- a/openslides/utils/widgets.py +++ b/openslides/utils/widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.core.urlresolvers import reverse from django.dispatch import Signal from django.template import RequestContext @@ -8,14 +6,14 @@ from django.template.loader import render_to_string from .dispatch import SignalConnectMetaClass -class Widget(object): +class Widget(object, metaclass=SignalConnectMetaClass): """ Base class for a widget for the dashboard. Every app which wants to add widgets to the dashboard has to create a - widget class subclassing from this base class. The name attribute has to - be set. It has to be unique. The __metaclass__ attribute - (SignalConnectMetaClass) does the rest of the magic. + widget class subclassing from this base class. The name attribute has to be + set. It has to be unique. The metaclass (SignalConnectMetaClass) does the + rest of the magic. For the appearance of the widget there are some attributes and methods like verbose_name, required_permission, default_column, default_weight, @@ -25,7 +23,6 @@ class Widget(object): get_icon_css_class, get_url_for_more, get_stylesheets and get_javascript_files. Most of them are optional. """ - __metaclass__ = SignalConnectMetaClass signal = Signal(providing_args=['request']) name = None verbose_name = None @@ -53,8 +50,8 @@ class Widget(object): def __repr__(self): return repr(self.get_verbose_name()) - def __unicode__(self): - return unicode(self.get_verbose_name()) + def __str__(self): + return str(self.get_verbose_name()) @classmethod def get_dispatch_uid(cls): diff --git a/requirements.txt b/requirements.txt index 002e67433..38f1e8314 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,10 +2,8 @@ -r requirements_production.txt # Requirements for development and tests in alphabetical order -Fabric==1.8.3 coverage==3.7.1 flake8==2.1.0 -mock==1.0.1 # Requirements for OpenSlides handbook/documentation in alphabetical order Sphinx==1.2.2 diff --git a/requirements_production.txt b/requirements_production.txt index 87adfc1b8..f373f58ba 100644 --- a/requirements_production.txt +++ b/requirements_production.txt @@ -1,18 +1,16 @@ # Requirements for OpenSlides in production in alphabetical order -Django>=1.5,<1.7 -beautifulsoup4>=4.3,<4.4 -bleach>=1.2,<1.5 -django-ckeditor-updated>=4.2,<4.3 +Django>=1.6,<1.7 +beautifulsoup4>=4.1,<4.4 +bleach>=1.4,<1.5 +django-ckeditor-updated>=4.2.3,<4.3 django-haystack>=2.1,<2.2 django-mptt>=0.6,<0.7 -jsonfield>=0.9,<0.10 -natsort>=3.2,<3.3 -reportlab>=2.7,<2.8 +jsonfield>=0.9.19,<0.10 +natsort>=3.2,<3.5 +reportlab>=3.0,<3.2 roman>=2.0,<2.1 -setuptools>=2.1,<3.7 +setuptools>=2.1,<5.8 sockjs-tornado>=1.0,<1.1 -tornado>=3.1,<3.3 +tornado>=2.1,<4.1 whoosh>=2.5.6,<2.6 -# For Python 2.6 support -argparse==1.2.1 diff --git a/setup.py b/setup.py index 5e007b018..cf2b84e8a 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import re import sys @@ -32,7 +31,7 @@ setup( 'Framework :: Django', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', ], license='MIT', packages=find_packages(exclude=['tests', 'tests.*']), diff --git a/tests/account/test_widgets.py b/tests/account/test_widgets.py index 95bb24f15..6abf27d16 100644 --- a/tests/account/test_widgets.py +++ b/tests/account/test_widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.test.client import Client from openslides.config.api import config diff --git a/tests/agenda/models.py b/tests/agenda/models.py index bb576ed47..1df6aec8b 100644 --- a/tests/agenda/models.py +++ b/tests/agenda/models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.db import models from openslides.projector.models import SlideMixin diff --git a/tests/agenda/test_list_of_speakers.py b/tests/agenda/test_list_of_speakers.py index eed2be788..2efa015e5 100644 --- a/tests/agenda/test_list_of_speakers.py +++ b/tests/agenda/test_list_of_speakers.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- +from unittest.mock import patch, MagicMock from django.contrib.auth.models import Permission from django.test.client import Client -from mock import patch, MagicMock from openslides.agenda.models import Item, Speaker from openslides.agenda.signals import agenda_list_of_speakers diff --git a/tests/agenda/tests.py b/tests/agenda/tests.py index f67eeda6f..f5de071d4 100644 --- a/tests/agenda/tests.py +++ b/tests/agenda/tests.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- +from unittest.mock import patch from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType from django.core.files.uploadedfile import SimpleUploadedFile from django.test.client import Client -from mock import patch from openslides.agenda.models import Item from openslides.agenda.slides import agenda_slide @@ -317,12 +316,16 @@ class ViewTest(TestCase): 'Organizational items can not have agenda items as child elements.') def test_csv_import(self): - item_number = Item.objects.all().count() + """ + Test to upload a csv file. + """ new_csv_file = SimpleUploadedFile( name='new_csv_file.csv', - content='Title,text,duration\nTitle thei5KieK6ohphuilahs,Text Chai1ioWae3ASh0Eloh1,42\n,Bad line\n') + content=bytes('Title,text,duration\nTitle thei5KieK6ohphuilahs,Text Chai1ioWae3ASh0Eloh1,42\n,Bad line\n', 'UTF-8')) + self.adminClient.post('/agenda/csv_import/', {'csvfile': new_csv_file}) - self.assertEqual(Item.objects.all().count(), item_number + 1) + + self.assertEqual(Item.objects.all().count(), 3) item = Item.objects.get(pk=3) self.assertEqual(item.title, 'Title thei5KieK6ohphuilahs') self.assertEqual(item.text, 'Text Chai1ioWae3ASh0Eloh1') diff --git a/tests/assignment/test_models.py b/tests/assignment/test_models.py index c79db6717..92b2146dd 100644 --- a/tests/assignment/test_models.py +++ b/tests/assignment/test_models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.test.client import Client from openslides.agenda.models import Item, Speaker diff --git a/tests/assignment/test_pdf.py b/tests/assignment/test_pdf.py index 90b3f92be..88ea6bc00 100644 --- a/tests/assignment/test_pdf.py +++ b/tests/assignment/test_pdf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.test.client import Client from openslides.assignment.models import Assignment diff --git a/tests/assignment/test_views.py b/tests/assignment/test_views.py index 2b2358b44..d4ef3660e 100644 --- a/tests/assignment/test_views.py +++ b/tests/assignment/test_views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.test.client import Client from openslides.assignment.models import Assignment, AssignmentPoll @@ -109,3 +107,25 @@ class TestAssignmentPollCreateView(TestCase): self.assertEqual(poll.assignment, self.assignment) self.assertEqual(poll.assignmentoption_set.count(), 1) self.assertTrue(poll.yesnoabstain) + + +class TestAssignmentPollPdfView(TestCase): + """ + Tests the creation of the assignment poll pdf + """ + + def test_assignment_create_poll_pdf(self): + # Create a assignment with a poll + admin = User.objects.get(pk=1) + assignment = Assignment.objects.create(name='assignment1', posts=1) + assignment.run(admin, admin) + assignment.set_status('vot') + assignment.gen_poll() + client = Client() + client.login(username='admin', password='admin') + + # request the pdf + response = client.get('/assignment/poll/1/print/') + + # test the response + self.assertEqual(response.status_code, 200) diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 9a20553fc..0634b2840 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -1,11 +1,12 @@ -# -*- coding: utf-8 -*- +import re +from unittest.mock import patch from django import forms from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType from django.dispatch import receiver from django.test.client import Client -from mock import patch + from openslides.config.api import (config, ConfigCollection, ConfigGroup, ConfigGroupedCollection, ConfigVariable) @@ -75,6 +76,7 @@ class HandleConfigTest(TestCase): Tests that the special callback is called and raises a special message. """ + # TODO: use right exception self.assertRaisesMessage( Exception, 'Change callback dhcnfg34dlg06kdg successfully called.', @@ -190,42 +192,36 @@ class ConfigFormTest(TestCase): self.assertNotContains(response=response, text='Ho5iengaoon5Hoht', status_code=200) def test_improperly_configured_config_view(self): - from openslides.config import urls + """ + Tests that a ConfigCollection object without an url raises ConfigError + when is_shown() is called. + """ collection = ConfigCollection( title='Only a small title but no url ci6xahb8Chula0Thesho', variables=(ConfigVariable(name='some_var_paiji9theiW8ooXivae6', default_value='', form_field=forms.CharField()),)) - def setup_bad_config_view_one(sender, **kwargs): - return collection - - config_signal.connect(setup_bad_config_view_one, dispatch_uid='setup_bad_config_view_one_for_testing') self.assertRaisesMessage( ConfigError, 'The config collection %s must have a title and an url attribute.' % repr(collection), - reload, - urls) - config_signal.disconnect(setup_bad_config_view_one, dispatch_uid='setup_bad_config_view_one_for_testing') + collection.is_shown) def test_improperly_configured_config_view_two(self): - from openslides.config import urls + """ + Tests that a ConfigCollection object without a title raises ConfigError + when is_shown() is called. + """ collection = ConfigCollection( url='only_url_ureiraeY1Oochuad7xei', variables=(ConfigVariable(name='some_var_vuuC6eiXeiyae3ik4gie', default_value='', form_field=forms.CharField()),)) - def setup_bad_config_view_two(sender, **kwargs): - return collection - - config_signal.connect(setup_bad_config_view_two, dispatch_uid='setup_bad_config_view_twoe_for_testing') self.assertRaisesMessage( ConfigError, 'The config collection %s must have a title and an url attribute.' % repr(collection), - reload, - urls) - config_signal.disconnect(setup_bad_config_view_two, dispatch_uid='setup_bad_config_view_twoe_for_testing') + collection.is_shown) def test_extra_stylefiles(self): response = self.client_manager.get('/config/testgroupedpage1/') @@ -274,9 +270,9 @@ class ConfigWeightTest(TestCase): def test_order_of_config_collections_on_view(self): response = self.client_manager.get('/config/testgroupedpage1/') - import re - m1 = re.search('\s*Config vars for testing 1\s*', response.content) - m2 = re.search('\s*Config vars for testing 2\s*', response.content) + content = response.content.decode('utf-8') + m1 = re.search('\s*Config vars for testing 1\s*', content) + m2 = re.search('\s*Config vars for testing 2\s*', content) self.assertGreater(m1.start(), m2.start()) diff --git a/tests/core/test_template_tags_filters.py b/tests/core/test_template_tags_filters.py index 3524b955d..e8eec4787 100644 --- a/tests/core/test_template_tags_filters.py +++ b/tests/core/test_template_tags_filters.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.template import Context, Template from openslides.config.api import config diff --git a/tests/core/test_views.py b/tests/core/test_views.py index eb7a1daf2..2321ff164 100644 --- a/tests/core/test_views.py +++ b/tests/core/test_views.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- +from unittest.mock import MagicMock, patch from django.test.client import Client, RequestFactory -from mock import MagicMock, patch from openslides import get_version from openslides.agenda.models import Item diff --git a/tests/forms/test_clean_html.py b/tests/forms/test_clean_html.py index d942b46d8..886cd17fb 100644 --- a/tests/forms/test_clean_html.py +++ b/tests/forms/test_clean_html.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from openslides.utils.forms import CleanHtmlFormMixin diff --git a/tests/mediafile/tests.py b/tests/mediafile/tests.py index 507c4691a..54185ffa9 100644 --- a/tests/mediafile/tests.py +++ b/tests/mediafile/tests.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import os import tempfile @@ -41,8 +39,8 @@ class MediafileTest(TestCase): def tearDown(self): self.object.mediafile.delete() - def test_unicode(self): - self.assertEqual(self.object.__unicode__(), 'Title File 1') + def test_str(self): + self.assertEqual(str(self.object), 'Title File 1') def test_absolute_url(self): self.assertEqual(self.object.get_absolute_url(), '/mediafile/1/edit/') @@ -64,7 +62,7 @@ class MediafileTest(TestCase): 'client_normal_user': client_normal_user} def test_see_mediafilelist(self): - for client in self.login_clients().itervalues(): + for client in self.login_clients().values(): response = client.get('/mediafile/') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'mediafile/mediafile_list.html') @@ -90,7 +88,7 @@ class MediafileTest(TestCase): def test_upload_mediafile_post_request(self): # Test first user client_1 = self.login_clients()['client_manager'] - new_file_1 = SimpleUploadedFile(name='new_test_file.txt', content='test content hello manager') + new_file_1 = SimpleUploadedFile(name='new_test_file.txt', content=bytes('test content hello manager', 'UTF-8')) response_1 = client_1.post('/mediafile/new/', {'title': 'new_test_file_title_1', 'mediafile': new_file_1, @@ -105,7 +103,7 @@ class MediafileTest(TestCase): # Test second user client_2 = self.login_clients()['client_vip_user'] - new_file_2 = SimpleUploadedFile(name='new_test_file.txt', content='test content hello vip_user') + new_file_2 = SimpleUploadedFile(name='new_test_file.txt', content=bytes('test content hello vip_user', 'UTF-8')) response_2 = client_2.post('/mediafile/new/', {'title': 'new_test_file_title_2', 'mediafile': new_file_2}) @@ -121,7 +119,7 @@ class MediafileTest(TestCase): # Test third user client_3 = self.login_clients()['client_normal_user'] - new_file_3 = SimpleUploadedFile(name='new_test_file.txt', content='test content hello vip_user') + new_file_3 = SimpleUploadedFile(name='new_test_file.txt', content=bytes('test content hello vip_user', 'UTF-8')) response_3 = client_3.post('/mediafile/new/', {'title': 'new_test_file_title_2', 'mediafile': new_file_3}) @@ -156,7 +154,7 @@ class MediafileTest(TestCase): os.close(tmpfile_no) object_2 = Mediafile.objects.create(title='Title File 2', mediafile=mediafile_2_path, uploader=self.vip_user) client_1 = self.login_clients()['client_manager'] - new_file_1 = SimpleUploadedFile(name='new_test_file.txt', content='test content hello manager') + new_file_1 = SimpleUploadedFile(name='new_test_file.txt', content=bytes('test content hello manager', 'UTF-8')) response_1 = client_1.post('/mediafile/2/edit/', {'title': 'new_test_file_title_1', 'mediafile': new_file_1, @@ -174,7 +172,7 @@ class MediafileTest(TestCase): os.close(tmpfile_no) object_2 = Mediafile.objects.create(title='Title File 2b', mediafile=mediafile_2_path, uploader=self.vip_user) client = self.login_clients()['client_vip_user'] - new_file_1 = SimpleUploadedFile(name='new_test_file.txt', content='test content hello vip user') + new_file_1 = SimpleUploadedFile(name='new_test_file.txt', content=bytes('test content hello vip user', 'UTF-8')) response_1 = client.post('/mediafile/2/edit/', {'title': 'new_test_file_title_2b', 'mediafile': new_file_1}) @@ -188,7 +186,7 @@ class MediafileTest(TestCase): def test_edit_mediafile_post_request_another_file(self): client = self.login_clients()['client_vip_user'] - new_file_1 = SimpleUploadedFile(name='new_test_file.txt', content='test content hello vip user') + new_file_1 = SimpleUploadedFile(name='new_test_file.txt', content=bytes('test content hello vip user', 'UTF-8')) response = client.post('/mediafile/1/edit/', {'title': 'new_test_file_title_2c', 'mediafile': new_file_1}) @@ -249,11 +247,11 @@ class MediafileTest(TestCase): self.assertEqual(object_4.get_filesize(), '< 1 kB') with open(object_4.mediafile.path, 'wb') as bigfile: bigfile.seek(2047) - bigfile.write('0') + bigfile.write(b'0') self.assertEqual(object_4.get_filesize(), '2 kB') with open(object_4.mediafile.path, 'wb') as bigfile: bigfile.seek(1048575) - bigfile.write('0') + bigfile.write(b'0') self.assertEqual(object_4.get_filesize(), '1 MB') os.remove(mediafile_4_path) self.assertEqual(object_4.get_filesize(), 'unknown') diff --git a/tests/motion/test_csv_import.py b/tests/motion/test_csv_import.py index 4efd55a90..4975495a7 100644 --- a/tests/motion/test_csv_import.py +++ b/tests/motion/test_csv_import.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- - import os -import StringIO +from io import BytesIO from django.test.client import Client @@ -41,7 +39,7 @@ class CSVImport(TestCase): csv_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'extras', 'csv-examples') self.assertEqual(Motion.objects.count(), 0) - with open(csv_dir + '/motions-demo_de.csv') as f: + with open(csv_dir + '/motions-demo_de.csv', 'rb') as f: success_message, warning_message, error_message = import_motions( csvfile=f, default_submitter=self.normal_user.person_id, override=False, importing_person=self.admin) self.assertEqual(Motion.objects.count(), 11) @@ -73,21 +71,18 @@ class CSVImport(TestCase): self.assertTrue('Several suitable categories found.' in warning_message) def test_malformed_file(self): - csv_file = StringIO.StringIO() - csv_file.write('Header\nMalformed data,\n,Title,Text,,,\n') + csv_file = BytesIO() + csv_file.write(bytes('Header\nMalformed data,\n,Title,Text,,,\n', 'utf8')) success_message, warning_message, error_message = import_motions( csvfile=csv_file, default_submitter=self.normal_user.person_id, override=False) self.assertEqual(success_message, '') self.assertTrue('Line is malformed.' in error_message) def test_wrong_encoding(self): - csv_file = StringIO.StringIO() - text = u'Müller'.encode('iso-8859-15') - csv_file.write(text) - csv_file.seek(0) + csv_file = BytesIO(bytes('Müller', 'iso-8859-15')) success_message, warning_message, error_message = import_motions( csvfile=csv_file, default_submitter=self.normal_user.person_id, override=False) self.assertEqual(success_message, '') - self.assertTrue('Import file has wrong character encoding, only UTF-8 is supported!' in error_message) + self.assertIn('Import file has wrong character encoding, only UTF-8 is supported!', error_message) diff --git a/tests/motion/test_models.py b/tests/motion/test_models.py index 1e6d30ec1..54667c3f8 100644 --- a/tests/motion/test_models.py +++ b/tests/motion/test_models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.config.api import config from openslides.motion.exceptions import WorkflowError from openslides.motion.models import Motion, State, Workflow diff --git a/tests/motion/test_pdf.py b/tests/motion/test_pdf.py index 7becbd12c..eea2e6e9c 100644 --- a/tests/motion/test_pdf.py +++ b/tests/motion/test_pdf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.test.client import Client from openslides.motion.models import Motion from openslides.participant.models import User diff --git a/tests/motion/test_views.py b/tests/motion/test_views.py index 8b47f0310..faf4ba469 100644 --- a/tests/motion/test_views.py +++ b/tests/motion/test_views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import os import tempfile diff --git a/tests/participant/test_csv.py b/tests/participant/test_csv.py new file mode 100644 index 000000000..9692f6d9f --- /dev/null +++ b/tests/participant/test_csv.py @@ -0,0 +1,23 @@ +from io import BytesIO +from textwrap import dedent + +from openslides.utils.test import TestCase +from openslides.participant.csv_import import import_users + + +class TestCSVImport(TestCase): + def test_csv_import(self): + # Create CSV-File + csv_file = BytesIO(bytes(dedent(""" + "Title";"First Name";"Last Name";"Gender";"Email";"Group id";"Structure Level";"Committee";"About me";"Comment";"Is active" + ;"Fred";"Nurk";"male";;3;"Australia";;;;1 + ;"Jan";"Jansen";"male";;3;"Belgium";;;;1 + ;"Juan";"Pérez";"male";;3;"Chile";;;;1 + """.strip()), 'utf8')) + + # Import file + success_message, warning_message, error_message = import_users(csvfile=csv_file) + + # Test result + self.assertEqual(warning_message, '') + self.assertEqual(error_message, '') diff --git a/tests/participant/test_models.py b/tests/participant/test_models.py index 9b2a0ae0d..6e6653699 100644 --- a/tests/participant/test_models.py +++ b/tests/participant/test_models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.participant.api import gen_password, gen_username from openslides.participant.models import Group, User from openslides.utils.person import get_person, Persons @@ -21,16 +19,16 @@ class UserTest(TestCase): self.assertEqual(self.django_user1.user, self.user1) self.assertEqual(self.django_user1, self.user1.django_user) - def test_repr(self): - self.assertEqual(unicode(self.user1), 'Max Mustermann') + def test_str(self): + self.assertEqual(str(self.user1), 'Max Mustermann') def test_name_suffix(self): self.user1.structure_level = u'München' self.user1.save() - self.assertEqual(unicode(self.user1), u'Max Mustermann (München)') + self.assertEqual(str(self.user1), u'Max Mustermann (München)') def test_reset_password(self): - self.assertIsInstance(self.user1.default_password, basestring) + self.assertIsInstance(self.user1.default_password, str) self.assertEqual(len(self.user1.default_password), 8) self.user1.set_unusable_password() self.assertFalse(self.user1.check_password(self.user1.default_password)) @@ -78,7 +76,7 @@ class DefaultGroups(TestCase): (3, 'Delegates'), (4, 'Staff')) for pk, name in default_groups: - self.assertEquals(Group.objects.get(pk=pk).name, name) + self.assertEqual(Group.objects.get(pk=pk).name, name) def test_default_perms_anonymous(self): anonymous = Group.objects.get(pk=1) diff --git a/tests/participant/test_umlaut_user.py b/tests/participant/test_umlaut_user.py index a5201fe83..0b9a5de58 100644 --- a/tests/participant/test_umlaut_user.py +++ b/tests/participant/test_umlaut_user.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.test.client import Client from django.test.utils import override_settings diff --git a/tests/participant/test_utils.py b/tests/participant/test_utils.py index cb6d2433d..c960438e5 100644 --- a/tests/participant/test_utils.py +++ b/tests/participant/test_utils.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.participant.api import gen_username from openslides.participant.models import User from openslides.utils.test import TestCase diff --git a/tests/participant/test_views.py b/tests/participant/test_views.py index 8ed721e85..0590c94a9 100644 --- a/tests/participant/test_views.py +++ b/tests/participant/test_views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import re from django.contrib.auth.models import Permission @@ -78,10 +76,9 @@ class GroupViews(TestCase): self.client.login(username='loginusername', password='default') def test_detail(self): - self.assertFalse(config['participant_sort_users_by_first_name']) response = self.client.get('/participant/group/3/') pattern = r'admins_first_name Administrator|aWei4ien6Se0vie0xeiv uquahx3Wohtieph9baer' - match = re.findall(pattern, response.content) + match = re.findall(pattern, response.content.decode('utf8')) self.assertEqual(match[0], 'admins_first_name Administrator') self.assertEqual(match[1], 'aWei4ien6Se0vie0xeiv uquahx3Wohtieph9baer') @@ -89,7 +86,7 @@ class GroupViews(TestCase): self.assertTrue(config['participant_sort_users_by_first_name']) response = self.client.get('/participant/group/3/') pattern = r'admins_first_name Administrator|aWei4ien6Se0vie0xeiv uquahx3Wohtieph9baer' - match = re.findall(pattern, response.content) + match = re.findall(pattern, response.content.decode('utf8')) self.assertEqual(match[1], 'admins_first_name Administrator') self.assertEqual(match[0], 'aWei4ien6Se0vie0xeiv uquahx3Wohtieph9baer') diff --git a/tests/person_api/__init__.py b/tests/person_api/__init__.py index d6501bfc2..faefc4665 100644 --- a/tests/person_api/__init__.py +++ b/tests/person_api/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - VERSION = (9999, 9999, 9999, 'alpha', 1) diff --git a/tests/person_api/tests.py b/tests/person_api/tests.py index c1eb5ff56..21aa1d2d3 100644 --- a/tests/person_api/tests.py +++ b/tests/person_api/tests.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib.auth.models import AnonymousUser from openslides.utils.person.api import get_person @@ -24,15 +22,15 @@ class PersonTest(TestCase): self.assertEqual(TestModel.objects.get(pk=test_object.pk).person, self.person1) def test_save_anonymous_user_in_person_field(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( AttributeError, 'An AnonymousUser can not be saved into the database.'): TestModel.objects.create(person=AnonymousUser()) def test_save_unsupported_object_in_person_field(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( AttributeError, - 'You can not save \'\' into a person field.'): + 'You can not save \'\' into a person field.'): TestModel.objects.create(person=5) def test_get_absolute_url_with_deleted_person(self): @@ -41,5 +39,5 @@ class PersonTest(TestCase): person_id = person2.person_id self.assertEqual(get_person(person_id).get_absolute_url(), 'absolute_url_of_test_person') person2.delete() - with self.assertRaisesRegexp(ValueError, 'This person object has no url.'): + with self.assertRaisesRegex(ValueError, 'This person object has no url.'): get_person(person_id).get_absolute_url() diff --git a/tests/plugin_api/test_plugin_api.py b/tests/plugin_api/test_plugin_api.py index 11c74e974..fc4b4b08c 100644 --- a/tests/plugin_api/test_plugin_api.py +++ b/tests/plugin_api/test_plugin_api.py @@ -1,15 +1,14 @@ -# -*- coding: utf-8 -*- +from imp import reload from django.test.client import Client from django.test.utils import override_settings +from django.core.urlresolvers import clear_url_caches from openslides.utils.test import TestCase @override_settings(INSTALLED_PLUGINS=('tests.plugin_api.test_plugin_one',)) class TestPluginOne(TestCase): - urls = 'tests.plugin_api.urls' # Use reloaded urlpatterns for this TestCase - def setUp(self): self.admin_client = Client() self.admin_client.login(username='admin', password='admin') @@ -21,6 +20,9 @@ class TestPluginOne(TestCase): self.assertContains(response, '– Version test_version_string_MoHonepahfofiree6Iej') def test_url_patterns(self): + from openslides import urls + reload(urls) + clear_url_caches() response = self.admin_client.get('/test_plugin_one_url_Eexea4nie1fexaax3oX7/') self.assertRedirects(response, '/version/') diff --git a/tests/plugin_api/test_plugin_one/__init__.py b/tests/plugin_api/test_plugin_one/__init__.py index ef3c9b497..ef7772481 100644 --- a/tests/plugin_api/test_plugin_one/__init__.py +++ b/tests/plugin_api/test_plugin_one/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf.urls import patterns, url from django.views.generic import RedirectView diff --git a/tests/plugin_api/urls.py b/tests/plugin_api/urls.py deleted file mode 100644 index c1f9884e1..000000000 --- a/tests/plugin_api/urls.py +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- - -from openslides import urls - -reload(urls) - -urlpatterns = urls.urlpatterns diff --git a/tests/projector/test_api.py b/tests/projector/test_api.py index ea0b00a7a..9373ce611 100644 --- a/tests/projector/test_api.py +++ b/tests/projector/test_api.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- - -from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from openslides.projector import api as projector_api from openslides.utils.test import TestCase diff --git a/tests/projector/test_overlays.py b/tests/projector/test_overlays.py index c9e8fdddf..1638b7789 100644 --- a/tests/projector/test_overlays.py +++ b/tests/projector/test_overlays.py @@ -1,8 +1,6 @@ -# -*- coding: utf-8 -*- - import warnings -from mock import MagicMock +from unittest.mock import MagicMock from openslides.projector.projector import Overlay from openslides.utils.test import TestCase @@ -18,4 +16,4 @@ class OverlayTest(TestCase): with warnings.catch_warnings(record=True) as warning: overlay.get_projector_html() - self.assertEqual(warning[0].message.message, 'Exception in overlay "test_overlay": no good error') + self.assertEqual(str(warning[0].message), 'Exception in overlay "test_overlay": no good error') diff --git a/tests/projector/test_signals.py b/tests/projector/test_signals.py index b78edd189..7e74c094e 100644 --- a/tests/projector/test_signals.py +++ b/tests/projector/test_signals.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.projector.signals import countdown from openslides.utils.test import TestCase @@ -15,7 +13,7 @@ class CountdownTest(TestCase): self.assertIsInstance(test_value, dict) self.assertEqual( - test_value.keys(), + list(test_value.keys()), ['load_file', 'projector_countdown_start', 'projector_countdown_duration', 'projector_countdown_pause', 'projector_countdown_state', 'call']) diff --git a/tests/projector/test_views.py b/tests/projector/test_views.py index 250a59c9e..94d993484 100644 --- a/tests/projector/test_views.py +++ b/tests/projector/test_views.py @@ -1,8 +1,6 @@ -# -*- coding: utf-8 -*- - from django.contrib.auth.models import AnonymousUser from django.test.client import Client, RequestFactory -from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from openslides.config.api import config from openslides.projector import views diff --git a/tests/settings.py b/tests/settings.py index f9b58b5ac..daa1b3d6e 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Settings file for OpenSlides' tests # @@ -42,11 +41,11 @@ HAYSTACK_CONNECTIONS['default']['STORAGE'] = 'ram' TEMPLATE_DIRS = ( os.path.join(OPENSLIDES_USER_DATA_PATH, 'templates'), - filesystem2unicode(os.path.join(SITE_ROOT, 'templates'))) + os.path.join(SITE_ROOT, 'templates')) STATICFILES_DIRS = ( os.path.join(OPENSLIDES_USER_DATA_PATH, 'static'), - filesystem2unicode(os.path.join(SITE_ROOT, 'static'))) + os.path.join(SITE_ROOT, 'static')) # Use a faster passwort hasher PASSWORD_HASHERS = ( diff --git a/tests/test_init.py b/tests/test_init.py index 72202b0c7..dd669323d 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -1,8 +1,5 @@ -# -*- coding: utf-8 -*- - -import tempfile - -from mock import MagicMock, patch +from io import StringIO +from unittest.mock import MagicMock, patch from openslides import get_git_commit_id, get_version from openslides.utils.test import TestCase @@ -21,28 +18,27 @@ class InitTest(TestCase): self.assertEqual(get_version(version=(2, 5, 3, 'alpha', 0), release=True), '2.5.3a0') self.assertEqual(get_version(version=(2, 5, 3, 'final', 0), release=True), '2.5.3') - def test_get_git_commit_id_general(self): - """ - Tests the lenght of the git commit id. - """ - git_commit_id = get_git_commit_id() - if not git_commit_id == 'unknown': - self.assertEqual(len(git_commit_id), 40) - - @patch('__builtin__.open', MagicMock(side_effect=IOError)) + @patch('builtins.open', MagicMock(side_effect=IOError)) def test_get_commit_id_unknown(self): """ Tests unknown git commit id. """ self.assertEqual(get_git_commit_id(), 'unknown') - @patch('__builtin__.open') + @patch('builtins.open') def test_get_commit_id_without_ref(self, mock): """ Tests reading the content of the git_commit_id file. """ - with tempfile.TemporaryFile() as git_file: - git_file.write('test_id_ahyuGo7yefai7Nai') - git_file.seek(0) - mock.return_value = git_file - self.assertEqual(get_git_commit_id(), 'test_id_ahyuGo7yefai7Nai') + mock.return_value = StringIO('test_id_ahyuGo7yefai7Nai') + self.assertEqual(get_git_commit_id(), 'test_id_ahyuGo7yefai7Nai') + + @patch('builtins.open') + def test_get_git_commit_id_general(self, mock): + """ + Tests reading the content of a git reference (e.g. tags or branches). + """ + mock.side_effect = (StringIO('ref: asdfgqwertfdfhiwer'), StringIO('TestOpenSlides-3.1415')) + git_commit_id = get_git_commit_id() + if not git_commit_id == 'unknown': + self.assertEqual(git_commit_id, 'TestOpenSlides-3.1415') diff --git a/tests/utils/test_dispatch.py b/tests/utils/test_dispatch.py index a2bdb4cd8..2350fcc86 100644 --- a/tests/utils/test_dispatch.py +++ b/tests/utils/test_dispatch.py @@ -1,15 +1,13 @@ -# -*- coding: utf-8 -*- +from unittest.mock import patch from django.dispatch import Signal from django.test.client import RequestFactory -from mock import patch from openslides.utils.dispatch import SignalConnectMetaClass from openslides.utils.test import TestCase -class TestBaseOne(object): - __metaclass__ = SignalConnectMetaClass +class TestBaseOne(object, metaclass=SignalConnectMetaClass): signal = Signal() @classmethod @@ -18,8 +16,7 @@ class TestBaseOne(object): return 'test_vieM1eingi6luish5Sei' -class TestBaseTwo(object): - __metaclass__ = SignalConnectMetaClass +class TestBaseTwo(object, metaclass=SignalConnectMetaClass): signal = Signal() @classmethod @@ -46,8 +43,9 @@ class TestSignalConnectMetaClass(TestCase): def test_bad_base_class(self): def wrapper(): - class BadClass1(object): - __metaclass__ = SignalConnectMetaClass + class BadClass1(object, metaclass=SignalConnectMetaClass): + pass + self.assertRaisesMessage( NotImplementedError, 'Your class BadClass1 must have a get_dispatch_uid classmethod.', @@ -55,9 +53,7 @@ class TestSignalConnectMetaClass(TestCase): def test_bad_base_class_without_signal(self): def wrapper(): - class BadClass2(object): - __metaclass__ = SignalConnectMetaClass - + class BadClass2(object, metaclass=SignalConnectMetaClass): @classmethod def get_dispatch_uid(cls): return True diff --git a/tests/utils/test_main.py b/tests/utils/test_main.py index 5ea30bc91..428c55750 100644 --- a/tests/utils/test_main.py +++ b/tests/utils/test_main.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- - import os import sys +from unittest.mock import MagicMock, patch from django.core.exceptions import ImproperlyConfigured -from mock import MagicMock, patch from openslides.__main__ import ( add_general_arguments, diff --git a/tests/utils/test_main_menu.py b/tests/utils/test_main_menu.py index 713627573..d939a4c49 100644 --- a/tests/utils/test_main_menu.py +++ b/tests/utils/test_main_menu.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib.auth.models import AnonymousUser from django.test.client import RequestFactory @@ -33,7 +31,7 @@ class MainMenuEntryObject(TestCase): pattern_name = 'core_version' verbose_name = 'Menu entry for testing gae2thooc4che4thaoNo' - self.assertEqual(unicode(self.get_entry(TestMenuEntryOne)), u'Menu entry for testing gae2thooc4che4thaoNo') + self.assertEqual(str(self.get_entry(TestMenuEntryOne)), 'Menu entry for testing gae2thooc4che4thaoNo') def test_missing_verbose_name(self): class TestMenuEntryBadOne(MainMenuEntry): @@ -41,8 +39,8 @@ class MainMenuEntryObject(TestCase): entry = self.get_entry(TestMenuEntryBadOne) text = ('The main menu entry class TestMenuEntryBadOne must provide a ' - 'verbose_name attribute or override the __unicode__ method.') - self.assertRaisesMessage(NotImplementedError, text, unicode, entry) + 'verbose_name attribute or override the __str__ method.') + self.assertRaisesMessage(NotImplementedError, text, str, entry) def test_missing_pattern_name(self): class TestMenuEntryBadTwo(MainMenuEntry): diff --git a/tests/utils/test_models.py b/tests/utils/test_models.py index 0fb5523b2..fd6ee34cf 100644 --- a/tests/utils/test_models.py +++ b/tests/utils/test_models.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.utils.models import AbsoluteUrlMixin from openslides.utils.test import TestCase diff --git a/tests/utils/test_personal_info.py b/tests/utils/test_personal_info.py index 0909b4714..d9140dc8a 100644 --- a/tests/utils/test_personal_info.py +++ b/tests/utils/test_personal_info.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib.auth.models import AnonymousUser from django.test.client import RequestFactory diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index b5dd3ff56..40433f964 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from openslides.utils.test import TestCase from openslides.utils.utils import html_strong, int_or_none diff --git a/tests/utils/test_views.py b/tests/utils/test_views.py index fe468538c..9efc09b56 100644 --- a/tests/utils/test_views.py +++ b/tests/utils/test_views.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +from unittest.mock import patch from django.contrib.auth.models import AnonymousUser from django.core.exceptions import ImproperlyConfigured @@ -6,7 +6,6 @@ from django.core.urlresolvers import clear_url_caches from django.test import RequestFactory from django.test.client import Client from django.test.utils import override_settings -from mock import patch from openslides.utils import views from openslides.utils.signals import template_manipulation @@ -33,7 +32,7 @@ class LoginMixinTest(ViewTestCase): client.login(username='admin', password='admin') response = client.get('/login_mixin/') self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, 'Well done.') + self.assertEqual(response.content, b'Well done.') class PermissionMixinTest(ViewTestCase): @@ -43,7 +42,7 @@ class PermissionMixinTest(ViewTestCase): # View without required_permission response = client.get('/permission_mixin1/') self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, 'Well done.') + self.assertEqual(response.content, b'Well done.') # View with required_permission without login response = client.get('/permission_mixin2/') @@ -65,7 +64,7 @@ class AjaxMixinTest(ViewTestCase): view = test_views.AjaxMixinView() ajax_get = view.ajax_get response = ajax_get(self.rf.get('/', {})) - self.assertEqual(response.content, '{"new_context": "newer_context"}') + self.assertEqual(response.content, b'{"new_context": "newer_context"}') def test_get_ajax_context(self): get_ajax_context = test_views.AjaxMixinView().get_ajax_context @@ -165,8 +164,7 @@ class QuestionViewTest(ViewTestCase): view.question_message = 'new_question' self.assertEqual(get_question_message(), 'new_question') - # Make sure it is unicode, so ugettext_lazy can work - self.assertIsInstance(get_question_message(), unicode) + self.assertIsInstance(get_question_message(), str) def test_get_answer_options(self): view = views.QuestionView() diff --git a/tests/utils/test_widgets.py b/tests/utils/test_widgets.py index 5f0eb6130..3348b07cb 100644 --- a/tests/utils/test_widgets.py +++ b/tests/utils/test_widgets.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.contrib.auth.models import AnonymousUser from django.test.client import RequestFactory diff --git a/tests/utils/urls.py b/tests/utils/urls.py index c31d30303..66c9d434f 100644 --- a/tests/utils/urls.py +++ b/tests/utils/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf.urls import patterns, url from openslides.urls import urlpatterns