Mercurial > agora-palash
annotate apps/snippet/views.py @ 133:ba51d3b7740b
Add ability to upload a file to create a snippet
If a file is specified, the contents of that file are used in preference
to the contents of the 'content' text box.
author | dellsystem <ilostwaldo@gmail.com> |
---|---|
date | Sat, 22 Sep 2012 12:20:24 -0400 |
parents | 4f6977515048 |
children | 3a850f49eea6 |
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 |
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
|
16 from agora.apps.snippet.forms import SnippetForm, UserSettingsForm |
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
|
17 from agora.apps.snippet.models import Snippet |
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
|
18 from agora.apps.snippet.highlight import pygmentize, guess_code_lexer, \ |
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 |
101
a8da60d611f7
Reorder imports in some python files
dellsystem <ilostwaldo@gmail.com>
parents:
88
diff
changeset
|
20 from agora.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 |
5956f6349373
Change URL for new snippet view
dellsystem <ilostwaldo@gmail.com>
parents:
55
diff
changeset
|
23 def snippet_explore(request): |
102
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
24 context = { |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
25 'recent_snippets': Snippet.objects.all()[:20] |
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 |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
38 snippet_form = SnippetForm(request.POST, |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
39 request.FILES, |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
40 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
|
41 instance=snippet) |
133
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
42 |
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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 |
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
|
49 recent = Snippet.objects.all()[:10] |
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
|
50 |
133
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
51 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
|
52 'snippet_form': snippet_form, |
88
f15934c73eb2
Rename context variable in snippets/views.py
dellsystem <ilostwaldo@gmail.com>
parents:
85
diff
changeset
|
53 'recent_snippets' : recent, |
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
|
54 } |
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
|
55 |
133
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
56 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
|
57 |
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
|
58 |
46
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
45
diff
changeset
|
59 def snippet_details(request, snippet_id, |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
45
diff
changeset
|
60 is_raw=False): |
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
|
61 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
|
62 snippet.num_views += 1 |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
63 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
|
64 |
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
|
65 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
|
66 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
|
67 |
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
|
68 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
|
69 'content': snippet.content, |
102
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
70 'lexer': snippet.lexer, |
132
4f6977515048
Add default title for snippet children (Re: title)
dellsystem <ilostwaldo@gmail.com>
parents:
102
diff
changeset
|
71 'title': 'Re: %s' % snippet.title, |
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
|
72 } |
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
|
73 |
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
|
74 if request.method == "POST": |
133
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
75 snippet_form = SnippetForm(request.POST, |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 else: |
102
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
83 snippet_form = SnippetForm(initial=new_snippet_initial, |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
84 request=request) |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
85 |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
86 if request.user.is_authenticated(): |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
87 default_pygments_style = request.user.get_profile().pygments_style |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
88 else: |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
89 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
|
90 |
133
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
91 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
|
92 '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
|
93 '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
|
94 '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
|
95 '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
|
96 'language': dict(LEXER_LIST)[snippet.lexer], |
102
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
97 'pygments_styles': PygmentsStyle.objects.all(), |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
98 'default_style': default_pygments_style, |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
99 'no_descendants': len(tree) == 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
|
100 } |
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 |
133
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
102 response = render(request, 'snippet/snippet_details.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
|
103 |
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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 |
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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 '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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 |
45
a46d4cccea4d
More snippet template name changes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
122 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
|
123 |
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
|
124 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
|
125 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
|
126 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
|
127 '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
|
128 None) |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
45
diff
changeset
|
129 ) |
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
|
130 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
|
131 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
|
132 |
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
|
133 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
|
134 '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
|
135 '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
|
136 } |
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 |
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 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
|
139 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
|
140 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
|
141 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
|
142 ) |
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
|
143 |
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 |
45
a46d4cccea4d
More snippet template name changes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
145 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
|
146 |
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
|
147 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
|
148 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
|
149 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
|
150 initial=\ |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
45
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 |
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 '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
|
162 '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
|
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 |
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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 ) |
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
|
170 |
45
a46d4cccea4d
More snippet template name changes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
171 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
|
172 |
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 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 |
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 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
|
183 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
|
184 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
|
185 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
|
186 '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
|
187 '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
|
188 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
|
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 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
|
191 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
|
192 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
|
193 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
|
194 |
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 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
|
196 '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
|
197 '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
|
198 '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
|
199 } |
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 |
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 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
|
202 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
|
203 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
|
204 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
|
205 ) |
46
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
45
diff
changeset
|
206 |
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
|
207 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
|
208 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
|
209 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
|
210 return HttpResponse(response) |