Mercurial > hg > agora-dellsystem
changeset 54:898881bbfdea
Tie snippets to their authors, enable a couple more lexer languages
author | Jordi Gutiérrez Hermoso <jordigh@gmail.com> |
---|---|
date | Mon, 07 Feb 2011 04:43:09 -0600 |
parents | e3f9a241e1bb |
children | d48e8676b18f |
files | apps/snippet/forms.py apps/snippet/highlight.py apps/snippet/models.py apps/snippet/views.py |
diffstat | 4 files changed, 13 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/apps/snippet/forms.py +++ b/apps/snippet/forms.py @@ -78,7 +78,6 @@ fields = ( 'title', 'content', - 'author', 'lexer', )
--- a/apps/snippet/highlight.py +++ b/apps/snippet/highlight.py @@ -6,12 +6,15 @@ LEXER_LIST_ALL = sorted([(i[1][0], i[0]) for i in get_all_lexers()]) LEXER_LIST = ( + ('bash', 'bash'), ('c', 'C'), ('c++', 'C++'), + ('java', 'Java'), ('matlab', 'MATLAB'), ('octave', 'Octave'), ('perl', 'Perl'), ('php', 'PHP'), + ('python', 'Python'), ('text', 'Text only'), ) LEXER_DEFAULT = 'octave'
--- a/apps/snippet/models.py +++ b/apps/snippet/models.py @@ -6,6 +6,7 @@ from django.db.models import permalink from django.utils.translation import ugettext_lazy as _ from agora.apps.snippet.highlight import LEXER_DEFAULT, pygmentize +from django.contrib.auth.models import User t = 'abcdefghijkmnopqrstuvwwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ1234567890' def generate_secret_id(length=4): @@ -14,7 +15,7 @@ class Snippet(models.Model): secret_id = models.CharField(_(u'Secret ID'), max_length=4, blank=True) title = models.CharField(_(u'Title'), max_length=120, blank=True) - author = models.CharField(_(u'Author'), max_length=30, blank=True) + author = models.ForeignKey(User, max_length=30, blank=True, null=True) content = models.TextField(_(u'Content'), ) content_highlighted = models.TextField(_(u'Highlighted Content'), blank=True)
--- a/apps/snippet/views.py +++ b/apps/snippet/views.py @@ -18,7 +18,13 @@ def snippet_new(request, template_name='snippet/snippet_new.djhtml'): if request.method == "POST": - snippet_form = SnippetForm(data=request.POST, request=request) + snippet = Snippet() + try: + snippet.author = request.user + except: + pass + snippet_form = SnippetForm(data=request.POST, request=request, + instance=snippet) if snippet_form.is_valid(): request, new_snippet = snippet_form.save() return HttpResponseRedirect(new_snippet.get_absolute_url()) @@ -95,8 +101,7 @@ try: snippet_list = get_list_or_404(Snippet, - pk__in=request.session.get - ( + pk__in=request.session.get( 'snippet_list', None) )