diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index 4ce3e34..09468e2 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -35,8 +35,8 @@ class CodeMirrorTextArea(forms.Textarea): def render(self, name, value, attrs=None, renderer=None): result = [] result.append( - super(CodeMirrorTextArea, self).render(name, value, attrs)) - result.append(u""" + super().render(name, value, attrs)) + result.append(""" """ % dict(media_prefix=settings.DBTEMPLATES_MEDIA_PREFIX, name=name)) - return mark_safe(u"".join(result)) + return mark_safe("".join(result)) if settings.DBTEMPLATES_USE_CODEMIRROR: @@ -144,7 +144,7 @@ class TemplateAdmin(TemplateModelAdmin): for template in queryset: valid, error = check_template_syntax(template) if not valid: - errors.append('%s: %s' % (template.name, error)) + errors.append('{}: {}'.format(template.name, error)) if errors: count = len(errors) message = ungettext( diff --git a/dbtemplates/loader.py b/dbtemplates/loader.py index 086a38b..d05f97e 100644 --- a/dbtemplates/loader.py +++ b/dbtemplates/loader.py @@ -33,7 +33,7 @@ class Loader(BaseLoader): def _load_and_store_template(self, template_name, cache_key, site, **params): template = Template.objects.get(name__exact=template_name, **params) db = router.db_for_read(Template, instance=template) - display_name = 'dbtemplates:%s:%s:%s' % (db, template_name, site.domain) + display_name = 'dbtemplates:{}:{}:{}'.format(db, template_name, site.domain) return set_and_return(cache_key, template.content, display_name) def _load_template_source(self, template_name, template_dirs=None): diff --git a/dbtemplates/management/commands/check_template_syntax.py b/dbtemplates/management/commands/check_template_syntax.py index c82ea96..235098f 100644 --- a/dbtemplates/management/commands/check_template_syntax.py +++ b/dbtemplates/management/commands/check_template_syntax.py @@ -12,7 +12,7 @@ class Command(BaseCommand): for template in Template.objects.all(): valid, error = check_template_syntax(template) if not valid: - errors.append('%s: %s' % (template.name, error)) + errors.append('{}: {}'.format(template.name, error)) if errors: raise CommandError( 'Some templates contained errors\n%s' % '\n'.join(errors)) diff --git a/dbtemplates/management/commands/sync_templates.py b/dbtemplates/management/commands/sync_templates.py index 7d95429..2c8a6e0 100644 --- a/dbtemplates/management/commands/sync_templates.py +++ b/dbtemplates/management/commands/sync_templates.py @@ -84,7 +84,7 @@ class Command(BaseCommand): "database.\nCreate it with '%s'?" " (y/[n]): """ % (name, path)) if force or confirm.lower().startswith('y'): - with io.open(path, encoding='utf-8') as f: + with open(path, encoding='utf-8') as f: t = Template(name=name, content=f.read()) t.save() t.sites.add(site) @@ -102,7 +102,7 @@ class Command(BaseCommand): if confirm in ('', FILES_TO_DATABASE, DATABASE_TO_FILES): if confirm == FILES_TO_DATABASE: - with io.open(path, encoding='utf-8') as f: + with open(path, encoding='utf-8') as f: t.content = f.read() t.save() t.sites.add(site) @@ -111,9 +111,9 @@ class Command(BaseCommand): os.remove(path) except OSError: raise CommandError( - u"Couldn't delete %s" % path) + "Couldn't delete %s" % path) elif confirm == DATABASE_TO_FILES: - with io.open(path, 'w', encoding='utf-8') as f: + with open(path, 'w', encoding='utf-8') as f: f.write(t.content) if delete: t.delete() diff --git a/dbtemplates/migrations/0001_initial.py b/dbtemplates/migrations/0001_initial.py index d5d3ed3..5d5b1f4 100644 --- a/dbtemplates/migrations/0001_initial.py +++ b/dbtemplates/migrations/0001_initial.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - import django from django.db import models, migrations import django.utils.timezone diff --git a/dbtemplates/models.py b/dbtemplates/models.py index 10cb83c..f115cc9 100644 --- a/dbtemplates/models.py +++ b/dbtemplates/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from dbtemplates.conf import settings from dbtemplates.utils.cache import (add_template_to_cache, remove_cached_template) @@ -20,7 +19,7 @@ class Template(models.Model): name = models.CharField(_('name'), max_length=100, help_text=_("Example: 'flatpages/default.html'")) content = models.TextField(_('content'), blank=True) - sites = models.ManyToManyField(Site, verbose_name=_(u'sites'), + sites = models.ManyToManyField(Site, verbose_name=_('sites'), blank=True) creation_date = models.DateTimeField(_('creation date'), default=now) @@ -59,7 +58,7 @@ class Template(models.Model): # populate the template instance with its content. if settings.DBTEMPLATES_AUTO_POPULATE_CONTENT and not self.content: self.populate() - super(Template, self).save(*args, **kwargs) + super().save(*args, **kwargs) def add_default_site(instance, **kwargs): diff --git a/dbtemplates/test_cases.py b/dbtemplates/test_cases.py index e724f07..06f8781 100644 --- a/dbtemplates/test_cases.py +++ b/dbtemplates/test_cases.py @@ -103,9 +103,9 @@ class DbTemplatesTestCase(TestCase): old_template_dirs = settings.TEMPLATES[0].get('DIRS', []) temp_template_dir = tempfile.mkdtemp('dbtemplates') temp_template_path = os.path.join(temp_template_dir, 'temp_test.html') - temp_template = io.open(temp_template_path, 'w', encoding='utf-8') + temp_template = open(temp_template_path, 'w', encoding='utf-8') try: - temp_template.write(u'temp test') + temp_template.write('temp test') settings.TEMPLATES[0]['DIRS'] = (temp_template_dir,) # these works well if is not settings patched at runtime # for supporting django < 1.7 tests we must patch dirs in runtime @@ -120,12 +120,12 @@ class DbTemplatesTestCase(TestCase): Template.objects.filter(name='temp_test.html').exists()) t = Template.objects.get(name='temp_test.html') - t.content = u'temp test modified' + t.content = 'temp test modified' t.save() call_command('sync_templates', force=True, verbosity=0, overwrite=DATABASE_TO_FILES) - self.assertEqual(u'temp test modified', - io.open(temp_template_path, + self.assertEqual('temp test modified', + open(temp_template_path, encoding='utf-8').read()) call_command('sync_templates', force=True, verbosity=0, diff --git a/dbtemplates/utils/cache.py b/dbtemplates/utils/cache.py index 53f0078..635dfb9 100644 --- a/dbtemplates/utils/cache.py +++ b/dbtemplates/utils/cache.py @@ -28,7 +28,7 @@ cache = get_cache_backend() def get_cache_key(name): current_site = Site.objects.get_current() - return 'dbtemplates::%s::%s' % (slugify(name), current_site.pk) + return 'dbtemplates::{}::{}'.format(slugify(name), current_site.pk) def get_cache_notfound_key(name): diff --git a/docs/conf.py b/docs/conf.py index bda62ab..2055241 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # django-dbtemplates documentation build configuration file, created by # sphinx-quickstart on Fri Oct 9 14:52:11 2009. @@ -37,8 +36,8 @@ source_suffix = '.txt' master_doc = 'index' # General information about the project. -project = u'django-dbtemplates' -copyright = u'2007-2019, Jannis Leidel and contributors' +project = 'django-dbtemplates' +copyright = '2007-2019, Jannis Leidel and contributors' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -177,8 +176,8 @@ htmlhelp_basename = 'django-dbtemplatesdoc' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'django-dbtemplates.tex', u'django-dbtemplates Documentation', - u'Jannis Leidel and contributors', 'manual'), + ('index', 'django-dbtemplates.tex', 'django-dbtemplates Documentation', + 'Jannis Leidel and contributors', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of diff --git a/setup.py b/setup.py index d4cde27..4425f7b 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup, find_packages def read(*parts): filename = os.path.join(os.path.dirname(__file__), *parts) - with io.open(filename, encoding="utf-8") as fp: + with open(filename, encoding="utf-8") as fp: return fp.read()