plain 0.20.0__py3-none-any.whl → 0.21.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,11 +14,16 @@ logger = logging.getLogger("plain.request")
14
14
 
15
15
 
16
16
  # These middleware classes are always used by Plain.
17
- BUILTIN_MIDDLEWARE = [
18
- "plain.internal.middleware.headers.DefaultHeadersMiddleware",
19
- "plain.internal.middleware.https.HttpsRedirectMiddleware",
17
+ BUILTIN_BEFORE_MIDDLEWARE = [
18
+ "plain.internal.middleware.headers.DefaultHeadersMiddleware", # Runs after response, to set missing headers
19
+ "plain.internal.middleware.https.HttpsRedirectMiddleware", # Runs before response, to redirect to HTTPS quickly
20
+ "plain.csrf.middleware.CsrfViewMiddleware", # Runs before and after get_response...
21
+ ]
22
+
23
+ BUILTIN_AFTER_MIDDLEWARE = [
24
+ # Want this to run first (when reversed) so the slash middleware
25
+ # can immediately redirect to the slash-appended path if there is one.
20
26
  "plain.internal.middleware.slash.RedirectSlashMiddleware",
21
- "plain.csrf.middleware.CsrfViewMiddleware",
22
27
  ]
23
28
 
24
29
 
@@ -34,7 +39,9 @@ class BaseHandler:
34
39
  get_response = self._get_response
35
40
  handler = convert_exception_to_response(get_response)
36
41
 
37
- middlewares = reversed(BUILTIN_MIDDLEWARE + settings.MIDDLEWARE)
42
+ middlewares = reversed(
43
+ BUILTIN_BEFORE_MIDDLEWARE + settings.MIDDLEWARE + BUILTIN_AFTER_MIDDLEWARE
44
+ )
38
45
 
39
46
  for middleware_path in middlewares:
40
47
  middleware = import_string(middleware_path)
plain/views/objects.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from plain.exceptions import ImproperlyConfigured, ObjectDoesNotExist
2
- from plain.http import Http404, Response, ResponseRedirect
2
+ from plain.forms import Form
3
+ from plain.http import Http404, Response
3
4
 
4
5
  from .forms import FormView
5
6
  from .templates import TemplateView
@@ -80,6 +81,8 @@ class CreateView(ObjectTemplateViewMixin, FormView):
80
81
  View for creating a new object, with a response rendered by a template.
81
82
  """
82
83
 
84
+ template_name_suffix = "_form"
85
+
83
86
  def post(self) -> Response:
84
87
  """
85
88
  Handle POST requests: instantiate a form instance with the passed
@@ -152,30 +155,41 @@ class UpdateView(ObjectTemplateViewMixin, FormView):
152
155
  return kwargs
153
156
 
154
157
 
155
- class DeleteView(ObjectTemplateViewMixin, TemplateView):
158
+ class DeleteView(ObjectTemplateViewMixin, FormView):
156
159
  """
157
160
  View for deleting an object retrieved with self.get_object(), with a
158
161
  response rendered by a template.
159
162
  """
160
163
 
164
+ class EmptyDeleteForm(Form):
165
+ def __init__(self, instance, *args, **kwargs):
166
+ self.instance = instance
167
+ super().__init__(*args, **kwargs)
168
+
169
+ def save(self):
170
+ self.instance.delete()
171
+
172
+ form_class = EmptyDeleteForm
161
173
  template_name_suffix = "_confirm_delete"
162
174
 
175
+ def post(self) -> Response:
176
+ """
177
+ Handle POST requests: instantiate a form instance with the passed
178
+ POST variables and then check if it's valid.
179
+ """
180
+ self.load_object()
181
+ return super().post()
182
+
163
183
  def get_form_kwargs(self):
164
184
  """Return the keyword arguments for instantiating the form."""
165
185
  kwargs = super().get_form_kwargs()
166
186
  kwargs.update({"instance": self.object})
167
187
  return kwargs
168
188
 
169
- def get_success_url(self):
170
- if self.success_url:
171
- return self.success_url.format(**self.object.__dict__)
172
- else:
173
- raise ImproperlyConfigured("No URL to redirect to. Provide a success_url.")
174
-
175
- def post(self):
176
- self.load_object()
177
- self.object.delete()
178
- return ResponseRedirect(self.get_success_url())
189
+ def form_valid(self, form):
190
+ """If the form is valid, save the associated model."""
191
+ form.save()
192
+ return super().form_valid(form)
179
193
 
180
194
 
181
195
  class ListView(TemplateView):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plain
3
- Version: 0.20.0
3
+ Version: 0.21.1
4
4
  Summary: A web framework for building products with Python.
5
5
  Author-email: Dave Gaeddert <dave.gaeddert@dropseed.dev>
6
6
  License-File: LICENSE
@@ -47,7 +47,7 @@ plain/internal/files/uploadedfile.py,sha256=JRB7T3quQjg-1y3l1ASPxywtSQZhaeMc45uF
47
47
  plain/internal/files/uploadhandler.py,sha256=eEnd5onstypjHYtg367PnVWwCaF1kAPlLPSV7goIf_E,7198
48
48
  plain/internal/files/utils.py,sha256=xN4HTJXDRdcoNyrL1dFd528MBwodRlHZM8DGTD_oBIg,2646
49
49
  plain/internal/handlers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
- plain/internal/handlers/base.py,sha256=_1aRNrNgqdx8kkUlXYRJNOTnZ_Z236JNYNcTdp7RRjc,4228
50
+ plain/internal/handlers/base.py,sha256=M9P3f5JaMmGxzxW7b6p72zAHxFXHuNl57aRcmRCMoWo,4609
51
51
  plain/internal/handlers/exception.py,sha256=DH9gh1FyqgetFpMaB8yLIVE6phBTVPKQLA1GIn9MOeI,4555
52
52
  plain/internal/handlers/wsgi.py,sha256=estA1QKHTk3ZqziWxenHsw5UO2cwPp3Zr0XjkDeM5TY,7561
53
53
  plain/internal/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -135,11 +135,11 @@ plain/views/csrf.py,sha256=7q6l5xzLWhRnMY64aNj0hR6G-3pxI2yhRwG6k_5j00E,144
135
135
  plain/views/errors.py,sha256=Y4oGX4Z6D2COKcDEfINvXE1acE8Ad15KwNNWPs5BCfc,967
136
136
  plain/views/exceptions.py,sha256=b4euI49ZUKS9O8AGAcFfiDpstzkRAuuj_uYQXzWNHME,138
137
137
  plain/views/forms.py,sha256=RhlaUcZCkeqokY_fvv-NOS-kgZAG4XhDLOPbf9K_Zlc,2691
138
- plain/views/objects.py,sha256=fRfS6KNehIGqkbPw4nSafj8HStxYExHmbggolBbzcxs,7921
138
+ plain/views/objects.py,sha256=g5Lzno0Zsv0K449UpcCtxwCoO7WMRAWqKlxxV2V0_qg,8263
139
139
  plain/views/redirect.py,sha256=KLnlktzK6ZNMTlaEiZpMKQMEP5zeTgGLJ9BIkIJfwBo,1733
140
140
  plain/views/templates.py,sha256=nF9CcdhhjAyp3LB0RrSYnBaHpHzMfPSw719RCdcXk7o,2007
141
- plain-0.20.0.dist-info/METADATA,sha256=xC6F5-ztR9t_Fa39_xt2VG8d2OqeVp4BSeoq7MG7afU,2518
142
- plain-0.20.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
143
- plain-0.20.0.dist-info/entry_points.txt,sha256=DHHprvufgd7xypiBiqMANYRnpJ9xPPYhYbnPGwOkWqE,40
144
- plain-0.20.0.dist-info/licenses/LICENSE,sha256=m0D5O7QoH9l5Vz_rrX_9r-C8d9UNr_ciK6Qwac7o6yo,3175
145
- plain-0.20.0.dist-info/RECORD,,
141
+ plain-0.21.1.dist-info/METADATA,sha256=N4d5IZSoIdNKWvbTZHzyvcGCaj1D5pD2iNzvIywz-iw,2518
142
+ plain-0.21.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
143
+ plain-0.21.1.dist-info/entry_points.txt,sha256=DHHprvufgd7xypiBiqMANYRnpJ9xPPYhYbnPGwOkWqE,40
144
+ plain-0.21.1.dist-info/licenses/LICENSE,sha256=m0D5O7QoH9l5Vz_rrX_9r-C8d9UNr_ciK6Qwac7o6yo,3175
145
+ plain-0.21.1.dist-info/RECORD,,
File without changes