Created
June 6, 2013 01:33
-
-
Save kevinseelbach/5718699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_color_choices(rid): | |
r_server = redis.Redis('localhost') | |
order_items = r_server.smembers('orderitems:%s' % rid) | |
roofing_brand = '' | |
for o in order_items: | |
c = json.loads(o) | |
if c['94'] == '1' and c['19'] == '1': | |
roofing_brand = c['22'] | |
break | |
key = 'colors:%s' % (roofing_brand) | |
sets = r_server.smembers(key) | |
choices = set() | |
for choice in sets: | |
x = json.loads(choice) | |
choices.add((x[0], x[1])) | |
return choices | |
def get_choices(keyname, rids): | |
r_server = redis.Redis('localhost') | |
choices = [ | |
('0', 'Select an option...'), | |
] | |
sorted_choices = [] | |
for rid in rids: | |
key = '%s:%s' % (keyname, rid) | |
sets = r_server.smembers(key) | |
for choice in sets: | |
x = json.loads(choice) | |
sorted_choices.append((x[0], x[1])) | |
sorted_choices = sorted(sorted_choices, key=itemgetter(1)) | |
for c in sorted_choices: | |
choices.append(c) | |
return choices | |
def get_name(keyname, rids, product): | |
rs = redis.Redis('localhost') | |
for rid in rids: | |
sets = rs.smembers('%s:%s' % (keyname, rids)) | |
for choice in sets: | |
x = json.loads(choice) | |
if x[0] == product: | |
return x[1] | |
def get_color(model, color_id): | |
rs = redis.Redis('localhost') | |
colors = rs.smembers('colors:%s' % model) | |
for c in colors: | |
x = json.loads(c) | |
if x[0] == color_id: | |
return x[1] | |
class ContractForm(forms.Form): | |
desc_roofing_work = forms.MultipleChoiceField(choices=ROOFING_WORK_CHECKLIST, | |
required=True, | |
widget=forms.CheckboxSelectMultiple, | |
label='Description of Roofing Work') | |
ice_water_options = forms.MultipleChoiceField(choices=ICE_WATER_CHOICES, | |
required=True, | |
widget=forms.CheckboxSelectMultiple) | |
roof_vent_qty = forms.IntegerField(required=False, | |
label="Roof Vent Qty") | |
ridge_vent_qty = forms.IntegerField(required=False, | |
label="Ridge Vent Qty") | |
roofing_initials = JSONFormField(label='Client Initials', | |
help_text='Any defective or rotted decking found during the shingle removal process must be replaced, per manufacturers recommendations and local building codes. A cost per piece of $50 will be charged for the material and labor to replace such decking. This cost is the responsibility of the client.') | |
desc_siding_work = forms.MultipleChoiceField(required=True, | |
label="Description of Siding Work", | |
widget=forms.CheckboxSelectMultiple, | |
choices=SIDING_WORK_CHECKLIST) | |
replace_siding = forms.BooleanField(required=False, | |
label="Replace siding") | |
replace_siding_choices = forms.MultipleChoiceField(choices=REPLACE_SIDING_CHECKLIST, | |
required=False, | |
widget=forms.CheckboxSelectMultiple, | |
label='' | |
) | |
siding_profile = forms.ChoiceField(choices=PROFILE_CHOICES, | |
required=False) | |
install_house_wrap = forms.ChoiceField(label='Install House Wrap', | |
choices=BOOLEAN_CHOICES, | |
required=False) | |
fascia_lf = forms.IntegerField(required=False, | |
label='Fascia Linear Ft.') | |
shutter_size = forms.CharField(required=False, | |
label='Shutter Size') | |
shutter_qty = forms.CharField(required=False, | |
label='Shutter Qty') | |
shutter_color = forms.CharField(required=False, | |
label='Shutter Color') | |
client_signature = JSONFormField(label='Client Signature') | |
rep_signature = JSONFormField(label='Rep Signature') | |
def clean(self): | |
cleaned_data = super(ContractForm, self).clean() | |
roofing_brand = cleaned_data.get('roofing_brand') | |
roofing_color = cleaned_data.get('roofing_color') | |
vent_type = cleaned_data.get('vent_type') | |
gutter_type = cleaned_data.get('gutter_type') | |
siding_brand = cleaned_data.get('siding_brand') | |
soffit_type = cleaned_data.get('soffit_type') | |
if 'roofing_color' in self._errors: | |
del self._errors['roofing_color'] | |
if 'soffit_color' in self._errors: | |
del self._errors['soffit_color'] | |
if 'vent_color' in self._errors: | |
del self._errors['vent_color'] | |
if 'gutter_color' in self._errors: | |
del self._errors['gutter_color'] | |
if roofing_brand and roofing_color: | |
options = get_choices('colors', [roofing_brand]) | |
count = 0 | |
for opt in options: | |
if opt[0] == roofing_color: | |
count = 1 | |
# cleaned_data['roofing_color_friendly'] = opt[1] | |
# cleaned_data['vent_type_friendly'] = [x[1] for x in self.fields['vent_type'].choices if x[0] == vent_type][0] | |
# cleaned_data['roofing_brand_friendly'] = [x[1] for x in self.fields['roofing_brand'].choices if x[0] == roofing_brand][0] | |
# cleaned_data['soffit_type_friendly'] = [x[1] for x in self.fields['soffit_type'].choices if x[0] == soffit_type][0] | |
# #cleaned_data['siding_brand_friendly'] = [x[1] for x in self.fields['siding_brand'].choices if x[0] == siding_brand][0] | |
# cleaned_data['gutter_type_friendly'] = [x[1] for x in self.fields['gutter_type'].choices if x[0] == gutter_type][0] | |
if count != 1: | |
raise forms.ValidationError('Could not find selected option for roofing color.') | |
return cleaned_data | |
def __init__(self, *args, **kwargs): | |
self.setting = kwargs.pop('setting', None) | |
self.rid = kwargs.pop('rid', None) | |
kwargs_new = {'error_class': BootstrapErrorList} | |
kwargs_new.update(kwargs) | |
super(ContractForm, self).__init__(*args, **kwargs_new) | |
self.fields['roofing_brand'] = forms.ChoiceField( | |
choices=get_choices('models', [ '1' ],), | |
required=False, | |
initial='' | |
) | |
self.fields['roofing_color'] = forms.ChoiceField( | |
choices=get_choices('colors', [self.initial['roofing_brand']],), | |
required=False, | |
) | |
self.fields['vent_type'] = forms.ChoiceField( | |
choices=get_choices('models', ['9', '10', '48']), | |
label='Order Vent Model', | |
required=False, | |
) | |
self.fields['vent_color'] = forms.ChoiceField( | |
choices=get_choices('colors', [self.initial['vent_type']]), | |
required=False, | |
) | |
self.fields['ridge_vent_color'] = forms.ChoiceField( | |
choices=get_choices('colors', ['147']), | |
required=False, | |
) | |
self.fields['gutter_type'] = forms.ChoiceField( | |
choices=get_choices('models', ['21']), | |
required=False, | |
) | |
self.fields['gutter_color'] = forms.ChoiceField( | |
choices=get_choices('colors', [self.initial['gutter_type']]), | |
required=False, | |
) | |
self.fields['gutter_protection_color'] = forms.ChoiceField( | |
choices=get_choices('colors', ['146']), | |
required=False, | |
) | |
self.fields['downspout_color'] = forms.ChoiceField( | |
choices=get_choices('colors', ['146']), | |
required=False, | |
) | |
self.fields['siding_brand'] = forms.ChoiceField( | |
choices=get_choices('models', ['22']), | |
required=False, | |
) | |
self.fields['soffit_type'] = forms.ChoiceField( | |
choices=get_choices('models', ['37', '43', '41', '44']), | |
required=False, | |
) | |
self.fields['soffit_color'] = forms.ChoiceField( | |
choices=get_choices('colors', [self.initial['soffit_type']]), | |
required=False, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment