From e6781d9dbcb76b7c17205f0e08629f17214363f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 9 Mar 2017 11:10:50 +0000 Subject: [PATCH 1/6] Expose `base_url` in global context for templates Since `DPASTE_BASE_URL` is a dynamic setting that can be changed when the application is self-hosted, the templates need to have access to the variable when rendering the templates so that they do not erroneously display the dpaste.de url. --- dpaste/context_processors.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dpaste/context_processors.py b/dpaste/context_processors.py index f4dbefa..ee72c7f 100644 --- a/dpaste/context_processors.py +++ b/dpaste/context_processors.py @@ -2,6 +2,7 @@ from django.conf import settings def dpaste_globals(request): return { + 'base_url': getattr(settings, 'DPASTE_BASE_URL', 'https://dpaste.de'), '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'), From ec533a9dcca5e18e8ac48425086329c1873fbda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 9 Mar 2017 11:13:29 +0000 Subject: [PATCH 2/6] Replace hard-coded urls in about page with `base_url` Display the `DPASTE_BASE_URL` instead of the hard-coded value `dpaste.de`. --- dpaste/templates/dpaste/about.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dpaste/templates/dpaste/about.html b/dpaste/templates/dpaste/about.html index aee113d..9834b7e 100644 --- a/dpaste/templates/dpaste/about.html +++ b/dpaste/templates/dpaste/about.html @@ -37,14 +37,14 @@ on this page. For a quick start here is a code example (Python 2.x):

