Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run flake8 and fix all errors #111

Merged
merged 2 commits into from May 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/PyCQA/flake8
rev: 3.9.1
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-tidy-imports
2 changes: 1 addition & 1 deletion example/example/notes/forms.py
@@ -1,5 +1,5 @@
# coding=utf-8
from django.forms import ModelForm

from .models import Note


Expand Down
10 changes: 9 additions & 1 deletion example/example/notes/migrations/0001_initial.py
Expand Up @@ -15,7 +15,15 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Note',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
(
'id',
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID'
)
),
('created', models.DateTimeField(auto_now_add=True)),
('message', models.CharField(max_length=100)),
('complete', models.BooleanField(default=False)),
Expand Down
2 changes: 1 addition & 1 deletion example/example/notes/models.py
@@ -1,6 +1,6 @@
# coding=utf-8
from django.db import models


class Note(models.Model):
created = models.DateTimeField(auto_now_add=True)
message = models.CharField(max_length=100)
Expand Down
3 changes: 1 addition & 2 deletions example/example/urls.py
@@ -1,5 +1,4 @@
from django.conf.urls import include, url
from example.notes.models import Note
from django.conf.urls import url
from example.notes.views import ListNotes, CreateNote, EditNote, DeleteNote

urlpatterns = [
Expand Down
30 changes: 2 additions & 28 deletions example/example/wsgi.py
@@ -1,32 +1,6 @@
"""
WSGI config for example project.

This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""
import os

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "example.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
application = get_wsgi_application()
32 changes: 27 additions & 5 deletions mkdocs.py
Expand Up @@ -26,7 +26,10 @@

main_header = '<li class="main"><a href="#{{ anchor }}">{{ title }}</a></li>'
sub_header = '<li><a href="#{{ anchor }}">{{ title }}</a></li>'
code_label = r'<a class="github" href="https://github.com/tomchristie/django-vanilla-views/tree/master/vanilla/\1"><span class="label label-info">\1</span></a>'
code_label = (
r'<a class="github" href="https://github.com/encode/django-vanilla-views'
+ r'/tree/master/vanilla/\1"><span class="label label-info">\1</span></a>'
)

with open(os.path.join(docs_dir, 'template.html'), 'r') as fp:
page = fp.read()
Expand Down Expand Up @@ -57,7 +60,7 @@
next_url_map[path] = rel + path_list[idx + 1][:-3] + suffix


for (dirpath, dirnames, filenames) in os.walk(docs_dir):
for (dirpath, _dirnames, filenames) in os.walk(docs_dir):
relative_dir = dirpath.replace(docs_dir, '').lstrip(os.path.sep)
build_dir = os.path.join(html_dir, relative_dir)

Expand Down Expand Up @@ -94,7 +97,15 @@

if not main_title:
main_title = title
anchor = title.lower().replace(' ', '-').replace(':-', '-').replace("'", '').replace('?', '').replace('.', '')
anchor = (
title
.lower()
.replace(' ', '-')
.replace(':-', '-')
.replace("'", '')
.replace('?', '')
.replace('.', '')
)
template = template.replace('{{ title }}', title)
template = template.replace('{{ anchor }}', anchor)
toc += template + '\n'
Expand All @@ -109,7 +120,14 @@

content = markdown.markdown(text, extensions=['toc'])

output = page.replace('{{ content }}', content).replace('{{ toc }}', toc).replace('{{ base_url }}', base_url).replace('{{ suffix }}', suffix).replace('{{ index }}', index)
output = (
page
.replace('{{ content }}', content)
.replace('{{ toc }}', toc)
.replace('{{ base_url }}', base_url)
.replace('{{ suffix }}', suffix)
.replace('{{ index }}', index)
)
output = output.replace('{{ title }}', main_title)
output = output.replace('{{ description }}', description)
output = output.replace('{{ page_id }}', filename[:-3])
Expand All @@ -129,7 +147,11 @@
output = output.replace('{{ next_url_disabled }}', 'disabled')

output = re.sub(r'a href="([^"]*)\.md"', r'a href="\1%s"' % suffix, output)
output = re.sub(r'<pre><code>:::bash', r'<pre class="prettyprint lang-bsh">', output)
output = re.sub(
r'<pre><code>:::bash',
r'<pre class="prettyprint lang-bsh">',
output,
)
output = re.sub(r'<pre>', r'<pre class="prettyprint lang-py">', output)
output = re.sub(r'<a class="github" href="([^"]*)"></a>', code_label, output)
with open(output_path, 'w') as fp:
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 80
select = E,F,W,B,B950,C,I
ignore = E203,E501,W503
19 changes: 8 additions & 11 deletions setup.py
Expand Up @@ -13,24 +13,20 @@
author_email = 'tom@tomchristie.com'
license = 'BSD'

long_description = """Django's generic class based view implementation is unneccesarily complicated.
with open("README.md", "r") as fp:
long_description = fp.read()

Django vanilla views gives you all the same functionality, in a vastly simplified, easier-to-use package, including:

* No mixin classes.
* No calls to super().
* A sane class hierarchy.
* A stripped down API.
* Simpler method implementations, with less magical behavior.

Remember, even though the API has been greatly simplified, everything you're able to do with Django's existing implementation is also supported in django-vanilla-views."""

def get_version(package):
"""
Return package version as listed in `__version__` in `init.py`.
"""
init_py = open(os.path.join(package, '__init__.py')).read()
return re.search("^__version__ = ['\"]([^'\"]+)['\"]", init_py, re.MULTILINE).group(1)
return re.search(
r"^__version__ = ['\"]([^'\"]+)['\"]",
init_py,
re.MULTILINE,
).group(1)


def get_packages(package):
Expand Down Expand Up @@ -74,6 +70,7 @@ def get_package_data(package):
license=license,
description=description,
long_description=long_description,
long_description_content_type="text/markdown",
author=author,
author_email=author_email,
license_file="LICENSE",
Expand Down
4 changes: 2 additions & 2 deletions vanilla/__init__.py
Expand Up @@ -5,9 +5,9 @@
'ListView', 'DetailView', 'CreateView', 'UpdateView', 'DeleteView'
)

from django.views.generic import View
from django.views.generic import RedirectView, View
from vanilla.views import (
GenericView, RedirectView, TemplateView, FormView
GenericView, TemplateView, FormView
)
from vanilla.model_views import (
GenericModelView, ListView, DetailView, CreateView, UpdateView, DeleteView
Expand Down
23 changes: 15 additions & 8 deletions vanilla/model_views.py
Expand Up @@ -6,7 +6,6 @@
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from django.views.generic import View
import warnings

# Avoid RemovedInDjango40Warning on Django 3.0+
if django.VERSION >= (3, 0):
Expand Down Expand Up @@ -42,10 +41,9 @@ class GenericModelView(View):
paginate_by = None
page_kwarg = 'page'

# Suffix that should be appended to automatically generated template names.
# Suffix that should be appended to automatically generated template names.
template_name_suffix = None


# Queryset and object lookup

def get_object(self):
Expand All @@ -59,7 +57,9 @@ def get_object(self):
lookup = {self.lookup_field: self.kwargs[lookup_url_kwarg]}
except KeyError:
msg = "Lookup field '%s' was not provided in view kwargs to '%s'"
raise ImproperlyConfigured(msg % (lookup_url_kwarg, self.__class__.__name__))
raise ImproperlyConfigured(
msg % (lookup_url_kwarg, self.__class__.__name__)
)

return get_object_or_404(queryset, **lookup)

Expand All @@ -76,7 +76,10 @@ def get_queryset(self):
if self.model is not None:
return self.model._default_manager.all()

msg = "'%s' must either define 'queryset' or 'model', or override 'get_queryset()'"
msg = (
"'%s' must either define 'queryset' or 'model', or override "
+ "'get_queryset()'"
)
raise ImproperlyConfigured(msg % self.__class__.__name__)

# Form instantiation
Expand Down Expand Up @@ -214,7 +217,7 @@ def render_to_response(self, context):
)


#The concrete model views
# The concrete model views

class ListView(GenericModelView):
template_name_suffix = '_list'
Expand All @@ -228,7 +231,7 @@ def get(self, request, *args, **kwargs):
raise Http404

if paginate_by is None:
# Unpaginated response
# Unpaginated response
self.object_list = queryset
context = self.get_context_data(
page_obj=None,
Expand Down Expand Up @@ -301,7 +304,11 @@ def get(self, request, *args, **kwargs):

def post(self, request, *args, **kwargs):
self.object = self.get_object()
form = self.get_form(data=request.POST, files=request.FILES, instance=self.object)
form = self.get_form(
data=request.POST,
files=request.FILES,
instance=self.object,
)
if form.is_valid():
return self.form_valid(form)
return self.form_invalid(form)
Expand Down