Compare commits
2 Commits
5922cd7629
...
34868bd0a5
Author | SHA1 | Date |
---|---|---|
Matthias Portzel | 34868bd0a5 | |
Matthias Portzel | 823ee5a6c7 |
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.0.3 on 2022-04-12 21:00
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0005_thought_media_alt'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='thought',
|
||||||
|
name='text',
|
||||||
|
field=models.CharField(blank=True, max_length=140),
|
||||||
|
),
|
||||||
|
]
|
|
@ -11,7 +11,7 @@ from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class Thought(models.Model):
|
class Thought(models.Model):
|
||||||
text = models.CharField(max_length=140)
|
text = models.CharField(max_length=140, blank=True)
|
||||||
extended_text = models.TextField(blank=True)
|
extended_text = models.TextField(blank=True)
|
||||||
uuid = models.UUIDField(default=uuid.uuid4, editable=False)
|
uuid = models.UUIDField(default=uuid.uuid4, editable=False)
|
||||||
posted = models.DateTimeField(auto_now_add=True)
|
posted = models.DateTimeField(auto_now_add=True)
|
||||||
|
@ -96,9 +96,6 @@ class ThoughtForm(forms.ModelForm):
|
||||||
|
|
||||||
error_messages = {
|
error_messages = {
|
||||||
"text": {
|
"text": {
|
||||||
# It's debatable whether this is actually a "nice" error message
|
|
||||||
# but I've grown fond of it
|
|
||||||
"required": "Need some text.",
|
|
||||||
"max_length": "Text must be at most 140 characters."
|
"max_length": "Text must be at most 140 characters."
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,6 +148,10 @@ h1 {
|
||||||
display: block; /*Needs to be inline-block or block, so that margin on it works*/
|
display: block; /*Needs to be inline-block or block, so that margin on it works*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.thought .main {
|
||||||
|
min-height: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
.thought-end {
|
.thought-end {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
import re
|
||||||
|
|
||||||
|
from django import http
|
||||||
|
from django.conf import settings
|
||||||
|
from django.urls import is_valid_path
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
from django.utils.deprecation import MiddlewareMixin
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveSlashMiddleware(MiddlewareMixin):
|
||||||
|
def process_request(self, request):
|
||||||
|
if getattr(settings, "APPEND_SLASH") and getattr(settings, "REMOVE_SLASH"):
|
||||||
|
raise ImproperlyConfigured("APPEND_SLASH and REMOVE_SLASH may not both be True.")
|
||||||
|
|
||||||
|
old_url = request.path_info # path_info only includes path, query information
|
||||||
|
if getattr(settings, "REMOVE_SLASH", False) and old_url[-1] == "/":
|
||||||
|
urlconf = getattr(request, "urlconf", None)
|
||||||
|
|
||||||
|
new_url = old_url[:-1]
|
||||||
|
|
||||||
|
# If the url with a / would 404 and without a slash wouldn't
|
||||||
|
if (not is_valid_path(old_url, urlconf)) and is_valid_path(new_url, urlconf):
|
||||||
|
if settings.DEBUG and request.method == "POST":
|
||||||
|
if old_url.startswith("/api/"):
|
||||||
|
return api.error("You made a POST request to a URL ending with a slash. Please repeat your request without the slash.")
|
||||||
|
|
||||||
|
raise RuntimeError(""
|
||||||
|
"You called this URL via POST, but the URL ends in a "
|
||||||
|
"slash and you have REMOVE_SLASH set. Django can't "
|
||||||
|
"redirect to the non-slash URL while maintaining POST "
|
||||||
|
f"data. Change your form to point to {new_url} (without a "
|
||||||
|
"trailing slash), or set REMOVE_SLASH=False in your "
|
||||||
|
"Django settings.")
|
||||||
|
|
||||||
|
# The ? and everything after
|
||||||
|
query_data = re.match(r"^[^?]*(\?.*)?$", request.build_absolute_uri()).group(1) or ""
|
||||||
|
|
||||||
|
return http.HttpResponsePermanentRedirect(new_url + query_data)
|
|
@ -64,6 +64,7 @@ MIDDLEWARE = [
|
||||||
"django.middleware.common.CommonMiddleware",
|
"django.middleware.common.CommonMiddleware",
|
||||||
"django.middleware.csrf.CsrfViewMiddleware",
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
|
"whispermaphone.middleware.RemoveSlashMiddleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
CSRF_COOKIE_SECURE = False
|
CSRF_COOKIE_SECURE = False
|
||||||
|
@ -113,6 +114,8 @@ USE_L10N = True
|
||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
|
APPEND_SLASH = False
|
||||||
|
REMOVE_SLASH = True
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||||
|
|
Loading…
Reference in New Issue