annotate apps/snippet/forms.py @ 133:ba51d3b7740b

Add ability to upload a file to create a snippet If a file is specified, the contents of that file are used in preference to the contents of the 'content' text box.
author dellsystem <ilostwaldo@gmail.com>
date Sat, 22 Sep 2012 12:20:24 -0400
parents d858aae811d0
children f299232c82e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
1 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
2 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
3 from django.utils.translation import ugettext_lazy as _
ab608f27ecd5 Copy preliminary django-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 agora.apps.snippet.models import 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
5 from agora.apps.snippet.highlight import LEXER_LIST_ALL, LEXER_LIST, LEXER_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
6 import datetime
ab608f27ecd5 Copy preliminary django-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
7
ab608f27ecd5 Copy preliminary django-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
8 #===============================================================================
ab608f27ecd5 Copy preliminary django-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 # 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
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
ab608f27ecd5 Copy preliminary django-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 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
13 (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
14 (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
15 (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
16 (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
17 )
ab608f27ecd5 Copy preliminary django-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
ab608f27ecd5 Copy preliminary django-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 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
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 class SnippetForm(forms.ModelForm):
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
22 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
23 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
24 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
25 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
26 ignored."),
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
27 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
28
ab608f27ecd5 Copy preliminary django-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
29 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
30 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
31 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
32 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
33 )
ab608f27ecd5 Copy preliminary django-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
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
35 def __init__(self, *args, **kwargs):
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
36 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
37 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
38 self.request = request
98
5a8f1dece263 Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents: 54
diff changeset
39
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
40 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
41 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
42 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
43 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
44 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
45 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
46
ab608f27ecd5 Copy preliminary django-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 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
48 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
49 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
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
98
5a8f1dece263 Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents: 54
diff changeset
52
133
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
53 # 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
54 self.fields['content'].required = False
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
55 self.fields['title'].required = True
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
56
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
57 def clean(self):
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
58 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
59 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
60 content = cleaned_data.get('content')
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
61
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
62 if file_data:
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
63 file_data.open()
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
64 cleaned_data['content'] = file_data.read()
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
65 elif not content:
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
66 # No snippet data specified
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
67 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
68 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
69 a file."))
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
70
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
71 return cleaned_data
ba51d3b7740b Add ability to upload a file to create a snippet
dellsystem <ilostwaldo@gmail.com>
parents: 99
diff changeset
72
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
73 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
74
ab608f27ecd5 Copy preliminary django-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
75 # 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
76 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
77 self.instance.parent = parent
98
5a8f1dece263 Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents: 54
diff changeset
78
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
79 # 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
80 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
81 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
82
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
83 # 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
84 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
85
ab608f27ecd5 Copy preliminary django-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 # 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94
ab608f27ecd5 Copy preliminary django-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 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
96
ab608f27ecd5 Copy preliminary django-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 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
98 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
99 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
100 '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
101 '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
102 '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
103 )
ab608f27ecd5 Copy preliminary django-paste code for snippets along with mptt. Works clunkily. Still need to adapt it for Agora.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
104
ab608f27ecd5 Copy preliminary django-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
ab608f27ecd5 Copy preliminary django-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 # 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
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
ab608f27ecd5 Copy preliminary django-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 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
111 (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
112 '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
113 '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
114 '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
115 '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
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 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
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 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
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 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
124 display_all_lexer = forms.BooleanField(
98
5a8f1dece263 Fix extra whitespace issues in Python file
dellsystem <ilostwaldo@gmail.com>
parents: 54
diff changeset
125 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
126 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
127 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
128 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
129 '\'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
130 )
46
b7c1c22fdfe8 Format code for 80 columns, add some js to static/ dir
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 42
diff changeset
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139 choices=USERPREFS_SIZES)