Mercurial > agora-palash
annotate apps/snippet/views.py @ 202:499e5f47f278
Add necessary code to views and forms of snippet for Ratings
author | Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com> |
---|---|
date | Fri, 19 Jul 2013 22:09:29 +0500 |
parents | a4f88ac85837 |
children | d534881629ff |
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 |
202
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
110 |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
111 |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
112 score = (snippet.rating.score/snippet.rating.votes) |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
113 |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
114 |
133
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
132
diff
changeset
|
115 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
|
116 '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
|
117 '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
|
118 '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
|
119 '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
|
120 'language': dict(LEXER_LIST)[snippet.lexer], |
102
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
121 'pygments_styles': PygmentsStyle.objects.all(), |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
122 'default_style': default_pygments_style, |
f872c643b056
Updates to snippet functionality (see details)
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
123 '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
|
124 'show': show, |
202
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
125 'score' : score, |
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
|
126 } |
ab608f27ecd5
Copy preliminary django-paste code for 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 |
144
77babc4afe34
Fix bug in raw snippet view
dellsystem <ilostwaldo@gmail.com>
parents:
139
diff
changeset
|
128 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
|
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 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 |
ab608f27ecd5
Copy preliminary django-paste code for 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 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 '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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 |
45
a46d4cccea4d
More snippet template name changes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
148 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
|
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 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
|
151 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
|
152 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
|
153 '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
|
154 None) |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
45
diff
changeset
|
155 ) |
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
|
156 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
|
157 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
|
158 |
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
|
159 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
|
160 '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
|
161 '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
|
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 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
|
165 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
|
166 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
|
167 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
|
168 ) |
ab608f27ecd5
Copy preliminary django-paste code for 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 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
|
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.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
|
174 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
|
175 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
|
176 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 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 |
ab608f27ecd5
Copy preliminary django-paste code for 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_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
|
187 '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
|
188 '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
|
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 |
ab608f27ecd5
Copy preliminary django-paste code for 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 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
|
192 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
|
193 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
|
194 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
|
195 ) |
ab608f27ecd5
Copy preliminary django-paste code for 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 |
45
a46d4cccea4d
More snippet template name changes
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
197 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
|
198 |
ab608f27ecd5
Copy preliminary django-paste code for 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 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 |
ab608f27ecd5
Copy preliminary django-paste code for 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 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
|
209 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
|
210 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
|
211 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
|
212 '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
|
213 '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
|
214 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
|
215 ) |
ab608f27ecd5
Copy preliminary django-paste code for 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 = '\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
|
217 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
|
218 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
|
219 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
|
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 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
|
222 '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
|
223 '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
|
224 '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
|
225 } |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
2
diff
changeset
|
226 |
ab608f27ecd5
Copy preliminary django-paste code for 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 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
|
228 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
|
229 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
|
230 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
|
231 ) |
46
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
45
diff
changeset
|
232 |
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
|
233 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
|
234 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
|
235 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
|
236 return HttpResponse(response) |
202
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
237 |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
238 |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
239 |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
240 #Rating Processing |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
241 def processrating(request,snippet_id): |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
242 from djangoratings.views import AddRatingView |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
243 import django.db.models |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
244 from django.contrib.contenttypes.models import ContentType |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
245 |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
246 |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
247 content_type = ContentType.objects.get(model='snippet').id |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
248 if request.method == 'POST': |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
249 params = { |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
250 'content_type_id': content_type, |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
251 'object_id': get_object_or_404(Snippet,secret_id=snippet_id).id, |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
252 'field_name': 'rating', # Must be the same as the name declared in the model of snippet |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
253 'score': int( request.POST['Rate']) , # the score value sent |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
254 } |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
255 response = AddRatingView()(request, **params) |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
256 if response.status_code == 200: |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
190
diff
changeset
|
257 return redirect( request.POST['next'] ) |