annotate apps/snippet/views.py @ 190:a4f88ac85837

Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
author ahsanalishahid <ahsan.ali.shahid@gmail.com>
date Thu, 20 Jun 2013 17:17:16 +0500
parents c7be7def8b57
children 499e5f47f278
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
101
a8da60d611f7 Reorder imports in some python files
dellsystem <ilostwaldo@gmail.com>
parents: 88
diff changeset
1 import difflib
a8da60d611f7 Reorder imports in some python files
dellsystem <ilostwaldo@gmail.com>
parents: 88
diff changeset
2
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
3 from django.shortcuts import render_to_response, \
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
4 get_object_or_404, get_list_or_404, render, redirect
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
5 from django.template.context \
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
6 import RequestContext
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
7 from django.http \
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
8 import HttpResponseRedirect, HttpResponseBadRequest, \
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
9 HttpResponse, HttpResponseForbidden
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
10 from django.conf import settings
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
11 from django.core.exceptions import ObjectDoesNotExist
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
12 from django.utils.translation import ugettext_lazy as _
101
a8da60d611f7 Reorder imports in some python files
dellsystem <ilostwaldo@gmail.com>
parents: 88
diff changeset
13 from django.core.urlresolvers import reverse
a8da60d611f7 Reorder imports in some python files
dellsystem <ilostwaldo@gmail.com>
parents: 88
diff changeset
14 from django.utils import simplejson
a8da60d611f7 Reorder imports in some python files
dellsystem <ilostwaldo@gmail.com>
parents: 88
diff changeset
15
151
c7be7def8b57 Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents: 144
diff changeset
16 from apps.snippet.forms import SnippetForm, UserSettingsForm
c7be7def8b57 Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents: 144
diff changeset
17 from apps.snippet.models import Snippet
c7be7def8b57 Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents: 144
diff changeset
18 from apps.snippet.highlight import pygmentize, guess_code_lexer, \
55
d48e8676b18f Show snippets by user in their profile, and show 10 latest snippets on the add snippet page
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 54
diff changeset
19 LEXER_LIST
151
c7be7def8b57 Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents: 144
diff changeset
20 from apps.pygments_style.models import PygmentsStyle
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
21
85
5956f6349373 Change URL for new snippet view
dellsystem <ilostwaldo@gmail.com>
parents: 55
diff changeset
22
151
c7be7def8b57 Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents: 144
diff changeset
23 def explore(request):
102
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
24 context = {
139
b8e0bdc37e32 Hide snippets created by anonymous users
dellsystem <ilostwaldo@gmail.com>
parents: 134
diff changeset
25 'recent_snippets': Snippet.objects.public()[:20]
102
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
26 }
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
27
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
28 return render(request, 'snippet/explore.html', context)
85
5956f6349373 Change URL for new snippet view
dellsystem <ilostwaldo@gmail.com>
parents: 55
diff changeset
29
5956f6349373 Change URL for new snippet view
dellsystem <ilostwaldo@gmail.com>
parents: 55
diff changeset
30
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
31 def snippet_new(request):
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
32 if request.method == "POST":
54
898881bbfdea Tie snippets to their authors, enable a couple more lexer languages
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 46
diff changeset
33 snippet = Snippet()
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
34
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
35 if request.user.is_authenticated():
54
898881bbfdea Tie snippets to their authors, enable a couple more lexer languages
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 46
diff changeset
36 snippet.author = request.user
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
37
190
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
38
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
39 snippet_form = SnippetForm(request.POST,
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
40 request.FILES,
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
41 request=request,
54
898881bbfdea Tie snippets to their authors, enable a couple more lexer languages
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 46
diff changeset
42 instance=snippet)
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
43
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
44 if snippet_form.is_valid():
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
45 request, new_snippet = snippet_form.save()
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
46 return redirect(new_snippet)
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
47 else:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
48 snippet_form = SnippetForm(request=request)
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
49
139
b8e0bdc37e32 Hide snippets created by anonymous users
dellsystem <ilostwaldo@gmail.com>
parents: 134
diff changeset
50 recent = Snippet.objects.public()[:10]
55
d48e8676b18f Show snippets by user in their profile, and show 10 latest snippets on the add snippet page
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 54
diff changeset
51
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
52 context = {
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
53 'snippet_form': snippet_form,
88
f15934c73eb2 Rename context variable in snippets/views.py
dellsystem <ilostwaldo@gmail.com>
parents: 85
diff changeset
54 'recent_snippets' : recent,
190
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
55 'show': True, # always true b/c guest posting is allowed
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
56 }
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
57
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
58 return render(request, 'snippet/snippet_new.djhtml', context)
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
59
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
60
190
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
61 def snippet_details(request, snippet_id,template_name='snippet/snippet_details.djhtml', is_raw=False):
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
62
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
63 snippet = get_object_or_404(Snippet, secret_id=snippet_id)
102
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
64 snippet.num_views += 1
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
65 snippet.save()
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
66
190
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
67
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
68 if request.user.is_authenticated() and hasattr(snippet,'author'):
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
69 show = True
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
70 elif ( request.user.is_anonymous() ) and (hasattr(snippet,'author') ):
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
71 if snippet.author == None:
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
72 show = True
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
73 else:
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
74 show = False
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
75 else:
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
76 show = False
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
77
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
78 tree = snippet.get_root()
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
79 tree = tree.get_descendants(include_self=True)
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
80
134
3a850f49eea6 Remove multiple 'RE: 's from default reply title
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
81 if snippet.title.startswith('Re: '):
3a850f49eea6 Remove multiple 'RE: 's from default reply title
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
82 reply_title = snippet.title
3a850f49eea6 Remove multiple 'RE: 's from default reply title
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
83 else:
3a850f49eea6 Remove multiple 'RE: 's from default reply title
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
84 reply_title = 'Re: %s' % snippet.title
3a850f49eea6 Remove multiple 'RE: 's from default reply title
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
85
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
86 new_snippet_initial = {
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
87 'content': snippet.content,
102
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
88 'lexer': snippet.lexer,
134
3a850f49eea6 Remove multiple 'RE: 's from default reply title
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
89 'title': reply_title,
190
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
90
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
91 }
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
92
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
93 if request.method == "POST":
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
94 snippet_form = SnippetForm(request.POST,
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
95 request.FILES,
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
96 request=request,
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
97 initial=new_snippet_initial)
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
98 if snippet_form.is_valid():
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
99 request, new_snippet = snippet_form.save(parent=snippet)
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
100 return redirect(new_snippet)
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
101 else:
102
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
102 snippet_form = SnippetForm(initial=new_snippet_initial,
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
103 request=request)
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
104
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
105 if request.user.is_authenticated():
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
106 default_pygments_style = request.user.get_profile().pygments_style
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
107 else:
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
108 default_pygments_style = PygmentsStyle.objects.get(pk=1)
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
109
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 132
diff changeset
110 context = {
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
111 'snippet_form': snippet_form,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
112 'snippet': snippet,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
113 'lines': range(snippet.get_linecount()),
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
114 'tree': tree,
55
d48e8676b18f Show snippets by user in their profile, and show 10 latest snippets on the add snippet page
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 54
diff changeset
115 'language': dict(LEXER_LIST)[snippet.lexer],
102
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
116 'pygments_styles': PygmentsStyle.objects.all(),
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
117 'default_style': default_pygments_style,
f872c643b056 Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents: 101
diff changeset
118 'no_descendants': len(tree) == 1,
190
a4f88ac85837 Changes: Now guest users cannot see revision history and they also cannot see snippets posted by registered users. To see snippets posted by registered users, one has to login.
ahsanalishahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
119 'show': show,
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
120 }
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
121
144
77babc4afe34 Fix bug in raw snippet view
dellsystem <ilostwaldo@gmail.com>
parents: 139
diff changeset
122 response = render(request, template_name, context)
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
123
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
124 if is_raw:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
125 response['Content-Type'] = 'text/plain'
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
126 return response
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
127 else:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
128 return response
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
129
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
130 def snippet_delete(request, snippet_id):
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
131 snippet = get_object_or_404(Snippet, secret_id=snippet_id)
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
132 try:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
133 snippet_list = request.session['snippet_list']
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
134 except KeyError:
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
135 return HttpResponseForbidden('You have no recent snippet list, '\
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
136 'cookie error?')
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
137 if not snippet.pk in snippet_list:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
138 return HttpResponseForbidden('That\'s not your snippet, sucka!')
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
139 snippet.delete()
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
140 return HttpResponseRedirect(reverse('snippet_new'))
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
141
45
a46d4cccea4d More snippet template name changes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 42
diff changeset
142 def snippet_userlist(request, template_name='snippet/snippet_list.djhtml'):
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
143
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
144 try:
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
145 snippet_list = get_list_or_404(Snippet,
54
898881bbfdea Tie snippets to their authors, enable a couple more lexer languages
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 46
diff changeset
146 pk__in=request.session.get(
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
147 'snippet_list',
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
148 None)
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
149 )
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
150 except ValueError:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
151 snippet_list = None
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
152
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
153 template_context = {
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
154 'snippets_max': getattr(settings, 'MAX_SNIPPETS_PER_USER', 10),
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
155 'snippet_list': snippet_list,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
156 }
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
157
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
158 return render_to_response(
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
159 template_name,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
160 template_context,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
161 RequestContext(request)
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
162 )
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
163
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
164
45
a46d4cccea4d More snippet template name changes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 42
diff changeset
165 def userprefs(request, template_name='snippet/userprefs.djhtml'):
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
166
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
167 if request.method == 'POST':
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
168 settings_form = \
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
169 UserSettingsForm(request.POST,
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
170 initial=\
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
171 request.session.get('userprefs', None))
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
172 if settings_form.is_valid():
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
173 request.session['userprefs'] = settings_form.cleaned_data
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
174 settings_saved = True
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
175 else:
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
176 settings_form = UserSettingsForm(initial=\
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
177 request.session.get('userprefs', None))
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
178 settings_saved = False
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
179
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
180 template_context = {
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
181 'settings_form': settings_form,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
182 'settings_saved': settings_saved,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
183 }
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
184
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
185 return render_to_response(
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
186 template_name,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
187 template_context,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
188 RequestContext(request)
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
189 )
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
190
45
a46d4cccea4d More snippet template name changes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 42
diff changeset
191 def snippet_diff(request, template_name='snippet/snippet_diff.djhtml'):
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
192
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
193 if request.GET.get('a').isdigit() and request.GET.get('b').isdigit():
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
194 try:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
195 fileA = Snippet.objects.get(pk=int(request.GET.get('a')))
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
196 fileB = Snippet.objects.get(pk=int(request.GET.get('b')))
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
197 except ObjectDoesNotExist:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
198 return HttpResponseBadRequest(u'Selected file(s) does not exist.')
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
199 else:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
200 return HttpResponseBadRequest(u'You must select two snippets.')
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
201
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
202 if fileA.content != fileB.content:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
203 d = difflib.unified_diff(
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
204 fileA.content.splitlines(),
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
205 fileB.content.splitlines(),
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
206 'Original',
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
207 'Current',
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
208 lineterm=''
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
209 )
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
210 difftext = '\n'.join(d)
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
211 difftext = pygmentize(difftext, 'diff')
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
212 else:
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
213 difftext = _(u'No changes were made between this two files.')
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
214
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
215 template_context = {
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
216 'difftext': difftext,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
217 'fileA': fileA,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
218 'fileB': fileB,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
219 }
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
220
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
221 return render_to_response(
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
222 template_name,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
223 template_context,
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
224 RequestContext(request)
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
225 )
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 45
diff changeset
226
42
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
227 def guess_lexer(request):
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
228 code_string = request.GET.get('codestring', False)
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
229 response = simplejson.dumps({'lexer': guess_code_lexer(code_string)})
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
230 return HttpResponse(response)