From 2d20a1074834b0c0355024bbfe1484384fcdf9cd Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Sun, 28 Oct 2018 22:19:58 +0100 Subject: [PATCH 1/2] Remove old_div function usage --- readthedocs/core/views/__init__.py | 7 ------- readthedocs/gold/models.py | 3 +-- readthedocs/integrations/models.py | 3 +-- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/readthedocs/core/views/__init__.py b/readthedocs/core/views/__init__.py index 3020090d9ef..f6c79022b17 100644 --- a/readthedocs/core/views/__init__.py +++ b/readthedocs/core/views/__init__.py @@ -7,7 +7,6 @@ from __future__ import absolute_import from __future__ import division -from past.utils import old_div import os import logging @@ -17,10 +16,8 @@ from django.views.decorators.csrf import csrf_exempt from django.views.generic import TemplateView -from readthedocs.builds.models import Build from readthedocs.builds.models import Version from readthedocs.core.utils import broadcast -from readthedocs.projects import constants from readthedocs.projects.models import Project, ImportedFile from readthedocs.projects.tasks import remove_dir from readthedocs.redirects.utils import get_redirect_response @@ -96,10 +93,6 @@ def wipe_version(request, project_slug, version_slug): {'version': version, 'project': version.project}) -def divide_by_zero(request): # pylint: disable=unused-argument - return old_div(1, 0) - - def server_error_500(request, template_name='500.html'): """A simple 500 handler so we get media.""" r = render(request, template_name) diff --git a/readthedocs/gold/models.py b/readthedocs/gold/models.py index c07aee2a92c..5924f73ccd9 100644 --- a/readthedocs/gold/models.py +++ b/readthedocs/gold/models.py @@ -1,7 +1,6 @@ """Django models for recurring donations aka Gold Membership.""" from __future__ import absolute_import from __future__ import division -from past.utils import old_div import math from django.db import models @@ -49,5 +48,5 @@ def __str__(self): @property def num_supported_projects(self): dollars = int(self.level.split('-')[-1]) - num_projects = int(math.floor(old_div(dollars, DOLLARS_PER_PROJECT))) + num_projects = int(math.floor(dollars // DOLLARS_PER_PROJECT)) return num_projects diff --git a/readthedocs/integrations/models.py b/readthedocs/integrations/models.py index 326430e6e8d..2b80de3389f 100644 --- a/readthedocs/integrations/models.py +++ b/readthedocs/integrations/models.py @@ -17,7 +17,6 @@ from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ from jsonfield import JSONField -from past.utils import old_div from pygments import highlight from pygments.formatters import HtmlFormatter from pygments.lexers import JsonLexer @@ -149,7 +148,7 @@ def __str__(self): @property def failed(self): # Assume anything that isn't 2xx level status code is an error - return int(old_div(self.status_code, 100)) != 2 + return not (200 <= self.status_code < 300) def formatted_json(self, field): """Try to return pretty printed and Pygment highlighted code.""" From 08a97bd5a316c0a6f18684e81b23e97e862b599c Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Sun, 28 Oct 2018 22:21:49 +0100 Subject: [PATCH 2/2] pre-commit linting --- readthedocs/core/views/__init__.py | 13 +++++++++--- readthedocs/gold/models.py | 34 +++++++++++++++++++++++------- readthedocs/integrations/models.py | 13 +++++++++--- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/readthedocs/core/views/__init__.py b/readthedocs/core/views/__init__.py index f6c79022b17..e97a7247ba1 100644 --- a/readthedocs/core/views/__init__.py +++ b/readthedocs/core/views/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + """ Core views, including the main homepage, @@ -50,7 +51,11 @@ def get_context_data(self, **kwargs): if not support_email: support_email = 'support@{domain}'.format( domain=getattr( - settings, 'PRODUCTION_DOMAIN', 'readthedocs.org')) + settings, + 'PRODUCTION_DOMAIN', + 'readthedocs.org', + ), + ) context['support_email'] = support_email return context @@ -89,8 +94,10 @@ def wipe_version(request, project_slug, version_slug): broadcast(type='build', task=remove_dir, args=[del_dir]) return redirect('project_version_list', project_slug) return render( - request, 'wipe_version.html', - {'version': version, 'project': version.project}) + request, + 'wipe_version.html', + {'version': version, 'project': version.project}, + ) def server_error_500(request, template_name='500.html'): diff --git a/readthedocs/gold/models.py b/readthedocs/gold/models.py index 5924f73ccd9..cca5c6cdf5c 100644 --- a/readthedocs/gold/models.py +++ b/readthedocs/gold/models.py @@ -1,6 +1,13 @@ +# -*- coding: utf-8 -*- + """Django models for recurring donations aka Gold Membership.""" -from __future__ import absolute_import -from __future__ import division +from __future__ import ( + absolute_import, + division, + print_function, + unicode_literals, +) + import math from django.db import models @@ -9,7 +16,6 @@ from readthedocs.projects.models import Project - #: The membership options that are currently available LEVEL_CHOICES = ( ('v1-org-5', '$5/mo'), @@ -32,11 +38,23 @@ class GoldUser(models.Model): pub_date = models.DateTimeField(_('Publication date'), auto_now_add=True) modified_date = models.DateTimeField(_('Modified date'), auto_now=True) - user = models.ForeignKey('auth.User', verbose_name=_('User'), unique=True, related_name='gold') - level = models.CharField(_('Level'), max_length=20, - choices=LEVEL_CHOICES, default=LEVEL_CHOICES[0][0]) - projects = models.ManyToManyField(Project, verbose_name=_('Projects'), - related_name='gold_owners') + user = models.ForeignKey( + 'auth.User', + verbose_name=_('User'), + unique=True, + related_name='gold', + ) + level = models.CharField( + _('Level'), + max_length=20, + choices=LEVEL_CHOICES, + default=LEVEL_CHOICES[0][0], + ) + projects = models.ManyToManyField( + Project, + verbose_name=_('Projects'), + related_name='gold_owners', + ) last_4_card_digits = models.CharField(max_length=4) stripe_id = models.CharField(max_length=255) diff --git a/readthedocs/integrations/models.py b/readthedocs/integrations/models.py index 2b80de3389f..7514699cef6 100644 --- a/readthedocs/integrations/models.py +++ b/readthedocs/integrations/models.py @@ -1,16 +1,23 @@ # -*- coding: utf-8 -*- + """Integration models for external services.""" from __future__ import ( - absolute_import, division, print_function, unicode_literals) + absolute_import, + division, + print_function, + unicode_literals, +) import json import re import uuid -from builtins import object, str +from builtins import object, str from django.contrib.contenttypes.fields import ( - GenericForeignKey, GenericRelation) + GenericForeignKey, + GenericRelation, +) from django.contrib.contenttypes.models import ContentType from django.db import models, transaction from django.utils.encoding import python_2_unicode_compatible