コード例 #1
0
ファイル: freezer.py プロジェクト: Shopcaster/django-south
def field_dependencies(field, checked_models=None):
    checked_models = checked_models or set()
    depends = set()
    arg_defs, kwarg_defs = modelsinspector.matching_details(field)
    for attrname, options in arg_defs + kwarg_defs.values():
        if options.get("ignore_if_auto_through", False) and auto_through(field):
            continue
        if options.get("is_value", False):
            value = attrname
        elif attrname == 'rel.through' and hasattr(getattr(field, 'rel', None), 'through_model'):
            # Hack for django 1.1 and below, where the through model is stored
            # in rel.through_model while rel.through stores only the model name.
            value = field.rel.through_model
        else:
            try:
                value = get_attribute(field, attrname)
            except AttributeError:
                if options.get("ignore_missing", False):
                    continue
                raise
        if isinstance(value, Model):
            value = value.__class__
        if not isinstance(value, ModelBase):
            continue
        if getattr(value._meta, "proxy", False):
            value = value._meta.proxy_for_model
        if value in checked_models:
            continue
        checked_models.add(value)
        depends.add(value)
        depends.update(model_dependencies(value, checked_models))

    return depends
コード例 #2
0
ファイル: freezer.py プロジェクト: lmorchard/whuru
def field_dependencies(field, checked_models=None):
    checked_models = checked_models or set()
    depends = set()
    arg_defs, kwarg_defs = modelsinspector.matching_details(field)
    for attrname, options in arg_defs + kwarg_defs.values():
        if options.get("ignore_if_auto_through",
                       False) and auto_through(field):
            continue
        if options.get("is_value", False):
            value = attrname
        elif attrname == 'rel.through' and hasattr(getattr(field, 'rel', None),
                                                   'through_model'):
            # Hack for django 1.1 and below, where the through model is stored
            # in rel.through_model while rel.through stores only the model name.
            value = field.rel.through_model
        else:
            try:
                value = get_attribute(field, attrname)
            except AttributeError:
                if options.get("ignore_missing", False):
                    continue
                raise
        if isinstance(value, Model):
            value = value.__class__
        if not isinstance(value, ModelBase):
            continue
        if getattr(value._meta, "proxy", False):
            value = value._meta.proxy_for_model
        if value in checked_models:
            continue
        checked_models.add(value)
        depends.add(value)
        depends.update(model_dependencies(value, checked_models))

    return depends
コード例 #3
0
ファイル: fields.py プロジェクト: Ryati/satchmo
class PaymentChoiceCharField(models.CharField):
    
    def __init__(self, *args, **kwargs):
        choices = kwargs.pop("choices", "__DYNAMIC__")
        if choices == "__DYNAMIC__":
            kwargs['choices'] = labelled_gateway_choices()
                    
        super(PaymentChoiceCharField, self).__init__(*args, **kwargs)

try:
    # South introspection rules for our custom field.
    from south.modelsinspector import add_introspection_rules, matching_details

    # get the kwargs for a Field instance
    # we're using Field, as CharField doesn't change __init__()
    _args, kwargs = matching_details(models.Field())

    add_introspection_rules([(
        (CreditChoiceCharField, ),
        [],
        kwargs,
    )], ['payment\.fields\.CreditChoiceCharField'])
    add_introspection_rules([(
        (PaymentChoiceCharField, ),
        [],
        kwargs,
    )], ['payment\.fields\.PaymentChoiceCharField'])
except ImportError:
    pass
コード例 #4
0
ファイル: fields.py プロジェクト: ringemup/satchmo
    try:
        return config_choice_values('SHIPPING','MODULES')
    except SettingNotSet:
        return ()


class ShippingChoiceCharField(models.CharField):

    def __init__(self, *args, **kwargs):
        choices = kwargs.pop("choices", "__DYNAMIC__")
        if choices == "__DYNAMIC__":
            kwargs['choices'] = shipping_choices()

        super(ShippingChoiceCharField, self).__init__(*args, **kwargs)

try:
    # South introspection rules for our custom field.
    from south.modelsinspector import add_introspection_rules, matching_details

    # get the kwargs for a Field instance
    # we're using Field, as CharField doesn't change __init__()
    _args, kwargs = matching_details(models.Field())

    add_introspection_rules([(
        (ShippingChoiceCharField, ),
        [],
        kwargs,
    )], ['shipping\.fields'])
except ImportError:
    pass