Try to use words.
This commit is contained in:
parent
5585af65a6
commit
3a0b346e3a
|
@ -51,3 +51,10 @@ If you're in production collect static files:
|
||||||
Run it:
|
Run it:
|
||||||
|
|
||||||
./manage.py runserver
|
./manage.py runserver
|
||||||
|
|
||||||
|
|
||||||
|
## Words generation
|
||||||
|
|
||||||
|
To generate the french dict I used
|
||||||
|
|
||||||
|
$ unmunch <(grep po:adj /usr/share/hunspell/fr_FR.dic) /usr/share/hunspell/fr_FR.aff | LC_ALL=C grep '^[a-z]*$' | grep '^[a-z]\{2,7\}$' | uniq > dict/french
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,6 @@
|
||||||
|
from webtools import settings
|
||||||
|
|
||||||
|
|
||||||
from django.contrib.sessions.middleware import (
|
from django.contrib.sessions.middleware import (
|
||||||
SessionMiddleware as DjangoSessionMiddleware,
|
SessionMiddleware as DjangoSessionMiddleware,
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,12 +2,44 @@ import string
|
||||||
import random
|
import random
|
||||||
import shortuuid
|
import shortuuid
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from webtools import settings
|
from webtools import settings
|
||||||
|
from functools import lru_cache
|
||||||
from .models import Paste
|
from .models import Paste
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache()
|
||||||
|
def find_words():
|
||||||
|
if not settings.DICT:
|
||||||
|
return None
|
||||||
|
short_words = []
|
||||||
|
try:
|
||||||
|
with open(settings.DICT) as dictionary:
|
||||||
|
for line in dictionary:
|
||||||
|
line = line.strip()
|
||||||
|
if re.match("[a-z]{2,5}$", line):
|
||||||
|
short_words.append(line)
|
||||||
|
return short_words
|
||||||
|
except FileNotFoundError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def random_id(model):
|
def random_id(model):
|
||||||
"""Returns a short uuid for the slug of the given model."""
|
"""Returns a short uuid for the slug of the given model.
|
||||||
|
|
||||||
|
If a DICT is given in the settings, try to use it to generate nicer URLS like:
|
||||||
|
"""
|
||||||
|
short_words = find_words()
|
||||||
|
if short_words:
|
||||||
|
slug = (
|
||||||
|
random.choice(string.digits)
|
||||||
|
+ random.choice(string.ascii_uppercase)
|
||||||
|
+ "-"
|
||||||
|
+ random.choice(short_words)
|
||||||
|
)
|
||||||
|
if not model.objects.filter(slug=slug):
|
||||||
|
return slug
|
||||||
|
# else, fallback to the shortuuid strategy:
|
||||||
uuid = random.choice("0123456789") + shortuuid.uuid()
|
uuid = random.choice("0123456789") + shortuuid.uuid()
|
||||||
for i in range(3, len(uuid)):
|
for i in range(3, len(uuid)):
|
||||||
potential_uuid = uuid[:i]
|
potential_uuid = uuid[:i]
|
||||||
|
|
|
@ -9,9 +9,9 @@ urlpatterns = [
|
||||||
url(r"^history$", views.history, name="history"),
|
url(r"^history$", views.history, name="history"),
|
||||||
url(r"^static/(?P<path>.*)", serve, {"document_root": settings.STATIC_ROOT}),
|
url(r"^static/(?P<path>.*)", serve, {"document_root": settings.STATIC_ROOT}),
|
||||||
url(
|
url(
|
||||||
r"^paste/(?P<slug>[a-zA-Z0-9]+)/(?P<renderer>[a-z]+)?$",
|
r"^paste/(?P<slug>[a-zA-Z0-9-]+)/(?P<renderer>[a-z]+)?$",
|
||||||
views.show,
|
views.show,
|
||||||
name="paste",
|
name="paste",
|
||||||
),
|
),
|
||||||
url(r"^(?P<slug>[0-9][a-zA-Z0-9]+)$", views.show, name="short_paste"),
|
url(r"^(?P<slug>[0-9][a-zA-Z0-9-]+)$", views.show, name="short_paste"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,136 +8,128 @@ SITE_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
|
||||||
### Customize/configure Pasteque
|
### Customize/configure Pasteque
|
||||||
|
|
||||||
DISPLAY_NAME = 'Pasteque'
|
DISPLAY_NAME = "Pasteque"
|
||||||
COMPRESS_ENABLED = False
|
COMPRESS_ENABLED = False
|
||||||
SECRET_KEY = 'change_me'
|
SECRET_KEY = "change_me"
|
||||||
ALLOWED_HOSTS = ['localhost','127.0.0.1']
|
ALLOWED_HOSTS = ["localhost", "127.0.0.1"]
|
||||||
TIME_ZONE = 'Europe/Brussels'
|
TIME_ZONE = "Europe/Brussels"
|
||||||
LANGUAGE_CODE = 'fr-FR'
|
LANGUAGE_CODE = "fr-FR"
|
||||||
DEBUG = False
|
DICT = os.path.join(SITE_ROOT, "dict", "french")
|
||||||
|
DEBUG = True
|
||||||
TEMPLATE_DEBUG = DEBUG
|
TEMPLATE_DEBUG = DEBUG
|
||||||
ADMINS = (
|
ADMINS = (("user", "user@hostname.domain"),)
|
||||||
('user', 'user@hostname.domain'),
|
|
||||||
)
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
"default": {
|
||||||
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
|
"ENGINE": "django.db.backends.sqlite3", # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
|
||||||
'NAME': os.path.join(SITE_ROOT, 'var', 'db', 'webtools.sqlite3'),
|
"NAME": os.path.join(SITE_ROOT, "var", "db", "webtools.sqlite3"),
|
||||||
# The following settings are not used with sqlite3:
|
# The following settings are not used with sqlite3:
|
||||||
'USER': '',
|
"USER": "",
|
||||||
'PASSWORD': '',
|
"PASSWORD": "",
|
||||||
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
|
"HOST": "", # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
|
||||||
'PORT': '', # Set to empty string for default.
|
"PORT": "", # Set to empty string for default.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
### End of customisation
|
### End of customisation
|
||||||
|
|
||||||
APP_NAME = 'Pasteque'
|
APP_NAME = "Pasteque"
|
||||||
APP_VERSION = 'v0.1'
|
APP_VERSION = "v0.1"
|
||||||
SITE_ID = 1
|
SITE_ID = 1
|
||||||
MANAGERS = ADMINS
|
MANAGERS = ADMINS
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
USE_L10N = True
|
USE_L10N = True
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
MEDIA_URL = ''
|
MEDIA_URL = ""
|
||||||
CACHE_PATH = os.path.join(SITE_ROOT, 'var', 'pygments-static')
|
CACHE_PATH = os.path.join(SITE_ROOT, "var", "pygments-static")
|
||||||
COMPRESS_ROOT = os.path.join(SITE_ROOT, 'static')
|
COMPRESS_ROOT = os.path.join(SITE_ROOT, "static")
|
||||||
MEDIA_ROOT = os.path.join(SITE_ROOT, 'assets')
|
MEDIA_ROOT = os.path.join(SITE_ROOT, "assets")
|
||||||
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
|
STATIC_ROOT = os.path.join(SITE_ROOT, "static")
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = "/static/"
|
||||||
STATICFILES_FINDERS = (
|
STATICFILES_FINDERS = (
|
||||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
||||||
'compressor.finders.CompressorFinder',
|
"compressor.finders.CompressorFinder",
|
||||||
)
|
)
|
||||||
TEMPLATE_LOADERS = (
|
TEMPLATE_LOADERS = (
|
||||||
'django.template.loaders.filesystem.Loader',
|
"django.template.loaders.filesystem.Loader",
|
||||||
'django.template.loaders.app_directories.Loader',
|
"django.template.loaders.app_directories.Loader",
|
||||||
)
|
)
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
'DIRS': [],
|
"DIRS": [],
|
||||||
'APP_DIRS': True,
|
"APP_DIRS": True,
|
||||||
'OPTIONS': {
|
"OPTIONS": {
|
||||||
'context_processors': [
|
"context_processors": [
|
||||||
'django.contrib.auth.context_processors.auth',
|
"django.contrib.auth.context_processors.auth",
|
||||||
'django.contrib.messages.context_processors.messages',
|
"django.contrib.messages.context_processors.messages",
|
||||||
'django.template.context_processors.debug',
|
"django.template.context_processors.debug",
|
||||||
'django.template.context_processors.request',
|
"django.template.context_processors.request",
|
||||||
'paste.context_processors.app_details',
|
"paste.context_processors.app_details",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'paste.middleware.SessionMiddleware',
|
"paste.middleware.SessionMiddleware",
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
'django.middleware.common.CommonMiddleware',
|
"django.middleware.common.CommonMiddleware",
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'webtools.urls'
|
ROOT_URLCONF = "webtools.urls"
|
||||||
WSGI_APPLICATION = 'webtools.wsgi.application'
|
WSGI_APPLICATION = "webtools.wsgi.application"
|
||||||
INSTALLED_APPS = (
|
INSTALLED_APPS = (
|
||||||
'django.contrib.staticfiles',
|
"django.contrib.staticfiles",
|
||||||
'django.contrib.contenttypes',
|
"django.contrib.contenttypes",
|
||||||
'django.contrib.admin',
|
"django.contrib.admin",
|
||||||
'django.contrib.auth',
|
"django.contrib.auth",
|
||||||
'django.contrib.messages',
|
"django.contrib.messages",
|
||||||
'django.contrib.sessions',
|
"django.contrib.sessions",
|
||||||
'compressor',
|
"compressor",
|
||||||
'paste',
|
"paste",
|
||||||
)
|
)
|
||||||
|
|
||||||
PASTE = {
|
PASTE = {
|
||||||
'has_title': False,
|
"has_title": False,
|
||||||
'has_expire_by_views': False,
|
"has_expire_by_views": False,
|
||||||
'has_meta_table': False,
|
"has_meta_table": False,
|
||||||
'show_char_left': False,
|
"show_char_left": False,
|
||||||
'private_by_default': True,
|
"private_by_default": True,
|
||||||
'enabled_renderers': ['pygments', 'raw'],
|
"enabled_renderers": ["pygments", "raw"],
|
||||||
'default_renderer': 'pygments',
|
"default_renderer": "pygments",
|
||||||
'max_characters': 100000,
|
"max_characters": 100000,
|
||||||
'default_lifetime': 60 * 24 * 7 * 365,
|
"default_lifetime": 60 * 24 * 7 * 365,
|
||||||
'default_language': 'Python',
|
"default_language": "Python",
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGING = {
|
LOGGING = {
|
||||||
'version': 1,
|
"version": 1,
|
||||||
'disable_existing_loggers': False,
|
"disable_existing_loggers": False,
|
||||||
'filters': {
|
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
|
||||||
'require_debug_false': {
|
"handlers": {
|
||||||
'()': 'django.utils.log.RequireDebugFalse'
|
"mail_admins": {
|
||||||
}
|
"level": "ERROR",
|
||||||
},
|
"filters": ["require_debug_false"],
|
||||||
'handlers': {
|
"class": "django.utils.log.AdminEmailHandler",
|
||||||
'mail_admins': {
|
|
||||||
'level': 'ERROR',
|
|
||||||
'filters': ['require_debug_false'],
|
|
||||||
'class': 'django.utils.log.AdminEmailHandler'
|
|
||||||
},
|
},
|
||||||
'console': {
|
"console": {"level": "DEBUG", "class": "logging.StreamHandler",},
|
||||||
'level': 'DEBUG',
|
"logfile": {
|
||||||
'class': 'logging.StreamHandler',
|
"level": "DEBUG",
|
||||||
},
|
"class": "logging.handlers.RotatingFileHandler",
|
||||||
'logfile': {
|
"filename": os.path.join(SITE_ROOT, "var", "logs", "error.log"),
|
||||||
'level': 'DEBUG',
|
"maxBytes": 50000,
|
||||||
'class': 'logging.handlers.RotatingFileHandler',
|
"backupCount": 2,
|
||||||
'filename': os.path.join(SITE_ROOT, 'var', 'logs', 'error.log'),
|
|
||||||
'maxBytes': 50000,
|
|
||||||
'backupCount': 2,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'loggers': {
|
"loggers": {
|
||||||
'django.request': {
|
"django.request": {
|
||||||
'handlers': ['console','logfile'],
|
"handlers": ["console", "logfile"],
|
||||||
'level': 'ERROR',
|
"level": "ERROR",
|
||||||
'propagate': True,
|
"propagate": True,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue