Esempio n. 1
0
    def render(self, name, value, attrs=None):
        if value is None: value = ''
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)

        localLinkID = "%s-local-link-name" % name
        foreignLinkID = "%s-foreign-link-name" % name
        inline = False

        if type(self.localLinkName) == list:
            localLinkNameWidget = newforms.Select(attrs={"class": "editable"},
                                                  choices=self.localLinkName)
            localLinkNameWidget = localLinkNameWidget.render(
                name=localLinkID, value=None, attrs={"id": localLinkID})
        else:
            localLinkNameWidget = None
            inline = True

        if type(self.localLinkName) in [str, unicode]:
            localLinkName = self.localLinkName
        else:
            localLinkName = None

        # XXX: Don't allow this to be editable.
        #foreignLinkNameWidget = newforms.Select(attrs={"class":"editable"}, choices = ())
        foreignLinkNameWidget = newforms.Select(choices=())

        t = template.loader.get_template("ajaxlinkadd.html")
        tContext = {
            "lookupURL":
            self.lookupURL,
            "linkLookupURL":
            self.linkLookupURL,
            "name":
            name,
            "localLinkNameWidget":
            localLinkNameWidget,
            "foreignLinkNameWidget":
            foreignLinkNameWidget.render(name=foreignLinkID,
                                         value=None,
                                         attrs={"id": foreignLinkID}),
            "localLinkID":
            localLinkID,
            "foreignLinkID":
            foreignLinkID,
            "wikidpage":
            self.wikidpage,
            "localLinkName":
            localLinkName,
            "inline":
            inline,
        }
        return t.render(template.Context(tContext))
Esempio n. 2
0
    def get_form_field(self, form_class=forms.CharField, **kwargs):
        """Return a Django form field appropriate for this property.

    Args:
      form_class: a forms.Field subclass, default forms.CharField

    Additional keyword arguments are passed to the form_class constructor,
    with certain defaults:
      required: self.required
      label: prettified self.verbose_name, if not None
      widget: a forms.Select instance if self.choices is non-empty
      initial: self.default, if not None

    Returns:
       A fully configured instance of form_class, or None if no form
       field should be generated for this property.
    """
        defaults = {'required': self.required}
        if self.verbose_name:
            defaults['label'] = self.verbose_name.capitalize().replace(
                '_', ' ')
        if self.choices:
            choices = []
            if not self.required or (self.default is None
                                     and 'initial' not in kwargs):
                choices.append(('', '---------'))
            for choice in self.choices:
                choices.append((str(choice), unicode(choice)))
            defaults['widget'] = forms.Select(choices=choices)
        if self.default is not None:
            defaults['initial'] = self.default
        defaults.update(kwargs)
        return form_class(**defaults)
Esempio n. 3
0
 def formfield(self, form_class=forms.CharField, **kwargs):
     "Returns a django.newforms.Field instance for this database Field."
     defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
     if self.choices:
         defaults['widget'] = forms.Select(choices=self.get_choices(include_blank=self.blank or not (self.has_default() or 'initial' in kwargs)))
     if self.has_default():
         defaults['initial'] = self.get_default()
     defaults.update(kwargs)
     return form_class(**defaults)
Esempio n. 4
0
class MoveMoneyForm(forms.Form):
    
    def __init__(self, data=None, from_account=None, *arg, **kwarg):
        self.base_fields['account'].queryset = Account.objects\
                            .filter(balance_currency=from_account.balance_currency)\
                            .exclude(number__exact=from_account.number)
        super(MoveMoneyForm, self).__init__(data, *arg, **kwarg)

    account = forms.ModelChoiceField(None)
    amount = forms.DecimalField(max_digits=12, decimal_places=2, min_value=0)
    tag = forms.IntegerField(widget=forms.Select(choices=add_empty_label(TX_TAG_CHOICES)), required=False)
    description = forms.CharField(widget=forms.Textarea())
Esempio n. 5
0
class TransactionForm(forms.Form):
    amount = forms.DecimalField(max_digits=12, decimal_places=2, min_value=0)
    tag = forms.IntegerField(widget=forms.Select(choices=add_empty_label(TX_TAG_CHOICES)), required=False)
    description = forms.CharField(widget=forms.Textarea())