forms.py 8.63 KB
Newer Older
1
# core django imports
2
from django import forms
3
# third party imports
4
from crispy_forms.helper import FormHelper
Daniel W Bond's avatar
Daniel W Bond committed
5
from crispy_forms.layout import Button, Submit, Layout, Fieldset, HTML, Field
Daniel W Bond's avatar
Daniel W Bond committed
6
from crispy_forms.bootstrap import AppendedPrependedText, FormActions
7 8
# imports from your apps
from .models import Listing, Bid, Flag, Rating
Jean Michel Rouly's avatar
Jean Michel Rouly committed
9

Daniel W Bond's avatar
Daniel W Bond committed
10 11

class ListingForm(forms.ModelForm):
Daniel W Bond's avatar
Daniel W Bond committed
12

13 14 15
    def __init__(self, *args, **kwargs):

        self.helper = FormHelper()
16
        # bootstrap3 formatting
Daniel W Bond's avatar
Daniel W Bond committed
17 18
        self.helper.label_class = 'col-md-3 be-bold'
        self.helper.field_class = 'col-md-9 bottom-padding'
19 20 21

        self.helper.layout = Layout(
            Fieldset("",
Daniel W Bond's avatar
Daniel W Bond committed
22
                     Field('isbn', placeholder='0801884039'),
23
                     HTML('<div class="collapse" id="section-collapse">'),
Daniel W Bond's avatar
Daniel W Bond committed
24 25 26 27
                     Field('title',
                           placeholder='Squirrels: The Animal Answer Guide'),
                     Field('author',
                           placeholder='Richard W. Thorington, Jr., and Katie Ferrell'),
28
                     Field('edition', placeholder='1'),
Daniel W Bond's avatar
Daniel W Bond committed
29
                     Field('year', placeholder='2006'),
30
                     HTML('</div>'),
Daniel W Bond's avatar
Daniel W Bond committed
31
                     Field('course_abbr', placeholder='ENGH 302'),
Daniel W Bond's avatar
Daniel W Bond committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
                     'condition',
                     'access_code',
                     AppendedPrependedText('price', '$', '.00',
                                           placeholder="whole numbers"),
                     'photo',
                     Field('description',
                           placeholder='I would be willing to exchange this textbook for one that I need next semester. /// This is for Professor Smith\'s section ONLY. /// I can give you the workbook as well.'),
                     FormActions(Submit('submit', 'Create',
                                 css_class='btn-primary'),
                                 Button('cancel', 'Never Mind',
                                        css_class='btn-default',
                                        onclick="history.back()")
                                 ),

                     ),
47 48 49 50
        )

        super(ListingForm, self).__init__(*args, **kwargs)
        self.fields['isbn'].label = "ISBN"
Daniel W Bond's avatar
Daniel W Bond committed
51
        self.fields['course_abbr'].label = "Course"
52
        self.fields['description'].label = "Other Notes"
53
        self.fields['photo'].required = False
Daniel W Bond's avatar
Daniel W Bond committed
54 55 56 57

    class Meta:
        model = Listing

Daniel W Bond's avatar
Daniel W Bond committed
58 59

class BidForm(forms.ModelForm):
60

61
    def __init__(self, *args, **kwargs):
62

63
        self.helper = FormHelper()
Daniel W Bond's avatar
Daniel W Bond committed
64 65
        self.helper.label_class = 'be-bold col-md-2'
        self.helper.field_class = 'col-md-10'
66 67 68

        self.helper.layout = Layout(
            Fieldset("",
Daniel W Bond's avatar
Daniel W Bond committed
69 70 71 72 73 74 75 76 77 78 79 80
                     'listing',
                     HTML("<div class='col-md-4'>"),
                     AppendedPrependedText('price', '$', '.00',
                                           placeholder="whole numbers"),
                     HTML("</div><div class='col-md-6'>"),
                     'text',
                     HTML("</div><div class='col-md-2'>"),
                     FormActions(Submit('submit', 'Submit',
                                        css_class='btn-primary')
                                 ),
                     HTML("</div>"),
                     ),
81
        )
Daniel W Bond's avatar
Daniel W Bond committed
82

83
        super(BidForm, self).__init__(*args, **kwargs)
84
        self.fields['text'].label = "Comments"
85

Jean Michel Rouly's avatar
Jean Michel Rouly committed
86 87
    class Meta:
        model = Bid
88

Daniel W Bond's avatar
Daniel W Bond committed
89 90

class FlagForm(forms.ModelForm):
91 92

    def __init__(self, *args, **kwargs):
93

94
        self.helper = FormHelper()
95

Daniel W Bond's avatar
Daniel W Bond committed
96
        self.helper.label_class = 'be-bold'
97 98
        self.helper.layout = Layout(
            Fieldset("",
Daniel W Bond's avatar
Daniel W Bond committed
99 100 101 102 103 104 105 106 107
                     'reason',
                     HTML("""<hr/ >"""),
                     FormActions(Submit('submit', 'Create',
                                        css_class='btn-primary'),
                                 Button('cancel', 'Never Mind',
                                        css_class='btn-default',
                                        onclick="history.back()")
                                 ),
                     ),
108 109 110 111 112 113
        )
        super(FlagForm, self).__init__(*args, **kwargs)

    class Meta:
        model = Flag

