Backwards incompatible: Removed Gist button feature.

This commit is contained in:
Martin Mahner 2017-01-19 12:16:07 +01:00
parent ae27acf1f9
commit a6a5bc726b
4 changed files with 4 additions and 38 deletions

View file

@ -95,14 +95,17 @@ behavior without touching the code:
``3600 * 24 * 30 * 12 * 100`` or simpler: ``DPASTE_EXPIRE_CHOICES[2][0]``. ``3600 * 24 * 30 * 12 * 100`` or simpler: ``DPASTE_EXPIRE_CHOICES[2][0]``.
``DPASTE_ENABLE_GIST`` ``DPASTE_ENABLE_GIST``
**Removed in Version 2.13!**
Boolean. Whether to display the Gist button for re-pasting to GitHub. Boolean. Whether to display the Gist button for re-pasting to GitHub.
Default: ``True`` Default: ``True``
``DPASTE_DEFAULT_GIST_NAME`` ``DPASTE_DEFAULT_GIST_NAME``
**Removed in Version 2.13!**
String. The filename used when pasting a snippet on Github Gist. String. The filename used when pasting a snippet on Github Gist.
Default: ``dpaste.de_snippet.py`` Default: ``dpaste.de_snippet.py``
``DPASTE_DEFAULT_GIST_DESCRIPTION`` ``DPASTE_DEFAULT_GIST_DESCRIPTION``
**Removed in Version 2.13!**
String. The filename used when pasting a snippet on Github Gist. String. The filename used when pasting a snippet on Github Gist.
Default: ``dpaste.de_snippet.py`` Default: ``dpaste.de_snippet.py``

View file

@ -48,10 +48,6 @@
{% if snippet.expire_type != 3 %} {% if snippet.expire_type != 3 %}
<a class="btn" href="{% url "snippet_details_raw" snippet.secret_id %}"><i class="icon-align-left"></i> {% trans "View Raw" %}</a> <a class="btn" href="{% url "snippet_details_raw" snippet.secret_id %}"><i class="icon-align-left"></i> {% trans "View Raw" %}</a>
{% endif %} {% endif %}
{% if gist %}
<a class="btn" href="{% url "snippet_gist" snippet.secret_id %}"
rel="nofollow" title="Create a secret Gist"><i class="icon-share"></i> {% trans "Gist" %}</a>
{% endif %}
{% if snippet.lexer != 'text' %} {% if snippet.lexer != 'text' %}
<a class="btn" href="#" id="toggleWordwrap">Wordwrap</a> <a class="btn" href="#" id="toggleWordwrap">Wordwrap</a>
{% endif %} {% endif %}

View file

@ -14,6 +14,5 @@ urlpatterns = [
url(r'^delete/$', views.snippet_delete, name='snippet_delete'), url(r'^delete/$', views.snippet_delete, name='snippet_delete'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d,})/?$' % L, views.snippet_details, name='snippet_details'), url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d,})/?$' % L, views.snippet_details, name='snippet_details'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d,})/delete/$' % L, views.snippet_delete, name='snippet_delete'), url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d,})/delete/$' % L, views.snippet_delete, name='snippet_delete'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d,})/gist/$' % L, views.snippet_gist, name='snippet_gist'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d,})/raw/?$' % L, views.snippet_details, {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'), url(r'^(?P<snippet_id>[a-zA-Z0-9]{%d,})/raw/?$' % L, views.snippet_details, {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'),
] ]

View file

@ -2,7 +2,6 @@ import datetime
import difflib import difflib
import json import json
import requests
from django.conf import settings from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
@ -10,7 +9,6 @@ from django.db.models import Count
from django.http import (Http404, HttpResponse, HttpResponseBadRequest, from django.http import (Http404, HttpResponse, HttpResponseBadRequest,
HttpResponseRedirect) HttpResponseRedirect)
from django.shortcuts import get_object_or_404, render 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.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.defaults import page_not_found as django_page_not_found from django.views.defaults import page_not_found as django_page_not_found
@ -23,6 +21,7 @@ from .highlight import (LEXER_DEFAULT, LEXER_KEYS, LEXER_LIST,
LEXER_WORDWRAP, PLAIN_CODE) LEXER_WORDWRAP, PLAIN_CODE)
from .models import ONETIME_LIMIT, Snippet from .models import ONETIME_LIMIT, Snippet
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Snippet Handling # Snippet Handling
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -185,37 +184,6 @@ def snippet_diff(request, template_name='dpaste/snippet_diff.html'):
return render(request, template_name, template_context) return render(request, template_name, template_context)
def snippet_gist(request, snippet_id): # pragma: no cover
"""
Put a snippet on Github Gist.
"""
if not getattr(settings, 'DPASTE_ENABLE_GIST', True):
raise Http404('Gist creation is disabled on this installation.')
snippet = get_object_or_404(Snippet, secret_id=snippet_id)
data = {
'description': getattr(settings, 'DPASTE_DEFAULT_GIST_DESCRIPTION', ''),
'public': False,
'files': {
getattr(settings, 'DPASTE_DEFAULT_GIST_NAME', 'dpaste.de_snippet.py'): {
'content': snippet.content,
}
}
}
try:
payload = json.dumps(data)
response = requests.post('https://api.github.com/gists', data=payload)
response_dict = response.json()
gist_url = response_dict.get('html_url')
# Github could be down, could return invalid JSON, it's rare
except:
return HttpResponse('Creating a Github Gist failed. Sorry, please go back and try again.')
return HttpResponseRedirect(gist_url)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Static pages # Static pages
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------