Пример #1
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])
Пример #2
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])
Пример #3
0
def specialWidget(mymodel, field, enumerableFields):
    """
    Determines the appropriate widget display if several could be applicable; otherwise returns None
    """
    widget = None
    if isinstance(field, (models.ForeignKey,models.ManyToManyField,models.OneToOneField)):
        if enumerableFields:
            if (field in enumerableFields):
                widget = 'pulldown'
        elif (not isAbstract(mymodel)) and (not isinstance(field, models.FileField)):
            try:
                maxpulldown = settings.XGDS_DATA_MAX_PULLDOWNABLE
            except AttributeError:
                maxpulldown = 100
            relatedCount = fieldSize(field, tableSize(mymodel), maxpulldown, 10 * maxpulldown)
            if (relatedCount is not None) and (relatedCount <= maxpulldown):
                widget = 'pulldown'
            else:
                widget = 'textbox'
    return widget
Пример #4
0
def specialWidget(mymodel, field, enumerableFields):
    """
    Determines the appropriate widget display if several could be applicable; otherwise returns None
    """
    widget = None
    if isinstance(
            field,
        (models.ForeignKey, models.ManyToManyField, models.OneToOneField)):
        if enumerableFields:
            if (field in enumerableFields):
                widget = 'pulldown'
        elif (not isAbstract(mymodel)) and (not isinstance(
                field, models.FileField)):
            try:
                maxpulldown = settings.XGDS_DATA_MAX_PULLDOWNABLE
            except AttributeError:
                maxpulldown = 100
            relatedCount = fieldSize(field, tableSize(mymodel), maxpulldown,
                                     10 * maxpulldown)
            if (relatedCount is not None) and (relatedCount <= maxpulldown):
                widget = 'pulldown'
            else:
                widget = 'textbox'
    return widget