コード例 #1
0
ファイル: forms.py プロジェクト: xgds/xgds_data
def editFormFields(mymodel, field, enumerableFields):
    """
    Returns a dict of Form fields to add to an edit form, based on the model field
    """
    formfields = {}
    if maskField(field):
        pass  # nothing
    elif isinstance(field, VirtualIncludedField):
        pass # still need to cross this bridge
    else:
        widget = specialWidget(mymodel, field, enumerableFields)
        try:
            name = field.verbose_name
        except AttributeError:
            name = field.name
        valField = valueFormField(mymodel, field, widget, label=name)
        if valField is None:
            ## This must be class that we have missed of haven't gotten around to supporting/ignoring
            longname = '.'.join([field.__class__.__module__,
                                 field.__class__.__name__])
            print("EditForm doesn't deal with %s yet" % longname)
        elif widget == 'textbox' and isinstance(field, fields.related.RelatedField):
            print("Too many values to edit %s" % field.name)
        else:
            formfields[field.name] = valField

    return formfields
コード例 #2
0
ファイル: forms.py プロジェクト: xgds/xgds_data
    def __init__(self, mymodel, *args, **kwargs):
        try:
            numorder = kwargs['num']
            del kwargs['num']
        except KeyError:
            numorder = 5
        try:
            directionWidget = kwargs['dwidget']
            del kwargs['dwidget']
        except KeyError:
            directionWidget = forms.RadioSelect

        forms.Form.__init__(self, *args, **kwargs)
        self.model = mymodel
        sortingfields = []
        for x in modelFields(mymodel):
            if maskField(x):
                pass
            elif ordinalField(self.model, x):
                if x.verbose_name != "":
                    sortingfields.append(x)
        if len(sortingfields) > 1:
            datachoices = (tuple((None, 'None') for x in [1]) +
                           tuple((x.name, x.verbose_name)
                                 for x in sortingfields))
            for order in range(1, numorder + 1):
                self.fields['order' + str(order)] = forms.ChoiceField(choices=datachoices,
                                                                      initial=datachoices[0][0],
                                                                      required=True)
                self.fields['direction' + str(order)] = forms.ChoiceField(choices=(('ASC', 'Ascending'),
                                                                                   ('DESC', 'Descending')),
                                                                          widget=directionWidget,
                                                                          initial='ASC',
                                                                          required=True)
コード例 #3
0
    def __init__(self, mymodel, *args, **kwargs):
        try:
            numorder = kwargs['num']
            del kwargs['num']
        except KeyError:
            numorder = 5
        try:
            directionWidget = kwargs['dwidget']
            del kwargs['dwidget']
        except KeyError:
            directionWidget = forms.RadioSelect

        forms.Form.__init__(self, *args, **kwargs)
        self.model = mymodel
        sortingfields = []
        for x in modelFields(mymodel):
            if maskField(x):
                pass
            elif ordinalField(self.model, x):
                if x.verbose_name != "":
                    sortingfields.append(x)
        if len(sortingfields) > 1:
            datachoices = (tuple((None, 'None') for x in [1]) + tuple(
                (x.name, x.verbose_name) for x in sortingfields))
            for order in range(1, numorder + 1):
                self.fields['order' + str(order)] = forms.ChoiceField(
                    choices=datachoices,
                    initial=datachoices[0][0],
                    required=True)
                self.fields['direction' + str(order)] = forms.ChoiceField(
                    choices=(('ASC', 'Ascending'), ('DESC', 'Descending')),
                    widget=directionWidget,
                    initial='ASC',
                    required=True)
コード例 #4
0
def editFormFields(mymodel, field, enumerableFields):
    """
    Returns a dict of Form fields to add to an edit form, based on the model field
    """
    formfields = {}
    if maskField(field):
        pass  # nothing
    elif isinstance(field, VirtualIncludedField):
        pass  # still need to cross this bridge
    else:
        widget = specialWidget(mymodel, field, enumerableFields)
        try:
            name = field.verbose_name
        except AttributeError:
            name = field.name
        valField = valueFormField(mymodel, field, widget, label=name)
        if valField is None:
            ## This must be class that we have missed of haven't gotten around to supporting/ignoring
            longname = '.'.join(
                [field.__class__.__module__, field.__class__.__name__])
            print("EditForm doesn't deal with %s yet" % longname)
        elif widget == 'textbox' and isinstance(field,
                                                fields.related.RelatedField):
            print("Too many values to edit %s" % field.name)
        else:
            formfields[field.name] = valField

    return formfields
