|
4 | 4 | from plain.http import (
|
5 | 5 | ResponseRedirect,
|
6 | 6 | )
|
7 |
| -from plain.urls import NoReverseMatch, reverse |
8 |
| -from plain.utils.functional import Promise |
9 | 7 | from plain.views import CreateView, FormView
|
10 | 8 |
|
11 | 9 | from .forms import (
|
|
17 | 15 | )
|
18 | 16 |
|
19 | 17 |
|
20 |
| -def resolve_url(to, *args, **kwargs): |
21 |
| - """ |
22 |
| - Return a URL appropriate for the arguments passed. |
23 |
| -
|
24 |
| - The arguments could be: |
25 |
| -
|
26 |
| - * A model: the model's `get_absolute_url()` function will be called. |
27 |
| -
|
28 |
| - * A view name, possibly with arguments: `urls.reverse()` will be used |
29 |
| - to reverse-resolve the name. |
30 |
| -
|
31 |
| - * A URL, which will be returned as-is. |
32 |
| - """ |
33 |
| - # If it's a model, use get_absolute_url() |
34 |
| - if hasattr(to, "get_absolute_url"): |
35 |
| - return to.get_absolute_url() |
36 |
| - |
37 |
| - if isinstance(to, Promise): |
38 |
| - # Expand the lazy instance, as it can cause issues when it is passed |
39 |
| - # further to some Python functions like urlparse. |
40 |
| - to = str(to) |
41 |
| - |
42 |
| - # Handle relative URLs |
43 |
| - if isinstance(to, str) and to.startswith(("./", "../")): |
44 |
| - return to |
45 |
| - |
46 |
| - # Next try a reverse URL resolution. |
47 |
| - try: |
48 |
| - return reverse(to, args=args, kwargs=kwargs) |
49 |
| - except NoReverseMatch: |
50 |
| - # If this is a callable, re-raise. |
51 |
| - if callable(to): |
52 |
| - raise |
53 |
| - # If this doesn't "feel" like a URL, re-raise. |
54 |
| - if "/" not in to and "." not in to: |
55 |
| - raise |
56 |
| - |
57 |
| - # Finally, fall back and assume it's a URL |
58 |
| - return to |
59 |
| - |
60 |
| - |
61 | 18 | def update_session_auth_hash(request, user):
|
62 | 19 | """
|
63 | 20 | Updating a user's password logs out all sessions for the user.
|
|
0 commit comments