From 021101d9e06e2d07e311774ac8be2f0dfe2617ab Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Thu, 24 Mar 2016 20:14:26 +0100 Subject: [PATCH 01/32] Fix for missing languages in about menu. --- dpaste/settings/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dpaste/settings/base.py b/dpaste/settings/base.py index c0f27b2..f783da8 100644 --- a/dpaste/settings/base.py +++ b/dpaste/settings/base.py @@ -104,6 +104,7 @@ TEMPLATES = [ 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', + 'django.template.context_processors.i18n', ], }, }, From c3ba7de621dbed758f3eaaf8a44f8b03fe04dc3d Mon Sep 17 00:00:00 2001 From: Marco Rougeth Date: Fri, 3 Jun 2016 15:24:45 -0300 Subject: [PATCH 02/32] Added R lexer --- dpaste/highlight.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dpaste/highlight.py b/dpaste/highlight.py index 7e5f806..83d6f8c 100644 --- a/dpaste/highlight.py +++ b/dpaste/highlight.py @@ -79,6 +79,7 @@ LEXER_LIST = getattr(settings, 'DPASTE_LEXER_LIST', ( ('properties', 'Properties'), ('puppet', 'Puppet'), ('python', 'Python'), + ('r', 'R'), ('rb', 'Ruby'), ('rst', 'reStructuredText'), ('rust', 'Rust'), From f604568beac92afea5863c985255ad55b848f919 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sat, 4 Jun 2016 07:02:07 +0000 Subject: [PATCH 03/32] Have logfiles in standard folder --- server/nginx.conf | 4 ++-- server/webalizer.conf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/nginx.conf b/server/nginx.conf index 5b5ff52..fd6b594 100644 --- a/server/nginx.conf +++ b/server/nginx.conf @@ -83,8 +83,8 @@ server { rewrite ^/(.*)$ https://dpaste.de/$1 permanent; } - access_log /srv/dpaste.de/var/nginx.access.log combined_port; - error_log /srv/dpaste.de/var/nginx.error.log; + access_log /var/log/nginx/dpaste.access.log combined_port; + error_log /var/log/nginx/dpaste.error.log; keepalive_timeout 5; client_max_body_size 10M; diff --git a/server/webalizer.conf b/server/webalizer.conf index 0e4a9fb..696a6e4 100644 --- a/server/webalizer.conf +++ b/server/webalizer.conf @@ -26,7 +26,7 @@ # (bzip2 compressed file), it will be decompressed on the fly as it # is being read. -LogFile /srv/dpaste.de/var/nginx.access.log +LogFile /var/log/nginx/dpaste.access.log # LogType defines the log type being processed. Normally, the Webalizer # expects a CLF or Combined web server log as input. Using this option, From 59014216574285687fd3e3f93e564797c1c7f2af Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sat, 18 Jun 2016 10:54:20 +0000 Subject: [PATCH 04/32] Make Webalizer work with rotated logfiles. --- server/webalizer.conf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/webalizer.conf b/server/webalizer.conf index 696a6e4..a5e720f 100644 --- a/server/webalizer.conf +++ b/server/webalizer.conf @@ -26,7 +26,7 @@ # (bzip2 compressed file), it will be decompressed on the fly as it # is being read. -LogFile /var/log/nginx/dpaste.access.log +LogFile /var/log/nginx/dpaste.access.log.1 # LogType defines the log type being processed. Normally, the Webalizer # expects a CLF or Combined web server log as input. Using this option, @@ -64,7 +64,7 @@ OutputDir /srv/dpaste.de/var/webalizer # with the IncrementalName option below). Please read at least the section # on Incremental processing in the README file before you enable this option. -#Incremental no +Incremental yes # IncrementalName allows you to specify the filename for saving the # incremental data in. It is similar to the HistoryName option where the @@ -73,7 +73,7 @@ OutputDir /srv/dpaste.de/var/webalizer # kept in the normal output directory. If you don't specify "Incremental" # as 'yes' then this option has no meaning. -#IncrementalName webalizer.current +IncrementalName webalizer.current # ReportTitle is the text to display as the title. The hostname # (unless blank) is appended to the end of this string (separated with From 26380964489929d6bc098cad12fd20b54b7eff4c Mon Sep 17 00:00:00 2001 From: nixon Date: Sun, 3 Jul 2016 10:04:48 -0500 Subject: [PATCH 05/32] use snippet_new url for headline --- dpaste/templates/dpaste/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpaste/templates/dpaste/base.html b/dpaste/templates/dpaste/base.html index 1f8dc35..1d8687f 100644 --- a/dpaste/templates/dpaste/base.html +++ b/dpaste/templates/dpaste/base.html @@ -19,7 +19,7 @@
  • {% trans "History" %}
  • {% trans "New snippet" %} →
  • -

    {% block headline %}{% endblock %}

    +

    {% block headline %}{% endblock %}

    {% block page %} PAGE MISSING From fd4beeec7331c7ebc37dc12bfe5f74cd78c8e134 Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Mon, 8 Aug 2016 23:41:53 +0000 Subject: [PATCH 06/32] Use https:// for jquery script download by default. Google offers SSL for the resource, so we might as well use that as the default to cut off MITM angles. --- dpaste/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpaste/views.py b/dpaste/views.py index e1e6fb0..ef20ad0 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -26,7 +26,7 @@ from .models import ONETIME_LIMIT, Snippet template_globals = { 'site_name': getattr(settings, 'DPASTE_SITE_NAME', 'dpaste.de'), 'jquery_url': getattr(settings, 'DPASTE_JQUERY_URL', - '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.js'), + 'https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js'), } # ----------------------------------------------------------------------------- From 0bf4a7587a1e6a681053de43d03a6632b5a09278 Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Wed, 10 Aug 2016 22:51:55 +0000 Subject: [PATCH 07/32] cleanup_snippets: use self.stdout rather than sys.stdout The point of using these handles rather than sys.* is to support things like this: https://docs.djangoproject.com/ja/1.9/ref/django-admin/#output-redirection It also makes unit testing the output simpler. --- dpaste/management/commands/cleanup_snippets.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dpaste/management/commands/cleanup_snippets.py b/dpaste/management/commands/cleanup_snippets.py index c24e6ec..cec58e4 100644 --- a/dpaste/management/commands/cleanup_snippets.py +++ b/dpaste/management/commands/cleanup_snippets.py @@ -20,10 +20,10 @@ class Command(LabelCommand): expire_type=Snippet.EXPIRE_TIME, expires__lte=timezone.now() ) - sys.stdout.write(u"%s snippets gets deleted:\n" % deleteable_snippets.count()) + self.stdout.write(u"%s snippets gets deleted:\n" % deleteable_snippets.count()) for d in deleteable_snippets: - sys.stdout.write(u"- %s (%s)\n" % (d.secret_id, d.expires)) + self.stdout.write(u"- %s (%s)\n" % (d.secret_id, d.expires)) if options.get('dry_run'): - sys.stdout.write(u'Dry run - Not actually deleting snippets!\n') + self.stdout.write(u'Dry run - Not actually deleting snippets!\n') else: deleteable_snippets.delete() From a39697bdeb5ca78056901f7612902810f015d827 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sun, 4 Sep 2016 20:05:44 +0200 Subject: [PATCH 08/32] Added Django 1.10 to local dev and tests. --- .travis.yml | 1 + requirements.txt | 2 +- tox.ini | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8e71bf5..fa0db70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ python: env: - DJANGO=1.8.* - DJANGO=1.9.* + - DJANGO=1.10.* before_install: - pip install codecov diff --git a/requirements.txt b/requirements.txt index 20b6c20..0325e0b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ # ----------------------------------------------------------------------------- # Project dependencies -django==1.9.* +django==1.10.* django-mptt pygments requests diff --git a/tox.ini b/tox.ini index 155def6..a7717a5 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] toxworkdir=/tmp/tox/dpaste envlist= - py{27,35}-django-{18,19} + py{27,35}-django-{18,19,110} [testenv] install_command = @@ -14,3 +14,4 @@ deps= # Django versions django-18: django==1.8.* django-19: django==1.9.* + django-110: django==1.10.* From b51c16bcbc73c908b4deb38c55beb74a3777617d Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sun, 4 Sep 2016 20:06:07 +0200 Subject: [PATCH 09/32] Code cleanup and update for Django 1.10. Fixed all warnings. --- dpaste/management/commands/cleanup_snippets.py | 17 ++++++++++------- dpaste/settings/local.py.example | 1 - dpaste/urls/dpaste_api.py | 2 +- runtests.py | 4 +++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/dpaste/management/commands/cleanup_snippets.py b/dpaste/management/commands/cleanup_snippets.py index cec58e4..37776b0 100644 --- a/dpaste/management/commands/cleanup_snippets.py +++ b/dpaste/management/commands/cleanup_snippets.py @@ -1,26 +1,29 @@ import sys from optparse import make_option -from django.core.management.base import LabelCommand +from django.core.management.base import BaseCommand from django.utils import timezone from dpaste.models import Snippet -class Command(LabelCommand): - option_list = LabelCommand.option_list + ( - make_option('--dry-run', '-d', action='store_true', dest='dry_run', - help='Don\'t do anything.'), - ) +class Command(BaseCommand): help = "Purges snippets that are expired" + def add_arguments(self, parser): + parser.add_argument('--dry-run', action='store_true', dest='dry_run', + help='Don\'t do anything.'), + def handle(self, *args, **options): deleteable_snippets = Snippet.objects.filter( expires__isnull=False, expire_type=Snippet.EXPIRE_TIME, expires__lte=timezone.now() ) - self.stdout.write(u"%s snippets gets deleted:\n" % deleteable_snippets.count()) + if len(deleteable_snippets) == 0: + self.stdout.write(u"No snippets to delete.") + return None + self.stdout.write(u"Will delete %s snippet(s):\n" % deleteable_snippets.count()) for d in deleteable_snippets: self.stdout.write(u"- %s (%s)\n" % (d.secret_id, d.expires)) if options.get('dry_run'): diff --git a/dpaste/settings/local.py.example b/dpaste/settings/local.py.example index b9e789a..5c5ffcf 100644 --- a/dpaste/settings/local.py.example +++ b/dpaste/settings/local.py.example @@ -1,7 +1,6 @@ from dpaste.settings.base import * DEBUG = True -TEMPLATE_DEBUG = DEBUG ADMINS = ( #('Your Name', 'name@example.com'), diff --git a/dpaste/urls/dpaste_api.py b/dpaste/urls/dpaste_api.py index df419e4..64f6334 100644 --- a/dpaste/urls/dpaste_api.py +++ b/dpaste/urls/dpaste_api.py @@ -1,4 +1,4 @@ -from django.conf.urls import patterns, url +from django.conf.urls import url from ..views import snippet_api diff --git a/runtests.py b/runtests.py index 770f4e4..2338e5b 100755 --- a/runtests.py +++ b/runtests.py @@ -40,7 +40,9 @@ SETTINGS = { ), 'STATIC_ROOT': '/tmp/dpaste_test_static/', 'STATIC_URL': '/static/', - 'ROOT_URLCONF': 'dpaste.urls' + 'ROOT_URLCONF': 'dpaste.urls', + 'LANGUAGE_CODE': 'en', + 'LANGUAGES': (('en', 'English'),), } def runtests(*test_args): From fcfa2c60fbec1bf7188b075e88de8f7e8257542b Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sun, 4 Sep 2016 20:09:22 +0200 Subject: [PATCH 10/32] 2.11 Release --- CHANGELOG | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 5ecc086..d472fc3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,13 @@ Changelog ========= +2.11 (2016-09-04) +----------------- + +* Django 1.10 Support +* R Lexer is enabled by default +* Minor fixes and improvements. + 2.10 (2016-03-23) ----------------- diff --git a/setup.py b/setup.py index e152e65..7b142e5 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ long_description = u'\n\n'.join(( setup( name='dpaste', - version='2.10', + version='2.11', description='dpaste is a Django based pastebin. It\'s intended to run ' 'separately but its also possible to be installed into an ' 'existing Django project like a regular app.', From 1cc6a1a05e6d69c19e19c2220ededc1901ba86c9 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sun, 4 Sep 2016 20:14:30 +0200 Subject: [PATCH 11/32] Added atom plugin. Closes #75. --- dpaste/templates/dpaste/about.html | 1 + 1 file changed, 1 insertion(+) diff --git a/dpaste/templates/dpaste/about.html b/dpaste/templates/dpaste/about.html index ac519ed..aee113d 100644 --- a/dpaste/templates/dpaste/about.html +++ b/dpaste/templates/dpaste/about.html @@ -53,6 +53,7 @@
  • dpasteGUI, a OS X interface
  • a dpaste Sublime 2 plugin
  • Marmalade, a Emacs plugin
  • +
  • atom-dpaste, a Atom editor plugin
  • {% trans "Statistics" %}

    From 722971e854f3f16aa56095d8b32d8e06dfd91d2c Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Tue, 6 Sep 2016 14:31:30 +0200 Subject: [PATCH 12/32] Trying different version identifiers. Refs #82. --- .travis.yml | 8 ++++---- requirements.txt | 9 +++------ tox.ini | 8 ++++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index fa0db70..c85e366 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,15 +5,15 @@ python: - 3.5 env: - - DJANGO=1.8.* - - DJANGO=1.9.* - - DJANGO=1.10.* + - DJANGO: django>=1.8,<1.9 + - DJANGO: django>=1.9,<1.10 + - DJANGO: django>=1.10 before_install: - pip install codecov install: - - pip install django==$DJANGO + - pip install $DJANGO - pip install -e . script: diff --git a/requirements.txt b/requirements.txt index 0325e0b..7e459fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ # ----------------------------------------------------------------------------- # Project dependencies -django==1.10.* +django>=1.10 django-mptt pygments requests @@ -16,10 +16,7 @@ tox docutils sphinx sphinx_rtd_theme -mysql-python # Deployment specific -django-redis==3.8.0 -gunicorn==19.1.1 -south==1.0.2 - +gunicorn +mysql-python diff --git a/tox.ini b/tox.ini index a7717a5..b19a3ae 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] toxworkdir=/tmp/tox/dpaste envlist= - py{27,35}-django-{18,19,110} + py{27,35}-django-{18,19,latest} [testenv] install_command = @@ -12,6 +12,6 @@ commands= deps= # Django versions - django-18: django==1.8.* - django-19: django==1.9.* - django-110: django==1.10.* + django-18: django>=1.8,<1.9 + django-19: django>=1.9,<1.10 + django-latest: django>=1.10 From 6505f07a2ac6795b3b88cf58bef9b822c27194c9 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Tue, 6 Sep 2016 15:07:54 +0200 Subject: [PATCH 13/32] Moved template variables into a context processor. Fixed content type handling with Django 1.10. --- dpaste/context_processors.py | 8 ++++++++ dpaste/settings/base.py | 1 + dpaste/views.py | 39 ++++++------------------------------ 3 files changed, 15 insertions(+), 33 deletions(-) create mode 100644 dpaste/context_processors.py diff --git a/dpaste/context_processors.py b/dpaste/context_processors.py new file mode 100644 index 0000000..f4dbefa --- /dev/null +++ b/dpaste/context_processors.py @@ -0,0 +1,8 @@ +from django.conf import settings + +def dpaste_globals(request): + return { + 'site_name': getattr(settings, 'DPASTE_SITE_NAME', 'dpaste.de'), + 'jquery_url': getattr(settings, 'DPASTE_JQUERY_URL', + 'https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js'), + } diff --git a/dpaste/settings/base.py b/dpaste/settings/base.py index f783da8..142b99c 100644 --- a/dpaste/settings/base.py +++ b/dpaste/settings/base.py @@ -105,6 +105,7 @@ TEMPLATES = [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.template.context_processors.i18n', + 'dpaste.context_processors.dpaste_globals', ], }, }, diff --git a/dpaste/views.py b/dpaste/views.py index ef20ad0..b48fdb6 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -9,7 +9,7 @@ from django.core.urlresolvers import reverse from django.db.models import Count from django.http import (Http404, HttpResponse, HttpResponseBadRequest, HttpResponseRedirect) -from django.shortcuts import get_object_or_404, render_to_response +from django.shortcuts import get_object_or_404, render from django.template.context import RequestContext from django.utils.translation import ugettext_lazy as _ from django.views.decorators.csrf import csrf_exempt @@ -23,12 +23,6 @@ from .highlight import (LEXER_DEFAULT, LEXER_KEYS, LEXER_LIST, LEXER_WORDWRAP, PLAIN_CODE) from .models import ONETIME_LIMIT, Snippet -template_globals = { - 'site_name': getattr(settings, 'DPASTE_SITE_NAME', 'dpaste.de'), - 'jquery_url': getattr(settings, 'DPASTE_JQUERY_URL', - 'https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js'), -} - # ----------------------------------------------------------------------------- # Snippet Handling # ----------------------------------------------------------------------------- @@ -51,12 +45,7 @@ def snippet_new(request, template_name='dpaste/snippet_new.html'): 'lexer_list': LEXER_LIST, 'is_new': True, } - - return render_to_response( - template_name, - template_context, - RequestContext(request, template_globals) - ) + return render(request, template_name, template_context) def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.html', is_raw=False): @@ -108,11 +97,7 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h 'gist': getattr(settings, 'DPASTE_ENABLE_GIST', True), } - response = render_to_response( - template_name, - template_context, - RequestContext(request, template_globals) - ) + response = render(request, template_name, template_context) if is_raw: response['Content-Type'] = 'text/plain;charset=UTF-8' @@ -158,11 +143,7 @@ def snippet_history(request, template_name='dpaste/snippet_list.html'): 'snippet_list': snippet_list, } - return render_to_response( - template_name, - template_context, - RequestContext(request, template_globals) - ) + return render(request, template_name, template_context) def snippet_diff(request, template_name='dpaste/snippet_diff.html'): @@ -205,11 +186,7 @@ def snippet_diff(request, template_name='dpaste/snippet_diff.html'): 'fileB': fileB, } - return render_to_response( - template_name, - template_context, - RequestContext(request, template_globals) - ) + return render(request, template_name, template_context) def snippet_gist(request, snippet_id): # pragma: no cover @@ -258,11 +235,7 @@ def about(request, template_name='dpaste/about.html'): count=Count('lexer')).order_by('-count')[:5], } - return render_to_response( - template_name, - template_context, - RequestContext(request, template_globals) - ) + return render(request, template_name, template_context) # ----------------------------------------------------------------------------- From d92a169805c695aab1b88d417a429adba475dc20 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Tue, 6 Sep 2016 15:14:27 +0200 Subject: [PATCH 14/32] 2.12 Release --- CHANGELOG | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index d472fc3..ed13a4b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,13 @@ Changelog ========= +2.12 (2016-09-06) +----------------- + +* Fixed "Content Type" problem with Django 1.10. +* Development requirements now use a different version scheme to be + compatible with older `pip` versions. + 2.11 (2016-09-04) ----------------- diff --git a/setup.py b/setup.py index 7b142e5..0ce080d 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ long_description = u'\n\n'.join(( setup( name='dpaste', - version='2.11', + version='2.12', description='dpaste is a Django based pastebin. It\'s intended to run ' 'separately but its also possible to be installed into an ' 'existing Django project like a regular app.', From 4b6dbb34d5d592f0ba2e0904129933d462184d0a Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Fri, 2 Dec 2016 13:38:13 +0100 Subject: [PATCH 15/32] Use Postgres for testing. --- dpaste/settings/local.py.example | 4 ++-- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dpaste/settings/local.py.example b/dpaste/settings/local.py.example index 5c5ffcf..00716ba 100644 --- a/dpaste/settings/local.py.example +++ b/dpaste/settings/local.py.example @@ -9,9 +9,9 @@ MANAGERS = ADMINS DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.mysql', + 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'dpaste', - 'USER': 'root', + 'USER': '', 'PASSWORD': '', } } diff --git a/requirements.txt b/requirements.txt index 7e459fc..23a92a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,4 @@ sphinx_rtd_theme # Deployment specific gunicorn -mysql-python +psycopg2 From d765a0ccda161ef133b2246395420c1e18a4693b Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Fri, 2 Dec 2016 13:38:47 +0100 Subject: [PATCH 16/32] Stub test for leading whitespace bug. --- dpaste/tests/test_snippet.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dpaste/tests/test_snippet.py b/dpaste/tests/test_snippet.py index 56eb1a3..ec4db29 100644 --- a/dpaste/tests/test_snippet.py +++ b/dpaste/tests/test_snippet.py @@ -131,6 +131,16 @@ class SnippetTestCase(TestCase): self.assertEqual(response.status_code, 404) self.assertEqual(Snippet.objects.count(), 0) + # def test_new_snippet_`_whitespace(self): + # # POST data + # data = self.valid_form_data(content=' abc') + # response = self.client.post(self.new_url, data, follow=True) + # self.assertEqual(response.status_code, 200) + # self.assertEqual(Snippet.objects.count(), 1) + # print(response.content) + # self.assertContains(response, '    abc') + + # ------------------------------------------------------------------------- # Reply # ------------------------------------------------------------------------- From 335fa38ab1d3bcdca855bbea792b432cba3909ba Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Fri, 2 Dec 2016 14:44:12 +0100 Subject: [PATCH 17/32] Copy url button --- dpaste/static/dpaste/clipboardjs.min.js | 7 +++++++ dpaste/static/dpaste/theme.css | 14 ++++++++++++++ dpaste/templates/dpaste/base.html | 4 ++++ dpaste/templates/dpaste/snippet_details.html | 9 ++++++++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 dpaste/static/dpaste/clipboardjs.min.js diff --git a/dpaste/static/dpaste/clipboardjs.min.js b/dpaste/static/dpaste/clipboardjs.min.js new file mode 100644 index 0000000..efbbd7f --- /dev/null +++ b/dpaste/static/dpaste/clipboardjs.min.js @@ -0,0 +1,7 @@ +/*! + * clipboard.js v1.5.15 + * https://zenorocha.github.io/clipboard.js + * + * Licensed MIT © Zeno Rocha + */ +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Clipboard=e()}}(function(){var e,t,n;return function e(t,n,i){function o(a,c){if(!n[a]){if(!t[a]){var l="function"==typeof require&&require;if(!c&&l)return l(a,!0);if(r)return r(a,!0);var s=new Error("Cannot find module '"+a+"'");throw s.code="MODULE_NOT_FOUND",s}var u=n[a]={exports:{}};t[a][0].call(u.exports,function(e){var n=t[a][1][e];return o(n?n:e)},u,u.exports,e,t,n,i)}return n[a].exports}for(var r="function"==typeof require&&require,a=0;a0&&void 0!==arguments[0]?arguments[0]:{};this.action=t.action,this.emitter=t.emitter,this.target=t.target,this.text=t.text,this.trigger=t.trigger,this.selectedText=""}},{key:"initSelection",value:function e(){this.text?this.selectFake():this.target&&this.selectTarget()}},{key:"selectFake",value:function e(){var t=this,n="rtl"==document.documentElement.getAttribute("dir");this.removeFake(),this.fakeHandlerCallback=function(){return t.removeFake()},this.fakeHandler=document.body.addEventListener("click",this.fakeHandlerCallback)||!0,this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[n?"right":"left"]="-9999px";var i=window.pageYOffset||document.documentElement.scrollTop;this.fakeElem.addEventListener("focus",window.scrollTo(0,i)),this.fakeElem.style.top=i+"px",this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,document.body.appendChild(this.fakeElem),this.selectedText=(0,o.default)(this.fakeElem),this.copyText()}},{key:"removeFake",value:function e(){this.fakeHandler&&(document.body.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(document.body.removeChild(this.fakeElem),this.fakeElem=null)}},{key:"selectTarget",value:function e(){this.selectedText=(0,o.default)(this.target),this.copyText()}},{key:"copyText",value:function e(){var t=void 0;try{t=document.execCommand(this.action)}catch(e){t=!1}this.handleResult(t)}},{key:"handleResult",value:function e(t){this.emitter.emit(t?"success":"error",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})}},{key:"clearSelection",value:function e(){this.target&&this.target.blur(),window.getSelection().removeAllRanges()}},{key:"destroy",value:function e(){this.removeFake()}},{key:"action",set:function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"copy";if(this._action=t,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')},get:function e(){return this._action}},{key:"target",set:function e(t){if(void 0!==t){if(!t||"object"!==("undefined"==typeof t?"undefined":r(t))||1!==t.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&t.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(t.hasAttribute("readonly")||t.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=t}},get:function e(){return this._target}}]),e}();e.exports=c})},{select:5}],8:[function(t,n,i){!function(o,r){if("function"==typeof e&&e.amd)e(["module","./clipboard-action","tiny-emitter","good-listener"],r);else if("undefined"!=typeof i)r(n,t("./clipboard-action"),t("tiny-emitter"),t("good-listener"));else{var a={exports:{}};r(a,o.clipboardAction,o.tinyEmitter,o.goodListener),o.clipboard=a.exports}}(this,function(e,t,n,i){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function l(e,t){var n="data-clipboard-"+e;if(t.hasAttribute(n))return t.getAttribute(n)}var s=o(t),u=o(n),f=o(i),d=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{};this.action="function"==typeof t.action?t.action:this.defaultAction,this.target="function"==typeof t.target?t.target:this.defaultTarget,this.text="function"==typeof t.text?t.text:this.defaultText}},{key:"listenClick",value:function e(t){var n=this;this.listener=(0,f.default)(t,"click",function(e){return n.onClick(e)})}},{key:"onClick",value:function e(t){var n=t.delegateTarget||t.currentTarget;this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new s.default({action:this.action(n),target:this.target(n),text:this.text(n),trigger:n,emitter:this})}},{key:"defaultAction",value:function e(t){return l("action",t)}},{key:"defaultTarget",value:function e(t){var n=l("target",t);if(n)return document.querySelector(n)}},{key:"defaultText",value:function e(t){return l("text",t)}},{key:"destroy",value:function e(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)}}]),t}(u.default);e.exports=h})},{"./clipboard-action":7,"good-listener":4,"tiny-emitter":6}]},{},[8])(8)}); diff --git a/dpaste/static/dpaste/theme.css b/dpaste/static/dpaste/theme.css index 42aed6c..ddf08c5 100644 --- a/dpaste/static/dpaste/theme.css +++ b/dpaste/static/dpaste/theme.css @@ -63,6 +63,20 @@ tt strong { color: #5393b4; } +input.headline-url { + font-size: 20px; + height: 40px; + width: 210px; + color: #5393b4; + border: none; + box-shadow: none; +} + +button.btn.headline-url-copy { + margin-top: -4px; + padding: 5px 10px 3px 10px; +} + h1, h2, h3, h4 { font-weight: 300; } diff --git a/dpaste/templates/dpaste/base.html b/dpaste/templates/dpaste/base.html index 1d8687f..a8c7115 100644 --- a/dpaste/templates/dpaste/base.html +++ b/dpaste/templates/dpaste/base.html @@ -19,7 +19,9 @@
  • {% trans "History" %}
  • {% trans "New snippet" %} →
  • + {% block headline_wrapper %}

    {% block headline %}{% endblock %}

    + {% endblock %} {% block page %} PAGE MISSING @@ -28,8 +30,10 @@ {% block script_footer %} +