Bump to Python 3 and Django 2.
This commit is contained in:
parent
ca38d1aa17
commit
e80f2f10dd
|
@ -1,17 +1,14 @@
|
|||
from django.forms import ModelForm
|
||||
from models import Paste, Language
|
||||
|
||||
|
||||
class LanguageForm(ModelForm):
|
||||
"""Language model form."""
|
||||
class Meta:
|
||||
model = Language
|
||||
from .models import Paste, Language
|
||||
|
||||
|
||||
class PasteForm(ModelForm):
|
||||
"""Paste model form."""
|
||||
class Meta:
|
||||
model = Paste
|
||||
fields = ['language', 'title', 'password', 'content', 'lifetime',
|
||||
'lifecount', 'private']
|
||||
|
||||
|
||||
def save(self, commit=True):
|
||||
"""Overwrites save method."""
|
||||
|
|
|
@ -27,16 +27,19 @@ class Language(models.Model):
|
|||
"""String representation."""
|
||||
return _(self.name)
|
||||
|
||||
def __str__(self):
|
||||
return str(_(self.name))
|
||||
|
||||
|
||||
class Paste(models.Model):
|
||||
"""Paste object."""
|
||||
language = models.ForeignKey(Language, default=13)
|
||||
language = models.ForeignKey(Language, default=13, on_delete=models.SET_NULL, null=True)
|
||||
slug = models.SlugField(unique=True, editable=False)
|
||||
title = models.CharField(max_length=200, blank=True)
|
||||
content = models.TextField(validators=[MaxLengthValidator(settings.MAX_CHARACTERS)])
|
||||
size = models.IntegerField(default=0, editable=False)
|
||||
paste_time = models.DateTimeField(default=datetime.now, editable=False)
|
||||
paste_ip = models.IPAddressField(editable=False)
|
||||
paste_ip = models.GenericIPAddressField(editable=False)
|
||||
paste_agent = models.CharField(max_length=200, editable=False)
|
||||
lifetime = models.IntegerField(default=0, choices=EXPIRE_CHOICES)
|
||||
lifecount = models.IntegerField(default=0)
|
||||
|
|
|
@ -18,19 +18,16 @@ def render_pygments(request, paste, data):
|
|||
cache_store(key, highlighted_content)
|
||||
data['paste'] = paste
|
||||
data['highlighted'] = highlighted_content
|
||||
context = RequestContext(request, data)
|
||||
return get_template('paste/show-pygments.html').render(context)
|
||||
return get_template('paste/show-pygments.html').render(data)
|
||||
|
||||
|
||||
def render_form(request, paste, data):
|
||||
"""Renders Form template."""
|
||||
data['paste'] = paste
|
||||
context = RequestContext(request, data)
|
||||
return get_template('paste/show-form.html').render(context)
|
||||
return get_template('paste/show-form.html').render(data)
|
||||
|
||||
|
||||
def render_raw(request, paste, data):
|
||||
"""Renders RAW content."""
|
||||
data['paste'] = paste
|
||||
context = RequestContext(request, data)
|
||||
return get_template('paste/show-raw.html').render(context)
|
||||
return get_template('paste/show-raw.html').render(data)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load i18n %}
|
||||
{% load i18n %}
|
||||
{% load compress %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
@ -6,10 +6,10 @@
|
|||
<title>{% block title %}{% endblock %} - {{ DISPLAY_NAME }}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
{% compress css %}
|
||||
<link href="{{ STATIC_URL }}css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="{{ STATIC_URL }}css/font-awesome.min.css" rel="stylesheet">
|
||||
<link href="{{ STATIC_URL }}css/pygments-highlight.css" rel="stylesheet">
|
||||
<link href="{{ STATIC_URL }}css/main.css" rel="stylesheet">
|
||||
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/static/css/font-awesome.min.css" rel="stylesheet">
|
||||
<link href="/static/css/pygments-highlight.css" rel="stylesheet">
|
||||
<link href="/static/css/main.css" rel="stylesheet">
|
||||
{% endcompress %}
|
||||
</head>
|
||||
<body>
|
||||
|
@ -38,9 +38,9 @@
|
|||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
{% compress js %}
|
||||
<script src="{{ STATIC_URL }}js/jquery-1.9.1.min.js"></script>
|
||||
<script src="{{ STATIC_URL }}js/bootstrap.min.js"></script>
|
||||
<script src="{{ STATIC_URL }}js/jquery.autogrowtextarea.min.js"></script>
|
||||
<script src="/static/js/jquery-1.9.1.min.js"></script>
|
||||
<script src="/static/js/bootstrap.min.js"></script>
|
||||
<script src="/static/js/jquery.autogrowtextarea.min.js"></script>
|
||||
{% endcompress %}
|
||||
{% block javascript %}{% endblock %}
|
||||
</body>
|
||||
|
|
|
@ -35,7 +35,7 @@ def cache_exists(key):
|
|||
def cache_store(key, value):
|
||||
"""Store cache value for key."""
|
||||
with open(cache_get_filepath(key), 'w') as cache_file:
|
||||
cache_file.write(value.encode('utf-8'))
|
||||
cache_file.write(value)
|
||||
|
||||
|
||||
def cache_fetch(key):
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from django.conf.urls import patterns, url
|
||||
from django.conf.urls import url
|
||||
from django.views.static import serve
|
||||
from paste import views
|
||||
from webtools import settings
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index, name='index'),
|
||||
url(r'^paste/(?P<slug>[A-z0-9]+)/(?P<renderer>[a-z]+)?$', views.show, name='paste'),
|
||||
url(r'^history$', views.history, name='history'),
|
||||
url(r'^static/(?P<path>.*)', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
|
||||
)
|
||||
url(r'^static/(?P<path>.*)', serve, {'document_root': settings.STATIC_ROOT}),
|
||||
]
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import renderers
|
||||
from . import renderers
|
||||
from django.http import HttpResponse
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.urls import reverse
|
||||
from django.shortcuts import redirect, render, get_object_or_404
|
||||
from models import Paste
|
||||
from forms import PasteForm
|
||||
from tools import random_id
|
||||
from .models import Paste
|
||||
from .forms import PasteForm
|
||||
from .tools import random_id
|
||||
from webtools import settings
|
||||
|
||||
|
||||
|
@ -13,8 +13,8 @@ def index(request):
|
|||
data = {'menu': 'index',
|
||||
'max_characters': settings.MAX_CHARACTERS}
|
||||
if request.method == 'POST':
|
||||
paste = Paste(slug=random_id(),
|
||||
paste_ip=request.META['REMOTE_ADDR'],
|
||||
paste = Paste(slug=random_id(),
|
||||
paste_ip=request.META['REMOTE_ADDR'],
|
||||
paste_agent=request.META['HTTP_USER_AGENT'])
|
||||
form = PasteForm(request.POST, instance=paste)
|
||||
if not form.is_valid():
|
||||
|
@ -34,7 +34,7 @@ def show(request, slug, renderer):
|
|||
# Handling expiration
|
||||
if paste.is_expired():
|
||||
return render(request, 'paste/expired.html')
|
||||
# Handling passwords
|
||||
# Handling passwords
|
||||
if paste.password:
|
||||
if 'password' in request.POST:
|
||||
password = request.POST['password']
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Django==1.5.1
|
||||
uWSGI==1.9.4
|
||||
Pygments==1.6
|
||||
shortuuid==0.3
|
||||
django_compressor==1.3
|
||||
beautifulsoup==3.2.1
|
||||
Django==2.0.5
|
||||
uWSGI==2.0.17
|
||||
Pygments==2.2.0
|
||||
shortuuid==0.5.0
|
||||
django_compressor==2.2
|
||||
beautifulsoup4==4.6.0
|
||||
|
|
|
@ -38,10 +38,6 @@ DATABASES = {
|
|||
|
||||
APP_NAME = 'Pasteque'
|
||||
APP_VERSION = 'v0.1'
|
||||
TEMPLATE_CONTEXT_PROCESSORS = (
|
||||
"paste.context_processors.app_details",
|
||||
"django.core.context_processors.static",
|
||||
)
|
||||
SITE_ID = 1
|
||||
MANAGERS = ADMINS
|
||||
USE_I18N = True
|
||||
|
@ -62,6 +58,23 @@ TEMPLATE_LOADERS = (
|
|||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
)
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
"paste.context_processors.app_details",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
|
@ -72,6 +85,7 @@ ROOT_URLCONF = 'webtools.urls'
|
|||
WSGI_APPLICATION = 'webtools.wsgi.application'
|
||||
INSTALLED_APPS = (
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.contenttypes',
|
||||
'compressor',
|
||||
'paste',
|
||||
)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.conf.urls import patterns, include, url
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'', include('paste.urls')),
|
||||
)
|
||||
urlpatterns = [
|
||||
path('', include('paste.urls')),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue