annotate apps/snippet/forms.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 c7be7def8b57
children d534881629ff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 form_choices = ( (x,x) for x in range(1,6) )
499e5f47f278 Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
39 Rate = forms.ChoiceField(form_choices,widget=forms.RadioSelect(attrs={'onclick' :"document.getElementById('rate_form').submit();","class":"rate_radio"}))
499e5f47f278 Add necessary code to views and forms of snippet for Ratings
Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
parents: 151
diff changeset
40
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
41 def __init__(self, *args, **kwargs):
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
42 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
43 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
44 self.request = request
98
5a8f1dece263 Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents: 54
diff changeset
45
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
46 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
47 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
48 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
49 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
50 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
51 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
52
ab608f27ecd5 Copy preliminary django-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
53 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
54 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
55 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
56 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
57 pass
98
5a8f1dece263 Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents: 54
diff changeset
58
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
59 # 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
60 self.fields['content'].required = False
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
61 self.fields['title'].required = True
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
62
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
63 def clean(self):
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
64 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
65 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
66 content = cleaned_data.get('content')
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
67
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
68 if file_data:
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
69 file_data.open()
135
f299232c82e8 Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
70 content_type = file_data.content_type
f299232c82e8 Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
71
f299232c82e8 Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
72 # 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
73 if (content_type.startswith('text/') or
f299232c82e8 Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
74 content_type.startswith('application')):
f299232c82e8 Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
75 cleaned_data['content'] = file_data.read()
f299232c82e8 Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
76 else:
f299232c82e8 Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
77 raise forms.ValidationError(_("Please ensure that you upload \
f299232c82e8 Perform basic validation on snippet file uploads
dellsystem <ilostwaldo@gmail.com>
parents: 133
diff changeset
78 a text file."))
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
79 elif not content:
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
80 # No snippet data specified
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
81 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
82 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
83 a file."))
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
84
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
85 return cleaned_data
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
86
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
87 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
88
ab608f27ecd5 Copy preliminary django-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 # 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
90 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
91 self.instance.parent = parent
98
5a8f1dece263 Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents: 54
diff changeset
92
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
93 # 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
94 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
95 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
96
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
97 # 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
98 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
99
ab608f27ecd5 Copy preliminary django-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
100 # 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
101 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
102 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
103 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
104 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
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 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
107 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
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 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
110
ab608f27ecd5 Copy preliminary django-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 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
112 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
113 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
114 '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
115 '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
116 '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
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
ab608f27ecd5 Copy preliminary django-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 # 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
122 #===============================================================================
ab608f27ecd5 Copy preliminary django-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
ab608f27ecd5 Copy preliminary django-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 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
125 (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
126 '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
127 '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
128 '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
129 '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
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 ]
ab608f27ecd5 Copy preliminary django-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 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
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 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
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:
diff changeset
137 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
138 display_all_lexer = forms.BooleanField(
98
5a8f1dece263 Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents: 54
diff changeset
139 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
140 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
141 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
142 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
143 '\'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
144 )
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 42
diff changeset
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 choices=USERPREFS_SIZES)