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

Format Python code with psf/black #257

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ repos:
- id: mixed-line-ending
- id: requirements-txt-fixer

- repo: https://github.com/python/black
rev: 23.11.0
hooks:
- id: black # See pyproject.toml for args

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
Expand Down
51 changes: 37 additions & 14 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx',
'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.ifconfig',
'sphinx.ext.viewcode', 'settings']
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'settings',
]

# Add any paths that contain templates here, relative to this directory.
# templates_path = ['_templates']
Expand All @@ -54,6 +60,7 @@
# The short X.Y version.
try:
from formtools import __version__

# The short X.Y version.
version = '.'.join(__version__.split('.')[:2])
# The full version, including alpha/beta/rc tags.
Expand Down Expand Up @@ -184,19 +191,22 @@
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-formtools.tex', 'django-formtools Documentation',
'Django Software Foundation and individual contributors', 'manual'),
(
'index',
'django-formtools.tex',
'django-formtools Documentation',
'Django Software Foundation and individual contributors',
'manual',
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -225,8 +235,13 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-formtools', 'django-formtools Documentation',
['Django Software Foundation and individual contributors'], 1)
(
'index',
'django-formtools',
'django-formtools Documentation',
['Django Software Foundation and individual contributors'],
1,
)
]

# If true, show URL addresses after external links.
Expand All @@ -239,9 +254,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'django-formtools', 'django-formtools Documentation',
'Django Software Foundation and individual contributors', 'django-formtools', 'One line description of project.',
'Miscellaneous'),
(
'index',
'django-formtools',
'django-formtools Documentation',
'Django Software Foundation and individual contributors',
'django-formtools',
'One line description of project.',
'Miscellaneous',
),
]

# Documents to append as an appendix to all manuals.
Expand Down Expand Up @@ -318,6 +339,8 @@
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'http://docs.python.org/': None,
'django': ('http://docs.djangoproject.com/en/dev/',
'http://docs.djangoproject.com/en/dev/_objects/'),
'django': (
'http://docs.djangoproject.com/en/dev/',
'http://docs.djangoproject.com/en/dev/_objects/',
),
}
17 changes: 10 additions & 7 deletions formtools/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def unused_name(self, name):

def preview_get(self, request):
"Displays the form"
f = self.form(auto_id=self.get_auto_id(),
initial=self.get_initial(request))
f = self.form(auto_id=self.get_auto_id(), initial=self.get_initial(request))
return render(request, self.form_template, self.get_context(request, f))

def preview_post(self, request):
Expand All @@ -61,7 +60,9 @@ def preview_post(self, request):
"""
# Even if files are not supported in preview, we still initialize files
# to give a chance to process_preview to access files content.
f = self.form(data=request.POST, files=request.FILES, auto_id=self.get_auto_id())
f = self.form(
data=request.POST, files=request.FILES, auto_id=self.get_auto_id()
)
context = self.get_context(request, f)
if f.is_valid():
self.process_preview(request, f, context)
Expand All @@ -82,8 +83,8 @@ def post_post(self, request):
form = self.form(request.POST, auto_id=self.get_auto_id())
if form.is_valid():
if not self._check_security_hash(
request.POST.get(self.unused_name('hash'), ''),
request, form):
request.POST.get(self.unused_name('hash'), ''), request, form
):
return self.failed_hash(request) # Security hash failed.
return self.done(request, form.cleaned_data)
else:
Expand Down Expand Up @@ -166,5 +167,7 @@ def done(self, request, cleaned_data):
return an :class:`~django.http.HttpResponseRedirect`, e.g. to a
success page.
"""
raise NotImplementedError('You must define a done() method on your '
'%s subclass.' % self.__class__.__name__)
raise NotImplementedError(
'You must define a done() method on your '
'%s subclass.' % self.__class__.__name__
)
1 change: 1 addition & 0 deletions formtools/wizard/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ class ManagementForm(forms.Form):
"""
``ManagementForm`` is used to keep track of the current wizard step.
"""

template_name = "django/forms/p.html" # Remove when Django 5.0 is minimal version.
current_step = forms.CharField(widget=forms.HiddenInput)
5 changes: 4 additions & 1 deletion formtools/wizard/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from .exceptions import MissingStorage, NoFileStorageConfigured

__all__ = [
"BaseStorage", "MissingStorage", "NoFileStorageConfigured", "get_storage",
"BaseStorage",
"MissingStorage",
"NoFileStorageConfigured",
"get_storage",
]


Expand Down
11 changes: 7 additions & 4 deletions formtools/wizard/storage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,26 @@ def get_step_files(self, step):
if wizard_files and not self.file_storage:
raise NoFileStorageConfigured(
"You need to define 'file_storage' in your "
"wizard view in order to handle file uploads.")
"wizard view in order to handle file uploads."
)

files = {}
for field, field_dict in wizard_files.items():
field_dict = field_dict.copy()
tmp_name = field_dict.pop('tmp_name')
if (step, field) not in self._files:
self._files[(step, field)] = UploadedFile(
file=self.file_storage.open(tmp_name), **field_dict)
file=self.file_storage.open(tmp_name), **field_dict
)
files[field] = self._files[(step, field)]
return files or None

def set_step_files(self, step, files):
if files and not self.file_storage:
raise NoFileStorageConfigured(
"You need to define 'file_storage' in your "
"wizard view in order to handle file uploads.")
"wizard view in order to handle file uploads."
)

if step not in self.data[self.step_files_key]:
self.data[self.step_files_key][step] = {}
Expand All @@ -118,7 +121,7 @@ def set_step_files(self, step, files):
'name': field_file.name,
'content_type': field_file.content_type,
'size': field_file.size,
'charset': field_file.charset
'charset': field_file.charset,
}
self.data[self.step_files_key][step][field] = file_dict

Expand Down
3 changes: 1 addition & 2 deletions formtools/wizard/storage/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def load_data(self):
def update_response(self, response):
super().update_response(response)
if self.data:
response.set_signed_cookie(self.prefix,
self.encoder.encode(self.data))
response.set_signed_cookie(self.prefix, self.encoder.encode(self.data))
else:
response.delete_cookie(self.prefix)
1 change: 0 additions & 1 deletion formtools/wizard/storage/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class SessionStorage(BaseStorage):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.prefix not in self.request.session:
Expand Down
Loading
Loading