114
#class EditListingForm( forms.ModelForm ):
115

Daniel W Bond's avatar
Daniel W Bond committed
116

117
class ExchangeListingForm(forms.ModelForm):
118

119
    def __init__(self, *args, **kwargs):
120

121 122
        self.helper = FormHelper()

Daniel W Bond's avatar
Daniel W Bond committed
123
        self.helper.label_class = 'be-bold'
124 125
        self.helper.layout = Layout(
            Fieldset("",
Daniel W Bond's avatar
Daniel W Bond committed
126 127 128
                     'winning_bid',
                     HTML("""<hr/ >"""),
                     HTML("""<strong>Your Email to Your Bidder</strong>"""),
129
                     HTML("""<div class="well"><em><p>Hey there!</p><p>Poster {{ listing.poster.user.get_full_name }} has picked your bid for {{ listing.title }} on SRCT Bookshare. They're the cc'ed email address-- {{ listing.poster.user.email }}.</p><p>Watch your email to arrange all the final touches to get your book.</p></em>"""),
Daniel W Bond's avatar
Daniel W Bond committed
130 131 132 133
                     Field('email_message',
                           placeholder='Do you want to meet tomorrow by the JC Info Desk at 4?'),
                     HTML("""<em><p>Thanks for using SRCT Bookshare!</p><p>Mason SRCT</p></em></div>"""),
                     HTML("""<hr/ >"""),
134 135
                     HTML("""<div class="text-center">Friendly reminder: Don't spam people. We will deactivate your account.</div>"""),
                     HTML("""<hr/ >"""),
136
                     FormActions(Submit('submit', 'Email and Exchange',
Daniel W Bond's avatar
Daniel W Bond committed
137 138 139 140 141 142
                                        css_class='btn-primary'),
                                 Button('cancel', 'Never Mind',
                                        css_class='btn-default',
                                        onclick="history.back()")
                                 ),
                     ),
143
        )
Daniel W Bond's avatar
Daniel W Bond committed
144

145
        super(ExchangeListingForm, self).__init__(*args, **kwargs)
146
        self.fields['email_message'].label = "Custom Message"
147
        self.fields['winning_bid'].required = True
148 149 150 151 152 153
        self.fields['email_message'].initial = ''

    class Meta:
        model = Listing


154
class UnExchangeListingForm(forms.ModelForm):
155 156 157 158 159 160 161 162 163

    def __init__(self, *args, **kwargs):

        self.helper = FormHelper()

        self.helper.label_class = 'be-bold'
        self.helper.layout = Layout(
            Fieldset("",
                     HTML("""<strong>Your Email to Your Bidder</strong>"""),
164
                     HTML("""<div class="well"><em><p>Hey there!</p><p>Poster {{ listing.poster.user.get_full_name }} has cancelled your bid for {{ listing.title }} on SRCT Bookshare.</p><p>We certainly hope that this doesn't come as a shock. :-P</p><p>(If you don't know why you're getting this email, hey're the cc'ed email address-- {{ listing.poster.user.email }}. Contact them ASAP to clear up any confusion.)<p></em>"""),
165
                     Field('email_message',                           placeholder='I haven\'t heard from you in a couple of days, so I\'m going to have to try to exchange my textbook to someone else. :-/'),
166 167
                     HTML("""<em><p>Thanks for using SRCT Bookshare!</p><p>Mason SRCT</p></em></div>"""),
                     HTML("""<hr/ >"""),
168 169
                     HTML("""<div class="text-center">Friendly reminder: Don't spam people. We will deactivate your account.</div>"""),
                     HTML("""<hr/ >"""),
170
                     FormActions(Submit('submit', 'Email and Cancel Exchange',
171 172 173 174 175 176 177 178
                                        css_class='btn-primary'),
                                 Button('cancel', 'Never Mind',
                                        css_class='btn-default',
                                        onclick="history.back()")
                                 ),
                     ),
        )

179
        super(UnExchangeListingForm, self).__init__(*args, **kwargs)
180 181
        self.fields['email_message'].label = "Custom Message"
        self.fields['email_message'].initial = ''
182 183 184

    class Meta:
        model = Listing
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210


class RatingForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):

        self.helper = FormHelper()

        self.helper.label_class = 'be-bold'
        self.helper.layout = Layout(
            Fieldset("",
                     'stars',
                     'review',
                     HTML("""<hr/ >"""),
                     FormActions(Submit('submit', 'Create',
                                        css_class='btn-primary'),
                                 Button('cancel', 'Never Mind',
                                        css_class='btn-default',
                                        onclick="history.back()")
                                 ),
                     ),
        )
        super(RatingForm, self).__init__(*args, **kwargs)

    class Meta:
        model = Rating