Skip to content

Commit

Permalink
Remove Pastebin form and related code
Browse files Browse the repository at this point in the history
The Pastebin is spammed a lot and not of much use anyway. So remove it.
Keep the API working for the GeniusPaste plugin.
  • Loading branch information
eht16 committed Jan 15, 2023
1 parent e721ef9 commit 144b440
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 371 deletions.
8 changes: 0 additions & 8 deletions geany/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@

# 3rd party
"compressor",
"captcha", # for pastebin
"django_extensions",
"honeypot", # for pastebin
"mezzanine_pagedown",
"mezzanine_sync_pages.apps.MezzanineSyncPagesAppConfig",
# "shortener", # disabled until it is fixed for Django 4.0 or we remove it completely
Expand Down Expand Up @@ -434,12 +432,6 @@
'compressor.filters.cssmin.CSSMinFilter']
COMPRESS_OFFLINE = True

# django-honeypot
HONEYPOT_FIELD_NAME = 'website'
CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge'
CAPTCHA_NOISE_FUNCTIONS = ('captcha.helpers.noise_dots',)
CAPTCHA_MATH_CHALLENGE_OPERATOR = '*'

NIGHTLYBUILDS_BASE_DIR = '/path/to/nightly/builds'

STATIC_DOCS_GITHUB_API_TOKEN = None
Expand Down
1 change: 0 additions & 1 deletion geany/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@

# Pastebin
path('p/', include('pastebin.urls')),
path('captcha/', include('captcha.urls')),

# URL Shortener
# path('s/', include('urlshortener.urls')), # disabled until it is fixed for Django 4.0
Expand Down
3 changes: 1 addition & 2 deletions pastebin/api/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _validate_passed_fields(self):
def _validate_against_snippet_form(self):
self._preprocess_data()

snippet_form = SnippetForm(request=self._request, data=self._data)
snippet_form = SnippetForm(data=self._data)
# SnippetForm allows only a subset of lexer choices except the user enables all lexers
# in her session but since we don't have a session here, we allow all unconditionally
snippet_form.fields['lexer'].choices = LEXER_LIST_ALL
Expand All @@ -115,7 +115,6 @@ def _validate_against_snippet_form(self):

# ----------------------------------------------------------------------
def _preprocess_data(self):
# compatibility with SnippetForm
self._data['expire_options'] = self._data.get('expires', 3600)
# try to map lexer from a Geany filetype name to a Pygments lexer name
# fallback to 'text' as default, also use that default in case no lexer was given at all
Expand Down
60 changes: 7 additions & 53 deletions pastebin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from datetime import timedelta

from captcha.fields import CaptchaField, CaptchaTextInput
from django import forms
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
Expand All @@ -36,15 +35,6 @@
EXPIRE_DEFAULT = 3600 * 24 * 30


class ExpiryOptionsWidget(forms.RadioSelect):
template_name = 'pastebin/widgets/radio.html'
option_inherits_attrs = False


class CaptchaTextInputWidget(CaptchaTextInput):
template_name = 'pastebin/widgets/captcha_field.html'


class SnippetForm(forms.ModelForm):

lexer = forms.ChoiceField(
Expand All @@ -57,19 +47,15 @@ class SnippetForm(forms.ModelForm):
choices=EXPIRE_CHOICES,
initial=EXPIRE_DEFAULT,
label=_('Expires'),
widget=ExpiryOptionsWidget,
)

captcha = CaptchaField(widget=CaptchaTextInputWidget(attrs={
'placeholder': 'Please solve the challenge'}))

# ----------------------------------------------------------------------
def __init__(self, request, *args, **kwargs):
forms.ModelForm.__init__(self, *args, **kwargs)
self.request = request
self.fields['captcha'].label = 'Verification'
# set author
self.fields['author'].initial = self.request.session.get('author', '')
class Meta:
model = Snippet
fields = (
'content',
'title',
'author',
'lexer',)

# ----------------------------------------------------------------------
def _clean_field(self, field_name):
Expand All @@ -92,35 +78,3 @@ def clean_content(self):
# ----------------------------------------------------------------------
def clean_title(self):
return self._clean_field('title')

# ----------------------------------------------------------------------
def save(self, *args, **kwargs): # pylint: disable=signature-differs
# Set parent snippet
parent = kwargs.pop('parent', None)
if parent:
self.instance.parent = parent

