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/3] 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/3] 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 #}
- - #!/usr/bin/env python
-
- from urllib import urlencode
- from urllib2 import Request, urlopen
- from sys import stdin
-
- def paste_code():
- request = Request('https://dpaste.de/api/', urlencode({
- 'content': stdin.read(),
- 'lexer': 'python',
- 'format': 'url',
- }))
- print urlopen(request).read()
-
- if __name__ == '__main__':
- paste_code()
+ - #!/usr/bin/env python
-
- from urllib import urlencode
- from urllib2 import Request, urlopen
- from sys import stdin
-
- def paste_code():
- request = Request('{{ base_url }}/api/', urlencode({
- 'content': stdin.read(),
- 'lexer': 'python',
- 'format': 'url',
- }))
- print urlopen(request).read()
-
- if __name__ == '__main__':
- 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