[geany/www.geany.org] 8d3b1d: Drop userprefs and 'guess lexer' to simplify usage
Enrico Tröger
git-noreply at xxxxx
Thu May 23 20:29:38 UTC 2013
Branch: refs/heads/master
Author: Enrico Tröger <enrico.troeger at uvena.de>
Committer: Enrico Tröger <enrico.troeger at uvena.de>
Date: Thu, 23 May 2013 20:29:38 UTC
Commit: 8d3b1d413060d72fa2230313120ec8f2df49c171
https://github.com/geany/www.geany.org/commit/8d3b1d413060d72fa2230313120ec8f2df49c171
Log Message:
-----------
Drop userprefs and 'guess lexer' to simplify usage
Modified Paths:
--------------
pastebin/forms.py
pastebin/highlight.py
pastebin/templates/pastebin/base.html
pastebin/templates/pastebin/snippet_details.html
pastebin/templates/pastebin/snippet_form.html
pastebin/templates/pastebin/snippet_new.html
pastebin/templates/pastebin/userprefs.html
pastebin/urls.py
pastebin/views.py
Modified: pastebin/forms.py
24 files changed, 2 insertions(+), 22 deletions(-)
===================================================================
@@ -12,10 +12,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
from django import forms
from django.utils.translation import ugettext_lazy as _
-from pastebin.highlight import LEXER_LIST_ALL, LEXER_LIST, LEXER_DEFAULT
+from pastebin.highlight import LEXER_LIST, LEXER_DEFAULT
from pastebin.models import Snippet, Spamword
import datetime
@@ -54,13 +53,7 @@ class SnippetForm(forms.ModelForm):
def __init__(self, request, *args, **kwargs):
forms.ModelForm.__init__(self, *args, **kwargs)
self.request = request
-
- try:
- if self.request.session['userprefs'].get('display_all_lexer', False):
- self.fields['lexer'].choices = LEXER_LIST_ALL
- except KeyError:
- pass
-
+ # set author
self.fields['author'].initial = self.request.session.get('author', '')
#----------------------------------------------------------------------
@@ -74,7 +67,6 @@ def clean_content(self):
#----------------------------------------------------------------------
def save(self, parent=None, *args, **kwargs):
-
# Set parent snippet
if parent:
self.instance.parent = parent
@@ -104,15 +96,3 @@ class Meta:
'title',
'author',
'lexer',)
-
-
-########################################################################
-class UserSettingsForm(forms.Form):
-
- default_name = forms.CharField(label=_(u'Default Name'), required=False)
- display_all_lexer = forms.BooleanField(
- label=_(u'Display all lexers'),
- required=False,
- widget=forms.CheckboxInput,
- help_text=_(u'This also enables the super secret \'guess lexer\' function.'),
- )
Modified: pastebin/highlight.py
22 files changed, 5 insertions(+), 17 deletions(-)
===================================================================
@@ -3,12 +3,12 @@
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
-#
+#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -19,8 +19,7 @@
from pygments.lexers import (
PythonLexer,
get_all_lexers,
- get_lexer_by_name,
- guess_lexer)
+ get_lexer_by_name)
LEXER_LIST_ALL = sorted([(i[1][0], i[0]) for i in get_all_lexers()])
@@ -65,22 +64,11 @@ def pygmentize(code_string, lexer_name=LEXER_DEFAULT):
if lexer_name:
lexer = get_lexer_by_name(lexer_name)
else:
- raise Exception
+ raise Exception(u'Unknown lexer')
except:
- try:
- lexer = guess_lexer(code_string)
- except:
- lexer = PythonLexer()
+ lexer = PythonLexer()
try:
return highlight(code_string, lexer, NakedHtmlFormatter())
except:
return escape(code_string)
-
-
-#----------------------------------------------------------------------
-def guess_code_lexer(code_string, default_lexer='unknown'):
- try:
- return guess_lexer(code_string).name
- except ValueError:
- return default_lexer
Modified: pastebin/templates/pastebin/base.html
4 files changed, 0 insertions(+), 4 deletions(-)
===================================================================
@@ -13,7 +13,6 @@
{% url 'about' as url_about %}
{% url 'api' as url_api %}
{% url 'snippet_list' as url_snippet_list %}
-{% url 'snippet_userprefs' as url_snippet_userprefs %}
<div class="row">
<div class="navbar">
@@ -31,9 +30,6 @@
<li class="{% if request.path = url_snippet_list %} active{% endif %}">
<a href="{{ url_snippet_list }}">Recent snippets</a>
</li>
- <li class="{% if request.path = url_snippet_userprefs %} active{% endif %}">
- <a href="{{ url_snippet_userprefs }}">Settings</a>
- </li>
</ul>
</div>
</div>
Modified: pastebin/templates/pastebin/snippet_details.html
18 files changed, 0 insertions(+), 18 deletions(-)
===================================================================
@@ -82,24 +82,6 @@
$('div.snippet div.line#l'+j).toggleClass('marked');
});
});
-
- {% if request.session.userprefs.display_all_lexer %}
- /**
- * Lexer Guessing
- */
- $('#guess_lexer_btn').click(function(){
- $.getJSON('{% url 'snippet_guess_lexer' %}',
- {'codestring': $('#id_content').val()},
- function(data){
- if(data.lexer == "unknown"){
- $('#guess_lexer_btn').css('color', 'red');
- }else{
- $('#id_lexer').val(data.lexer);
- $('#guess_lexer_btn').css('color', 'inherit');
- }
- });
- });
- {% endif %}
});
</script>
{% endblock %}
Modified: pastebin/templates/pastebin/snippet_form.html
3 files changed, 0 insertions(+), 3 deletions(-)
===================================================================
@@ -28,9 +28,6 @@
{% endfor %}
<div class="control-group">
<div class="controls">
- {% if request.session.userprefs.display_all_lexer %}
- <input class="btn" type="button" value="Guess lexer" id="guess_lexer_btn"/>
- {% endif %}
<input type="submit" value="Paste it" class="btn"/>
</div>
</div>
Modified: pastebin/templates/pastebin/snippet_new.html
23 files changed, 0 insertions(+), 23 deletions(-)
===================================================================
@@ -15,26 +15,3 @@
</div>
{% endblock %}
-
-
-
-{% block footer_js %}
-<script type="text/javascript">
-jQuery(document).ready(function(){
- {% if request.session.userprefs.display_all_lexer %}
- $('#guess_lexer_btn').click(function(){
- $.getJSON('{% url 'snippet_guess_lexer' %}',
- {'codestring': $('#id_content').val()},
- function(data){
- if(data.lexer == "unknown"){
- $('#guess_lexer_btn').css('color', 'red');
- }else{
- $('#id_lexer').val(data.lexer);
- $('#guess_lexer_btn').css('color', 'inherit');
- }
- });
- });
- {% endif %}
-});
-</script>
-{% endblock %}
Modified: pastebin/templates/pastebin/userprefs.html
42 files changed, 0 insertions(+), 42 deletions(-)
===================================================================
@@ -1,42 +0,0 @@
-{% extends "pastebin/base.html" %}
-
-
-{% block meta_title %}
- User settings | {{ block.super }}
-{% endblock %}
-
-
-{% block main %}
-<div class="well">
- <h2>User Settings</h2>
-
- {% if settings_saved %}
- <p class="label label-success">
- Your preferences were successfully saved.
- </p>
- {% endif %}
-
- <form class="form-horizontal" method="post" action="{% url 'snippet_userprefs' %}">
- {% csrf_token %}
- {% for field in settings_form %}
- <div>
- <div class="control-group">
- {{ field.label_tag }}
- <div class="controls">
- {{ field }}
- </div>
- </div>
- </div>
- {% endfor %}
- <div class="control-group">
- <div class="controls">
- <input type="submit" value="Save settings" class="btn"/>
- </div>
- </div>
- </form>
-
- <p class="label label-info">
- Remember: Your data is stored in a cookie.
- </p>
-</div>
-{% endblock %}
Modified: pastebin/urls.py
6 files changed, 2 insertions(+), 4 deletions(-)
===================================================================
@@ -3,12 +3,12 @@
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
-#
+#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -27,9 +27,7 @@
url(r'^api/$', 'pastebin.views.api_create'),
url(r'^$', 'pastebin.views.snippet_new', name='home'),
- url(r'^guess/$', 'pastebin.views.guess_lexer', name='snippet_guess_lexer'),
url(r'^latest/$', 'pastebin.views.snippet_list', name='snippet_list'),
- url(r'^your-settings/$', 'pastebin.views.userprefs', name='snippet_userprefs'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/$', 'pastebin.views.snippet_details', name='snippet_details'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/delete/$', 'pastebin.views.snippet_delete', name='snippet_delete'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/raw/$', 'pastebin.views.snippet_details', {'template_name': 'pastebin/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'),
Modified: pastebin/views.py
74 files changed, 1 insertions(+), 73 deletions(-)
===================================================================
@@ -21,16 +21,12 @@
HttpResponse, HttpResponseForbidden
from django.shortcuts import render_to_response, get_object_or_404
from django.template.context import RequestContext
-from django.utils import simplejson
-from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from honeypot.decorators import check_honeypot
from pastebin.api.create import CreateSnippetApiController, SnippetValidationError
-from pastebin.forms import SnippetForm, UserSettingsForm
-from pastebin.highlight import pygmentize, guess_code_lexer
+from pastebin.forms import SnippetForm
from pastebin.models import Snippet
-import difflib
#----------------------------------------------------------------------
@@ -166,74 +162,6 @@ def snippet_list(request, template_name='pastebin/snippet_list.html'):
#----------------------------------------------------------------------
-def userprefs(request, template_name='pastebin/userprefs.html'):
-
- if request.method == 'POST':
- settings_form = UserSettingsForm(request.POST, initial=request.session.get('userprefs', None))
- if settings_form.is_valid():
- request.session['userprefs'] = settings_form.cleaned_data
- settings_saved = True
- else:
- settings_form = UserSettingsForm(initial=request.session.get('userprefs', None))
- settings_saved = False
-
- template_context = {
- 'settings_form': settings_form,
- 'settings_saved': settings_saved,
- }
-
- return render_to_response(
- template_name,
- template_context,
- RequestContext(request))
-
-
-#----------------------------------------------------------------------
-def snippet_diff(request, template_name='pastebin/snippet_diff.html'):
-
- if request.GET.get('a') and request.GET.get('a').isdigit() \
- and request.GET.get('b') and request.GET.get('b').isdigit():
- try:
- fileA = Snippet.objects.get(pk=int(request.GET.get('a')))
- fileB = Snippet.objects.get(pk=int(request.GET.get('b')))
- except ObjectDoesNotExist:
- return HttpResponseBadRequest(u'Selected file(s) does not exist.')
- else:
- return HttpResponseBadRequest(u'You must select two snippets.')
-
- if fileA.content != fileB.content:
- d = difflib.unified_diff(
- fileA.content.splitlines(),
- fileB.content.splitlines(),
- 'Original',
- 'Current',
- lineterm=''
- )
- difftext = '\n'.join(d)
- difftext = pygmentize(difftext, 'diff')
- else:
- difftext = _(u'No changes were made between this two files.')
-
- template_context = {
- 'difftext': difftext,
- 'fileA': fileA,
- 'fileB': fileB,
- }
-
- return render_to_response(
- template_name,
- template_context,
- RequestContext(request))
-
-
-#----------------------------------------------------------------------
-def guess_lexer(request):
- code_string = request.GET.get('codestring', False)
- response = simplejson.dumps({'lexer': guess_code_lexer(code_string)})
- return HttpResponse(response)
-
-
-#----------------------------------------------------------------------
def _get_site(request):
if hasattr(request, 'site'):
return request.site
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list