コード例 #5
0
ファイル: forms.py プロジェクト: xgds/xgds_data
    def __init__(self, mfields, *args, **kwargs):
        seriesablefields = kwargs.pop('seriesablefields', None)
        forms.Form.__init__(self, *args, **kwargs)
        chartablefields = []

        if (seriesablefields is None):
            seriesablePreset = False
            seriesablefields = []
            try:
                itemCount = tableSize(mfields[0].model)  # an upper bound
            except (IndexError,AttributeError):
                pass  # no fields, apparently
            try:
                maxseriesable = settings.XGDS_DATA_MAX_SERIESABLE
            except AttributeError:
                maxseriesable = 100
        else:
            seriesablePreset = True

        for x in mfields:
            if (not isinstance(x, VirtualIncludedField)) and (not maskField(x)):
                if ordinalField(x.model, x):
                    chartablefields.append(x)
                elif ((seriesablePreset) or
                      (isinstance(x, GenericForeignKey)) or
                      (isAbstract(x.model)) or
                      (itemCount is None)):
                    pass
                else:
                    estCount = fieldSize(x,
                                         tableSize(x.model),
                                          maxseriesable,
                                          maxseriesable * 1000)
                    if (estCount is not None) and (estCount <= maxseriesable):
                        seriesablefields.append(x)

        if len(chartablefields) > 1:
            datachoices = (tuple((x, x)
                                 for x in ['Rank']) +
                           tuple((x.name, x.verbose_name)
                                 for x in chartablefields))
            serieschoices = [(None, 'None')]
            for x in seriesablefields:
                if isinstance(x, fields.related.RelatedField):
                    serieschoices.append((x.name, x.verbose_name))
                else:
                    serieschoices.append((x.name, x.verbose_name))
            self.fields['xaxis'] = forms.ChoiceField(choices=datachoices,
                                                     required=True,
                                                     initial=chartablefields[0].name)
            self.fields['yaxis'] = forms.ChoiceField(choices=datachoices,
                                                     required=True,
                                                     initial=chartablefields[1].name)
            self.fields['series'] = forms.ChoiceField(choices=tuple(serieschoices),
                                                      required=True,
                                                      initial=serieschoices[0][0])
コード例 #6
0
    def __init__(self, mfields, *args, **kwargs):
        seriesablefields = kwargs.pop('seriesablefields', None)
        forms.Form.__init__(self, *args, **kwargs)
        chartablefields = []

        if (seriesablefields is None):
            seriesablePreset = False
            seriesablefields = []
            try:
                itemCount = tableSize(mfields[0].model)  # an upper bound
            except (IndexError, AttributeError):
                pass  # no fields, apparently
            try:
                maxseriesable = settings.XGDS_DATA_MAX_SERIESABLE
            except AttributeError:
                maxseriesable = 100
        else:
            seriesablePreset = True

        for x in mfields:
            if (not isinstance(x,
                               VirtualIncludedField)) and (not maskField(x)):
                if ordinalField(x.model, x):
                    chartablefields.append(x)
                elif ((seriesablePreset) or (isinstance(x, GenericForeignKey))
                      or (isAbstract(x.model)) or (itemCount is None)):
                    pass
                else:
                    estCount = fieldSize(x, tableSize(x.model), maxseriesable,
                                         maxseriesable * 1000)
                    if (estCount is not None) and (estCount <= maxseriesable):
                        seriesablefields.append(x)

        if len(chartablefields) > 1:
            datachoices = (tuple((x, x) for x in ['Rank']) + tuple(
                (x.name, x.verbose_name) for x in chartablefields))
            serieschoices = [(None, 'None')]
            for x in seriesablefields:
                if isinstance(x, fields.related.RelatedField):
                    serieschoices.append((x.name, x.verbose_name))
                else:
                    serieschoices.append((x.name, x.verbose_name))
            self.fields['xaxis'] = forms.ChoiceField(
                choices=datachoices,
                required=True,
                initial=chartablefields[0].name)
            self.fields['yaxis'] = forms.ChoiceField(
                choices=datachoices,
                required=True,
                initial=chartablefields[1].name)
            self.fields['series'] = forms.ChoiceField(
                choices=tuple(serieschoices),
                required=True,
                initial=serieschoices[0][0])