# Add expire datestamp
self.instance.expires = timezone.now() + \
timedelta(seconds=int(self.cleaned_data['expire_options']))

# Save snippet in the db
super().save(self, *args, **kwargs)

# Add snippet to the user's session
if not self.request.session.get('snippet_list', False):
self.request.session['snippet_list'] = []
self.request.session['snippet_list'].append(self.instance.pk)

# Remember author
self.request.session['author'] = self.instance.author

return self.request, self.instance

class Meta:
model = Snippet
fields = (
'content',
'title',
'author',
'lexer',)
7 changes: 5 additions & 2 deletions pastebin/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ def wrap(self, source):

# ----------------------------------------------------------------------
def _wrap_code(self, inner):
for code, text in inner:
yield code, text
yield from inner

# ----------------------------------------------------------------------
def _wrap_div(self, inner):
yield from inner


# ----------------------------------------------------------------------
Expand Down
88 changes: 0 additions & 88 deletions pastebin/templates/pastebin/api.html

This file was deleted.

12 changes: 0 additions & 12 deletions pastebin/templates/pastebin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
{% endblock %}

{% block top_menu %}
{% url 'snippet_new' as url_snippet_new %}
{% url 'snippet_help' as url_help %}
{% url 'snippet_help_api' as url_api %}
{% url 'snippet_list' as url_snippet_list %}

<div class="navbar navbar-inverse navbar-fixed-top">
Expand All @@ -27,15 +24,6 @@

<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav" id="navbar">
<li class="{% if request.path == url_snippet_new %} active{% endif %}">
<a href="{{ url_snippet_new }}">New snippet</a>
</li>
<li class="{% if request.path == url_help %} active{% endif %}">
<a href="{{ url_help }}">Help</a>
</li>
<li class="{% if request.path == url_api %} active{% endif %}">
<a href="{{ url_api }}">API</a>
</li>
<li class="{% if request.path == url_snippet_list %} active{% endif %}">
<a href="{{ url_snippet_list }}">Recent snippets</a>
</li>
Expand Down
27 changes: 0 additions & 27 deletions pastebin/templates/pastebin/help.html

This file was deleted.

15 changes: 5 additions & 10 deletions pastebin/templates/pastebin/snippet_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ <h1>
<div class="snippet-options">
<abbr title="Time to life">TTL:</abbr> {{ snippet.expires|timeuntil_or_forever }}
&mdash;
{% if snippet.pk|in_list:request.session.snippet_list %}
<a onclick="return confirm('Really delete this snippet?')" href="{% url 'snippet_delete' snippet.secret_id %}">Delete</a>
&mdash;
{% endif %}
{% if snippet.parent_id %}
(Copy of <a href="{{ snippet.parent.get_absolute_url }}">snippet #{{ snippet.parent.id }}</a>)
&mdash;
Expand All @@ -31,14 +27,13 @@ <h1>
<p>on <span class="date">{{ snippet.published|date:"Y/m/d G:i:s" }} (UTC)</span> by
{% if snippet.author %}{{ snippet.author }}{% else %}Anonymous{% endif %}
as {{ snippet.lexer|title }}</p>

<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab1" data-toggle="tab">Markup</a></li>
<li><a href="#tab2" data-toggle="tab">Plain</a></li>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#markup" data-toggle="tab" aria-controls="markup" role="tab">Markup</a></li>
<li role="presentation"><a href="#plain" data-toggle="tab" aria-controls="plain" role="tab">Plain</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<div class="tab-pane active" role="tabpanel" id="markup">
<div class="snippet">
<ol>
{% for line in snippet|highlight %}
Expand All @@ -49,7 +44,7 @@ <h1>
</ol>
</div>
</div>
<div class="tab-pane" id="tab2">
<div class="tab-pane" role="tabpanel" id="plain">
<div class="snippet-plain">
<textarea class="snippet-plain">{{ snippet.content }}</textarea>
</div>
Expand Down
41 changes: 0 additions & 41 deletions pastebin/templates/pastebin/snippet_form.html

This file was deleted.

24 changes: 0 additions & 24 deletions pastebin/templates/pastebin/snippet_new.html

This file was deleted.

0 comments on commit 144b440

Please sign in to comment.