Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow css classes to come from self.attrs without being overwritten. #39

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions zebra/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.core.exceptions import NON_FIELD_ERRORS
from django.utils.dates import MONTHS

from six import iteritems

from zebra.conf import options
from zebra.widgets import NoNameSelect, NoNameTextInput

Expand All @@ -22,15 +24,15 @@ def __init__(self, *args, **kwargs):
super(StripePaymentForm, self).__init__(*args, **kwargs)
self.fields['card_cvv'].label = "Card CVC"
self.fields['card_cvv'].help_text = "Card Verification Code; see rear of card."
months = [ (m[0], u'%02d - %s' % (m[0], unicode(m[1])))
for m in sorted(MONTHS.iteritems()) ]
months = [ (m[0], u'%02d - %s' % (m[0], str(m[1])))
for m in sorted(iteritems(MONTHS)) ]
self.fields['card_expiry_month'].choices = months

card_number = forms.CharField(required=False, max_length=20,
widget=NoNameTextInput())
card_cvv = forms.CharField(required=False, max_length=4,
widget=NoNameTextInput())
card_expiry_month = forms.ChoiceField(required=False, widget=NoNameSelect(),
choices=MONTHS.iteritems())
choices=iteritems(MONTHS))
card_expiry_year = forms.ChoiceField(required=False, widget=NoNameSelect(),
choices=options.ZEBRA_CARD_YEARS_CHOICES)
3 changes: 1 addition & 2 deletions zebra/templatetags/zebra_tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.core.urlresolvers import reverse
from django import template
from django.template.loader import render_to_string
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _

Expand All @@ -15,7 +14,7 @@ def _set_up_zebra_form(context):
if "form" in context:
context["zebra_form"] = context["form"]
else:
raise Exception, "Missing stripe form."
raise Exception("Missing stripe form.")
context["STRIPE_PUBLISHABLE"] = options.STRIPE_PUBLISHABLE
return context

Expand Down
11 changes: 10 additions & 1 deletion zebra/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
class NoNameWidget(object):

def _update_to_noname_class_name(self, name, kwargs_dict):
name_class = name.replace("_", "-")

current_classes = ''
if "class" in self.attrs:
current_classes = self.attrs["class"]

if "attrs" in kwargs_dict:
if "class" in kwargs_dict["attrs"]:
kwargs_dict["attrs"]["class"] += " %s" % (name.replace("_", "-"), )
kwargs_dict["attrs"]["class"] += (" %s" % name.replace("_", "-"))
else:
kwargs_dict["attrs"].update({'class': name.replace("_", "-")})
else:
kwargs_dict["attrs"] = {'class': name.replace("_", "-")}

if current_classes != '':
kwargs_dict["attrs"]["class"] += ' %s' % current_classes

return kwargs_dict

def _strip_name_attr(self, widget_string, name):
Expand Down