{# Just put the script in dpaste and copy the source node #} -
  1. #!/usr/bin/env python
  2.  
  3. from urllib import urlencode
  4. from urllib2 import Request, urlopen
  5. from sys import stdin
  6.  
  7. def paste_code():
  8.     request = Request('https://dpaste.de/api/', urlencode({
  9.         'content': stdin.read(),
  10.         'lexer': 'python',
  11.         'format': 'url',
  12.     }))
  13.     print urlopen(request).read()
  14.  
  15. if __name__ == '__main__':
  16.     paste_code()
+
  1. #!/usr/bin/env python
  2.  
  3. from urllib import urlencode
  4. from urllib2 import Request, urlopen
  5. from sys import stdin
  6.  
  7. def paste_code():
  8.     request = Request('{{ base_url }}/api/', urlencode({
  9.         'content': stdin.read(),
  10.         'lexer': 'python',
  11.         'format': 'url',
  12.     }))
  13.     print urlopen(request).read()
  14.  
  15. if __name__ == '__main__':
  16.     paste_code()

Save this script in /usr/local/bin/dpaste and give it the executable bit: chmod +x /usr/local/bin/dpaste.

Usage: cat foo.txt | dpaste

An alternative would be to just use curl: - alias dpaste="curl -F 'content=<-' https://dpaste.de/api/"

+ alias dpaste="curl -F 'content=<-' {{ base_url }}/api/"

Applications using the API:

@@ -84,7 +84,7 @@

Type the 4 letter code of your snippet in the field and submit. - Like this yellow one here: http://dpaste.de/SiZrT + Like this yellow one here: {{ base_url }}/SiZrT

From 0e980b1eafe1bfc7f2d6f159ed05171e9771375a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 9 Mar 2017 14:27:09 +0000 Subject: [PATCH 3/6] Change variable name from `base_url` to `site_url` So it's more in-line with other global context variables ie. `site_name`. See https://github.com/bartTC/dpaste/pull/89#issuecomment-285331008 --- dpaste/context_processors.py | 2 +- dpaste/templates/dpaste/about.html | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dpaste/context_processors.py b/dpaste/context_processors.py index ee72c7f..98939ef 100644 --- a/dpaste/context_processors.py +++ b/dpaste/context_processors.py @@ -2,7 +2,7 @@ from django.conf import settings def dpaste_globals(request): return { - 'base_url': getattr(settings, 'DPASTE_BASE_URL', 'https://dpaste.de'), + 'site_url': getattr(settings, 'DPASTE_BASE_URL', 'https://dpaste.de'), '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/templates/dpaste/about.html b/dpaste/templates/dpaste/about.html index 9834b7e..e527a22 100644 --- a/dpaste/templates/dpaste/about.html +++ b/dpaste/templates/dpaste/about.html @@ -37,14 +37,14 @@ on this page. For a quick start here is a code example (Python 2.x):

{# Just put the script in dpaste and copy the source node #} -
  1. #!/usr/bin/env python
  2.  
  3. from urllib import urlencode
  4. from urllib2 import Request, urlopen
  5. from sys import stdin
  6.  
  7. def paste_code():
  8.     request = Request('{{ base_url }}/api/', urlencode({
  9.         'content': stdin.read(),
  10.         'lexer': 'python',
  11.         'format': 'url',
  12.     }))
  13.     print urlopen(request).read()
  14.  
  15. if __name__ == '__main__':
  16.     paste_code()
+
  1. #!/usr/bin/env python
  2.  
  3. from urllib import urlencode
  4. from urllib2 import Request, urlopen
  5. from sys import stdin
  6.  
  7. def paste_code():
  8.     request = Request('{{ site_url }}/api/', urlencode({
  9.         'content': stdin.read(),
  10.         'lexer': 'python',
  11.         'format': 'url',
  12.     }))
  13.     print urlopen(request).read()
  14.  
  15. if __name__ == '__main__':
  16.     paste_code()

Save this script in /usr/local/bin/dpaste and give it the executable bit: chmod +x /usr/local/bin/dpaste.

Usage: cat foo.txt | dpaste

An alternative would be to just use curl: - alias dpaste="curl -F 'content=<-' {{ base_url }}/api/"

+ alias dpaste="curl -F 'content=<-' {{ site_url }}/api/"

Applications using the API:

@@ -84,7 +84,7 @@

Type the 4 letter code of your snippet in the field and submit. - Like this yellow one here: {{ base_url }}/SiZrT + Like this yellow one here: {{ site_url }}/SiZrT

From 4ae6e0aaa65aaac3bcf49b71f107c1242c3fd4ad Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sat, 29 Apr 2017 08:53:14 +0200 Subject: [PATCH 4/6] Added Django 1.11 to the test list. --- .travis.yml | 1 + tox.ini | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 06ec320..9827095 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ env: - DJANGO: django>=1.8,<1.9 - DJANGO: django>=1.9,<1.10 - DJANGO: django>=1.10,<1.11 + - DJANGO: django>=1.11,<1.12 before_install: - pip install codecov diff --git a/tox.ini b/tox.ini index 232ada2..5350d2e 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ toxworkdir=/tmp/tox/dpaste skip_missing_interpreters=True envlist= - py{27,34,35,36}-django-{18,19,110} + py{27,34,35,36}-django-{18,19,110,111} [testenv] install_command = @@ -16,3 +16,4 @@ deps= django-18: django>=1.8,<1.9 django-19: django>=1.9,<1.10 django-110: django>=1.10,<1.11 + django-111: django>=1.11,<1.12 From fef7dd79ee60bbf38b634f3a8acb6a22bfcf75ea Mon Sep 17 00:00:00 2001 From: lb1c Date: Fri, 19 May 2017 15:30:27 +0200 Subject: [PATCH 5/6] Update installation.rst --- docs/installation.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 5e0e513..9e402b7 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -15,11 +15,15 @@ Ready to contribute? Here's how to set up `dpaste` for local development. $ cd dpaste/ $ pip install -r requirements.txt -4. Run the commands:: +4. Copy the settings file and edit it, to meet your needs:: + + $ cp dpaste/settings/local.py.example dpaste/settings/local.py + $ nano dpaste/settings/local.py + +5. Initialze the database by running the command:: - $ python manage.py syncdb $ python manage.py migrate -5. Start up the webserver:: +6. Start up the webserver:: $ python manage.py runserver From 6caa5bff489f3315e6973a3ac3bc374c377c00f2 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Mon, 5 Jun 2017 20:31:45 +0200 Subject: [PATCH 6/6] Fixed curl docs. Closes #92 --- docs/api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.rst b/docs/api.rst index c1ccb65..ecc9105 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -123,6 +123,6 @@ A sample Python 2 script to publish snippets:: You can simply use curl to publish a whole file:: - $ alias dpaste="curl -F 'content=<-' https://dpaste.de/api/?format=url" + $ alias dpaste="curl -F 'format=url' -F 'content=<-' https://dpaste.de/api/" $ cat foo.txt | dpaste https://dpaste.de/ke2pB