Mercurial > agora-palash
annotate apps/snippet/forms.py @ 207:d534881629ff
Updated snippet's template and views files to fix rating code collision which prevented posting new snippets.
Updated snippet's models file so that now secret id of each snippet will be unique. It also means that the no two or more than two snippets will have same secret id.
author | Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com> |
---|---|
date | Mon, 19 Aug 2013 20:30:19 +0500 |
parents | 499e5f47f278 |
children |
rev | line source |
---|---|
151
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
135
diff
changeset
|
1 import datetime |
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
135
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:
diff
changeset
|
3 from django import forms |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
4 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:
diff
changeset
|
5 from django.utils.translation import ugettext_lazy as _ |
151
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
135
diff
changeset
|
6 |
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
135
diff
changeset
|
7 from apps.snippet.models import Snippet |
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
135
diff
changeset
|
8 from apps.snippet.highlight import LEXER_LIST_ALL, LEXER_LIST, LEXER_DEFAULT |
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:
diff
changeset
|
9 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
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:
diff
changeset
|
11 # Snippet Form and Handling |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
12 #=============================================================================== |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
13 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
14 EXPIRE_CHOICES = ( |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
15 (3600, _(u'In one hour')), |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
16 (3600*24*7, _(u'In one week')), |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
17 (3600*24*30, _(u'In one month')), |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
18 (3600*24*30*12*100, _(u'Save forever')), # 100 years, I call it forever ;) |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
19 ) |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
20 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
21 EXPIRE_DEFAULT = 3600*24*30 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
22 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
23 class SnippetForm(forms.ModelForm): |
133
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
24 file = forms.FileField(help_text=_("If the snippet you want to post is \ |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
25 saved as a file on your computer, you can upload it directly rather \ |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
26 than having to copy and paste it into the box above. If a file \ |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
27 is specified, the text in the content field above will be \ |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
28 ignored."), |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
29 required=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:
diff
changeset
|
30 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
31 expire_options = forms.ChoiceField( |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
32 choices=EXPIRE_CHOICES, |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
33 initial=EXPIRE_DEFAULT, |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
34 label=_(u'Expires'), |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
35 ) |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
36 |
202
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents:
151
diff
changeset
|
37 |
499e5f47f278
Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <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:
99
diff
changeset
|
39 def __init__(self, *args, **kwargs): |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
40 request = kwargs.pop('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:
diff
changeset
|
41 super(SnippetForm, self).__init__(*args, **kwargs) |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
42 self.request = request |
98
5a8f1dece263
Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents:
54
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:
diff
changeset
|
44 try: |
46
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
45 if self.request.session['userprefs'].get('display_all_lexer', |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
46 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:
diff
changeset
|
47 self.fields['lexer'].choices = LEXER_LIST_ALL |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
48 except KeyError: |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
49 pass |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
50 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
51 try: |
46
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
52 self.fields['author'].initial = \ |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
53 self.request.session['userprefs'].get('default_name', '') |
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:
diff
changeset
|
54 except KeyError: |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
55 pass |
98
5a8f1dece263
Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents:
54
diff
changeset
|
56 |
133
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
57 # Make the content field not required (validated in clean()) |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
58 self.fields['content'].required = False |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
59 self.fields['title'].required = True |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
60 |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
61 def clean(self): |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
62 cleaned_data = super(SnippetForm, self).clean() |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
63 file_data = cleaned_data.get('file') |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
64 content = cleaned_data.get('content') |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
65 |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
66 if file_data: |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
67 file_data.open() |
135
f299232c82e8
Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents:
133
diff
changeset
|
68 content_type = file_data.content_type |
f299232c82e8
Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents:
133
diff
changeset
|
69 |
f299232c82e8
Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents:
133
diff
changeset
|
70 # Do some very basic checking of types. NOT SECURE. |
f299232c82e8
Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents:
133
diff
changeset
|
71 if (content_type.startswith('text/') or |
f299232c82e8
Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents:
133
diff
changeset
|
72 content_type.startswith('application')): |
f299232c82e8
Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents:
133
diff
changeset
|
73 cleaned_data['content'] = file_data.read() |
f299232c82e8
Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents:
133
diff
changeset
|
74 else: |
f299232c82e8
Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents:
133
diff
changeset
|
75 raise forms.ValidationError(_("Please ensure that you upload \ |
f299232c82e8
Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents:
133
diff
changeset
|
76 a text file.")) |
133
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
77 elif not content: |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
78 # No snippet data specified |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
79 raise forms.ValidationError(_("Please specify some content for \ |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
80 the snippet, either in the content field or by uploading \ |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
81 a file.")) |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
82 |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
83 return cleaned_data |
ba51d3b7740b
Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents:
99
diff
changeset
|
84 |
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:
diff
changeset
|
85 def save(self, parent=None, *args, **kwargs): |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
86 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
87 # Set parent 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:
diff
changeset
|
88 if parent: |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
89 self.instance.parent = parent |
98
5a8f1dece263
Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents:
54
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:
diff
changeset
|
91 # Add expire datestamp |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
92 self.instance.expires = datetime.datetime.now() + \ |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
93 datetime.timedelta(seconds=int(self.cleaned_data['expire_options'])) |
98
5a8f1dece263
Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents:
54
diff
changeset
|
94 |
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:
diff
changeset
|
95 # Save snippet in the db |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
96 super(SnippetForm, self).save(*args, **kwargs) |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
97 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
98 # Add the snippet to the user session 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:
diff
changeset
|
99 if self.request.session.get('snippet_list', False): |
46
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
100 if len(self.request.session['snippet_list']) >= \ |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
101 getattr(settings, 'MAX_SNIPPETS_PER_USER', 10): |
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:
diff
changeset
|
102 self.request.session['snippet_list'].pop(0) |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
103 self.request.session['snippet_list'] += [self.instance.pk] |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
104 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:
diff
changeset
|
105 self.request.session['snippet_list'] = [self.instance.pk] |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
106 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
107 return self.request, self.instance |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
108 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
109 class Meta: |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
110 model = 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:
diff
changeset
|
111 fields = ( |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
112 'title', |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
113 '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:
diff
changeset
|
114 'lexer', |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
115 ) |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
116 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
117 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
118 #=============================================================================== |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
119 # User 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:
diff
changeset
|
120 #=============================================================================== |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
121 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
122 USERPREFS_FONT_CHOICES = [(None, _(u'Default'))] + [ |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
123 (i, i) for i in sorted(( |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
124 'Monaco', |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
125 'Bitstream Vera Sans Mono', |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
126 'Courier 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:
diff
changeset
|
127 'Consolas', |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
128 )) |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
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:
diff
changeset
|
130 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
131 USERPREFS_SIZES = [(None, _(u'Default'))] + [(i, '%dpx' % i) for i in range(5, 25)] |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
132 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
133 class UserSettingsForm(forms.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:
diff
changeset
|
134 |
ab608f27ecd5
Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
135 default_name = forms.CharField(label=_(u'Default Name'), required=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:
diff
changeset
|
136 display_all_lexer = forms.BooleanField( |
98
5a8f1dece263
Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents:
54
diff
changeset
|
137 label=_(u'Display all lexer'), |
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:
diff
changeset
|
138 required=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:
diff
changeset
|
139 widget=forms.CheckboxInput, |
46
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
140 help_text=_(u'This also enables the super secret ' \ |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
141 '\'guess lexer\' function.'), |
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:
diff
changeset
|
142 ) |
46
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
143 font_family = forms.ChoiceField(label=_(u'Font Family'), |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
144 required=False, |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
145 choices=USERPREFS_FONT_CHOICES) |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
146 font_size = forms.ChoiceField(label=_(u'Font Size'), |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
147 required=False, |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
148 choices=USERPREFS_SIZES) |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
149 line_height = forms.ChoiceField(label=_(u'Line Height'), |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
150 required=False, |
b7c1c22fdfe8
Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
42
diff
changeset
|
151 choices=USERPREFS_SIZES) |