7
7
from django import forms
9
from bashoneliners.main.models import OneLiner
18
class PostOneLinerForm(forms.ModelForm):
19
def save(self, hacker):
20
self.instance.hacker = hacker
21
return super(PostOneLinerForm, self).save()
27
'line': forms.Textarea(attrs={'cols': 80, 'rows': 3, }),
28
'summary': forms.Textarea(attrs={'cols': 80, 'rows': 3, }),
29
'explanation': forms.Textarea(attrs={'cols': 80, 'rows': 10, }),
30
'caveats': forms.Textarea(attrs={'cols': 80, 'rows': 3, }),
8
from django.contrib.comments.forms import CommentForm
10
from oneliners.models import OneLiner, HackerProfile, Question
13
class CommonOneLinerForm(forms.ModelForm):
15
next_url = forms.URLField(required=False)
16
action = forms.CharField()
18
def __init__(self, user, *args, **kwargs):
20
super(CommonOneLinerForm, self).__init__(*args, **kwargs)
26
'summary': forms.TextInput(attrs={'class': 'span6', }),
27
'line': forms.TextInput(attrs={'class': 'span6', }),
28
'explanation': forms.Textarea(attrs={'rows': 10, 'class': 'span6', }),
29
'limitations': forms.Textarea(attrs={'rows': 3, 'class': 'span6', }),
41
class PostOneLinerForm(CommonOneLinerForm):
42
title = 'Post a One-Liner'
43
actions = ({'name': 'Post one-liner', 'cssclass': 'btn-primary'},)
46
self.instance.user = self.user
47
return super(PostOneLinerForm, self).save()
50
class EditOneLinerForm(CommonOneLinerForm):
51
title = 'Edit one-liner'
52
action_save = {'name': 'Save one-liner', 'cssclass': 'btn-primary'}
53
action_delete = {'name': 'Delete one-liner', 'cssclass': 'btn-danger'}
54
actions = (action_save, action_delete)
59
def clean_action(self):
60
action = self.cleaned_data['action']
61
if action == self.action_save['name']:
63
elif action == self.action_delete['name']:
68
if self.instance.user != self.user:
69
raise forms.ValidationError('User %s is not the owner of this OneLiner' % self.user)
70
return self.cleaned_data
73
class SearchOneLinerForm(forms.Form):
74
query = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'class': 'span4', }))
75
is_advanced = forms.BooleanField(required=False)
76
match_summary = forms.BooleanField(initial=True, required=False)
77
match_line = forms.BooleanField(initial=True, required=False)
78
match_explanation = forms.BooleanField(initial=True, required=False)
79
match_limitations = forms.BooleanField(initial=True, required=False)
80
match_whole_words = forms.BooleanField(initial=False, required=False)
83
class EditHackerProfileForm(forms.ModelForm):
84
next_url = forms.URLField(required=False)
86
def clean_display_name(self):
87
display_name = self.cleaned_data['display_name']
88
if display_name == '':
96
'display_name': forms.TextInput(attrs={'class': '', }),
97
'twitter_name': forms.TextInput(attrs={'class': '', }),
98
'blog_url': forms.TextInput(attrs={'class': 'span6', }),
99
'homepage_url': forms.TextInput(attrs={'class': 'span6', }),
107
class CommonQuestionForm(forms.ModelForm):
109
next_url = forms.URLField(required=False)
110
action = forms.CharField()
112
def __init__(self, user, *args, **kwargs):
114
super(CommonQuestionForm, self).__init__(*args, **kwargs)
120
'summary': forms.TextInput(attrs={'class': 'span6', }),
121
'explanation': forms.Textarea(attrs={'rows': 5, 'class': 'span6', }),
132
class PostQuestionForm(CommonQuestionForm):
133
title = 'Post a question'
134
actions = ({'name': 'Post question', 'cssclass': 'btn-primary'},)
137
self.instance.user = self.user
138
return super(PostQuestionForm, self).save()
141
class EditQuestionForm(CommonQuestionForm):
142
title = 'Edit question'
143
action_save = {'name': 'Save question', 'cssclass': 'btn-primary'}
144
action_delete = {'name': 'Delete question', 'cssclass': 'btn-danger'}
145
actions = (action_save, action_delete)
150
def clean_action(self):
151
action = self.cleaned_data['action']
152
if action == self.action_save['name']:
154
elif action == self.action_delete['name']:
155
self.is_delete = True
159
if self.instance.user != self.user:
160
raise forms.ValidationError('User %s is not the owner of this Question' % self.user)
161
return self.cleaned_data
164
class PostCommentOnOneLinerForm(CommentForm):
165
next_url = forms.URLField(required=False)
167
def __init__(self, *args, **kwargs):
168
super(PostCommentOnOneLinerForm, self).__init__(*args, **kwargs)
169
self.fields['comment'].widget = forms.Textarea(attrs={'rows': 5, 'class': 'span6', })