###################################### modelfields.py ######################################
class FSISBNField(models.CharField):
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 13
super(FSISBNField, self).__init__(*args, **kwargs)
def formfield(self, **kwargs):
kwargs['widget'] = FSAltISBNWidget()
return super(FSISBNField, self).formfield(**kwargs)
###################################### widgets.py #########################################
class AltISBNWidget(forms.TextInput):
def __init__(self, language=None, attrs={}):
super(AltISBNWidget, self).__init__(attrs=attrs)
def render(self, name, value, attrs={}):
if (not value) or len(str(value)) < 2:
return super(FSAltISBNWidget, self).render(name, value, attrs)
return super(FSAltISBNWidget, self).render(name, value, attrs) + mark_safe("""
<br />
<div class="alt">%s-digit: <span class="altisbn">%s <span class="doodad">
<a href="http://www.librarything.com/isbn/%s">more ⚭</a>
</span></span></div>
""" % (
(len(str(value)) == 10) and "13" or "10",
pyisbn.convert(value),
value
))
Comments
Why is it called FSISBNField() but the instruction on the right is to write isbn = ISBNField()?
What is this "FS" about?
I think all FS should be removed from the source.
#