コード例 #7
0
def searchFormFields(mymodel, field, enumerableFields, queryGenerator=None):
    """
    Returns a dict of Form fields to add to a search form, based on the model field
    """
    formfields = {}
    if maskField(field):
        pass  # nothing
    elif isinstance(field, VirtualIncludedField):
        tmfs = field.targetFields()
        if len(tmfs):
            #  need to assume all are the same, so just use the first one
            #print(searchFormFields(tmfs[0].model, tmfs[0], enumerableFields))
            vfields = dict()
            for name, ff in searchFormFields(
                    tmfs[0].model,
                    tmfs[0],
                    enumerableFields,
                    queryGenerator=queryGenerator).iteritems():
                vname = '__'.join([field.throughfield_name, name])
                vfields[vname] = ff
            formfields.update(vfields)
    else:
        widget = specialWidget(mymodel, field, enumerableFields)
        opField = operatorFormField(mymodel, field, widget)
        if opField is None:
            #  This must be class that we have missed of haven't gotten around to supporting/ignoring
            longname = '.'.join(
                [field.__class__.__module__, field.__class__.__name__])
            print("SearchForm forms doesn't deal with %s yet (%s)" %
                  (longname, field))
        else:
            formfieldname = field.name
            if ordinalField(mymodel, field):
                formfields[formfieldname + '_lo'] = valueFormField(
                    mymodel, field, widget, queryGenerator=queryGenerator)
                formfields[formfieldname + '_hi'] = valueFormField(
                    mymodel, field, widget, queryGenerator=queryGenerator)
            else:
                vff = valueFormField(mymodel,
                                     field,
                                     widget,
                                     allowMultiple=False,
                                     queryGenerator=queryGenerator)
                if (widget != 'pulldown') and (isinstance(
                        field, fields.related.RelatedField)):
                    to_field_name = toFieldName(field.rel.to)
                    if to_field_name is None:
                        to_field_name = pk(field.rel.to).name
                    formfieldname = '__'.join([formfieldname, to_field_name])
                formfields[formfieldname] = vff
            formfields[formfieldname + '_operator'] = opField

    return formfields
コード例 #8
0
ファイル: forms.py プロジェクト: xgds/xgds_data
def searchFormFields(mymodel, field, enumerableFields,
                     queryGenerator=None):
    """
    Returns a dict of Form fields to add to a search form, based on the model field
    """
    formfields = {}
    if maskField(field):
        pass  # nothing
    elif isinstance(field, VirtualIncludedField):
        tmfs = field.targetFields()
        if len(tmfs):
            #  need to assume all are the same, so just use the first one
            #print(searchFormFields(tmfs[0].model, tmfs[0], enumerableFields))
            vfields = dict()
            for name,ff in searchFormFields(tmfs[0].model, tmfs[0], enumerableFields, queryGenerator=queryGenerator).iteritems():
                vname = '__'.join([field.throughfield_name,name])
                vfields[vname] = ff
            formfields.update(vfields)
    else:
        widget = specialWidget(mymodel, field, enumerableFields)
        opField = operatorFormField(mymodel, field, widget)
        if opField is None:
            #  This must be class that we have missed of haven't gotten around to supporting/ignoring
            longname = '.'.join([field.__class__.__module__,
                                 field.__class__.__name__])
            print("SearchForm forms doesn't deal with %s yet (%s)" % (longname, field))
        else:
            formfieldname = field.name
            if ordinalField(mymodel, field):
                formfields[formfieldname + '_lo'] = valueFormField(mymodel, field, widget, queryGenerator=queryGenerator)
                formfields[formfieldname + '_hi'] = valueFormField(mymodel, field, widget, queryGenerator=queryGenerator)
            else:
                vff = valueFormField(mymodel, field, widget, allowMultiple=False, queryGenerator=queryGenerator)
                if (widget != 'pulldown') and (isinstance(field, fields.related.RelatedField)):
                    to_field_name = toFieldName(field.rel.to)
                    if to_field_name is None:
                        to_field_name = pk(field.rel.to).name
                    formfieldname = '__'.join([formfieldname, to_field_name])
                formfields[formfieldname] = vff
            formfields[formfieldname + '_operator'] = opField

    return formfields