Example #1
0
class ProcessBatchAdminResource(resources.ModelResource):
    user = fields.Field(column_name='user', widget=CharWidget())
    process = fields.Field(column_name='process', widget=CharWidget())
    batch = fields.Field(attribute="batch",
                         column_name='batch',
                         widget=ProcessBatchAdminForeignKeyWidget(
                             Batch, 'name'))

    def dehydrate_process(self, Instance):
        return rgetattr(Instance, 'batch.process.name')

    def dehydrate_user(self, Instance):
        return rgetattr(Instance, 'batch.process.owner.username')

    def before_import(self, dataset, using_transactions, dry_run, **kwargs):
        for row in dataset.dict:
            user_ins = get_user_model().objects.filter(
                username=row["user"]).first()
            if not user_ins:
                raise ValidationError(
                    'Could not find for user \'%s\' defined in row %s.' %
                    (user_ins, row))
            process_ins = Process.objects.filter(name=row['process'],
                                                 owner=user_ins).first()
            if not process_ins:
                raise ValidationError(
                    'Could not find process \'%s\' for user \'%s\' defined in row %s.'
                    % (process_ins, user_ins, row))
            batch_ins = Batch.objects.filter(name=row['batch'],
                                             process=process_ins).first()
            if not batch_ins:
                raise ValidationError(
                    'Could not find batch \'%s\' related to process \'%s\' for user \'%s\' for row %s'
                    % (batch_ins, process_ins, user_ins, row))
Example #2
0
class Pannzer2AnnotationResource(resources.ModelResource):
    organism = fields.Field(column_name='organism',
                            attribute='organism',
                            widget=ForeignKeyWidget(Organism, 'taxid'))
    protein_id = fields.Field(column_name='protein_id',
                              attribute='protein_id',
                              widget=CharWidget())
    go_id = fields.Field(column_name='go_id',
                         attribute='go_id',
                         widget=CharWidget())
    ontology = fields.Field(column_name='ontology',
                            attribute='ontology',
                            widget=CharWidget())
    description = fields.Field(column_name='description',
                               attribute='description',
                               widget=CharWidget())
    skip_unchanged = True
    report_skipped = True
    exclude = ('id', )

    class Meta:
        model = Pannzer2Annotation
        fields = ('organism', 'protein_id', 'go_id', 'ontology', 'description',
                  'id')
Example #3
0
class AnalysisAnnotatedGeneResource(resources.ModelResource):
    organism = fields.Field(column_name='organism',
                            attribute='organism',
                            widget=ForeignKeyWidget(Organism, 'taxid'))
    experimental_design = fields.Field(column_name='experimental_design',
                                       attribute='experimental_design',
                                       widget=ForeignKeyWidget(
                                           ExperimentalDesign, 'description'))
    de_gene = fields.Field(column_name='de_gene',
                           attribute='de_gene',
                           widget=CharWidget())
    log_fc = fields.Field(column_name='log_fc',
                          attribute='log_fc',
                          widget=FloatWidget())
    log_cpm = fields.Field(column_name='log_cpm',
                           attribute='log_cpm',
                           widget=FloatWidget())
    f = fields.Field(column_name='f', attribute='f', widget=FloatWidget())
    p_value = fields.Field(column_name='p_value',
                           attribute='p_value',
                           widget=FloatWidget())
    fdr = fields.Field(column_name='fdr',
                       attribute='fdr',
                       widget=FloatWidget())
    real_differential_expression = fields.Field(
        column_name='real_differential_expression',
        attribute='real_differential_expression',
        widget=BooleanWidget())
    skip_unchanged = True
    report_skipped = True
    exclude = ('id', )

    class Meta:
        model = AnalysisAnnotatedGene
        fields = ('organism', 'experimental_design', 'de_gene', 'log_fc',
                  'log_cpm', 'f', 'p_value', 'fdr', 'id')
Example #4
0
class CustomerResource(resources.ModelResource):
    id = fields.Field(attribute='id', widget=IdWidget(), readonly=True)
    email = fields.Field(attribute='user',
                         default="*****@*****.**",
                         widget=OneToOneWidget(User, 'email'),
                         readonly=False)
    phone1 = fields.Field(attribute='phone1',
                          default="1234",
                          widget=CharWidget(),
                          readonly=False)
    phone2 = fields.Field(attribute='phone2',
                          widget=CharWidget(),
                          readonly=False)
    date_balance = fields.Field(attribute='get_admin_date_balance',
                                widget=CharWidget(),
                                readonly=True)
    balance = fields.Field(attribute='get_admin_balance',
                           widget=TwoMoneysWidget(),
                           readonly=True)
    may_order = fields.Field(attribute='may_order',
                             default=False,
                             widget=DecimalBooleanWidget(),
                             readonly=False)
    is_group = fields.Field(attribute='is_group',
                            default=False,
                            widget=DecimalBooleanWidget(),
                            readonly=False)
    represent_this_buyinggroup = fields.Field(
        attribute='represent_this_buyinggroup',
        default=False,
        widget=DecimalBooleanWidget(),
        readonly=True)
    is_active = fields.Field(attribute='is_active',
                             widget=DecimalBooleanWidget(),
                             readonly=True)
    membership_fee_valid_until = fields.Field(
        attribute='membership_fee_valid_until',
        default=timezone.now().date(),
        widget=DateWidgetExcel(),
        readonly=False)
    last_membership_fee = fields.Field(attribute='get_last_membership_fee',
                                       widget=TwoMoneysWidget(),
                                       readonly=True)
    last_membership_fee_date = fields.Field(
        attribute='last_membership_fee_date',
        widget=DateWidgetExcel(),
        readonly=True)
    purchase = fields.Field(attribute='get_purchase',
                            widget=ZeroDecimalsWidget(),
                            readonly=True)
    participation = fields.Field(attribute='get_participation',
                                 widget=ZeroDecimalsWidget(),
                                 readonly=True)
    delivery_point = fields.Field(attribute='delivery_point',
                                  widget=TranslatedForeignKeyWidget(
                                      LUT_DeliveryPoint, field='short_name'))
    valid_email = fields.Field(attribute='valid_email',
                               widget=DecimalBooleanWidget(),
                               readonly=True)
    zero_waste = fields.Field(attribute='zero_waste',
                              widget=DecimalBooleanWidget(),
                              readonly=True)
    date_joined = fields.Field(attribute='get_admin_date_joined',
                               widget=CharWidget(),
                               readonly=True)

    def before_save_instance(self, instance, using_transactions, dry_run):
        """
        Override to add additional logic.
        """
        user_model = get_user_model()
        user_email_qs = user_model.objects.filter(email=instance.user.email,
                                                  is_staff=False).order_by('?')
        user_username_qs = user_model.objects.filter(
            username=instance.short_basket_name).order_by('?')
        if instance.id is not None:
            customer = Customer.objects.filter(
                id=instance.id).order_by('?').only('id', 'user_id').first()
            user_email_qs = user_email_qs.exclude(id=customer.user_id)
            user_username_qs = user_username_qs.exclude(id=customer.user_id)
        else:
            customer = None
        if user_email_qs.exists():
            raise ValueError(
                _("The email {} is already used by another user.").format(
                    instance.user.email))
        if user_username_qs.exists():
            raise ValueError(
                _("The short_basket_name {} is already used by another user.").
                format(instance.short_basket_name))
        if using_transactions or not dry_run:
            if instance.id is not None:
                email = instance.user.email
                instance.user = user_model.objects.get(id=customer.user_id)
                instance.user.username = instance.short_basket_name
                instance.user.first_name = EMPTY_STRING
                instance.user.last_name = instance.short_basket_name
                instance.user.email = email
                instance.user.save()
            else:
                instance.user = user_model.objects.create_user(
                    username=instance.short_basket_name,
                    email=instance.user.email,
                    password=uuid.uuid1().hex,
                    first_name=EMPTY_STRING,
                    last_name=instance.short_basket_name)
                instance.user_id = instance.user.id

    class Meta:
        model = Customer
        fields = ('id', 'may_order', 'short_basket_name', 'long_basket_name',
                  'email', 'email2', 'language', 'phone1', 'phone2', 'address',
                  'city', 'bank_account1', 'bank_account2', 'date_balance',
                  'balance', 'price_list_multiplier',
                  'membership_fee_valid_until', 'last_membership_fee',
                  'last_membership_fee_date', 'participation', 'purchase',
                  'represent_this_buyinggroup', 'is_group', 'is_active',
                  'delivery_point', 'zero_waste', 'valid_email')
        export_order = fields
        import_id_fields = ('id', )
        skip_unchanged = True
        report_skipped = False
        use_transactions = False
Example #5
0
class ProducerResource(resources.ModelResource):

    id = fields.Field(attribute="id", widget=IdWidget(), readonly=True)
    phone1 = fields.Field(attribute="phone1",
                          widget=CharWidget(),
                          readonly=False)
    phone2 = fields.Field(attribute="phone2",
                          widget=CharWidget(),
                          readonly=False)

    price_list_multiplier = fields.Field(
        attribute="price_list_multiplier",
        default=DECIMAL_ONE,
        widget=TwoDecimalsWidget(),
        readonly=False,
    )
    date_balance = fields.Field(attribute="get_admin_date_balance",
                                widget=DateWidgetExcel(),
                                readonly=True)
    balance = fields.Field(attribute="get_admin_balance",
                           widget=TwoMoneysWidget(),
                           readonly=True)
    invoice_by_basket = fields.Field(
        attribute="invoice_by_basket",
        default=False,
        widget=DecimalBooleanWidget(),
        readonly=False,
    )
    sort_products_by_reference = fields.Field(
        attribute="sort_products_by_reference",
        default=False,
        widget=DecimalBooleanWidget(),
        readonly=False,
    )
    represent_this_buyinggroup = fields.Field(
        attribute="represent_this_buyinggroup",
        default=False,
        widget=DecimalBooleanWidget(),
        readonly=True,
    )
    is_active = fields.Field(attribute="is_active",
                             widget=DecimalBooleanWidget(),
                             readonly=True)
    reference_site = fields.Field(attribute="reference_site", readonly=True)

    def before_save_instance(self, instance, using_transactions, dry_run):
        """
        Override to add additional logic.
        """
        producer_qs = Producer.objects.filter(
            short_profile_name=instance.short_profile_name).order_by("?")
        if instance.id is not None:
            producer_qs = producer_qs.exclude(id=instance.id)
        if producer_qs.exists():
            raise ValueError(
                _("The short_basket_name {} is already used by another producer."
                  ).format(instance.short_profile_name))

    class Meta:
        model = Producer
        fields = (
            "id",
            "short_profile_name",
            "long_profile_name",
            "email",
            "email2",
            "email3",
            "language",
            "phone1",
            "phone2",
            "fax",
            "address",
            "invoice_by_basket",
            "sort_products_by_reference",
            "producer_price_are_wo_vat",
            "price_list_multiplier",
            "reference_site",
            "bank_account",
            "date_balance",
            "balance",
            "represent_this_buyinggroup",
            "is_active",
        )
        export_order = fields
        import_id_fields = ("id", )
        skip_unchanged = True
        report_skipped = False
        use_transactions = False
Example #6
0
class ProducerResource(resources.ModelResource):
    id = fields.Field(attribute='id', widget=IdWidget(), readonly=True)
    phone1 = fields.Field(attribute='phone1',
                          default='1234',
                          widget=CharWidget(),
                          readonly=False)
    phone2 = fields.Field(attribute='phone2',
                          widget=CharWidget(),
                          readonly=False)
    price_list_multiplier = fields.Field(attribute='price_list_multiplier',
                                         default=DECIMAL_ONE,
                                         widget=TwoDecimalsWidget(),
                                         readonly=False)
    date_balance = fields.Field(attribute='get_admin_date_balance',
                                widget=DateWidgetExcel(),
                                readonly=True)
    balance = fields.Field(attribute='get_admin_balance',
                           widget=TwoMoneysWidget(),
                           readonly=True)
    invoice_by_basket = fields.Field(attribute='invoice_by_basket',
                                     default=False,
                                     widget=DecimalBooleanWidget(),
                                     readonly=False)
    manage_replenishment = fields.Field(attribute='manage_replenishment',
                                        default=False,
                                        widget=DecimalBooleanWidget(),
                                        readonly=False)
    sort_products_by_reference = fields.Field(
        attribute='sort_products_by_reference',
        default=False,
        widget=DecimalBooleanWidget(),
        readonly=False)
    is_resale_price_fixed = fields.Field(attribute='is_resale_price_fixed',
                                         default=False,
                                         widget=DecimalBooleanWidget(),
                                         readonly=False)
    represent_this_buyinggroup = fields.Field(
        attribute='represent_this_buyinggroup',
        default=False,
        widget=DecimalBooleanWidget(),
        readonly=True)
    is_active = fields.Field(attribute='is_active',
                             widget=DecimalBooleanWidget(),
                             readonly=True)
    reference_site = fields.Field(attribute='reference_site', readonly=True)

    def before_save_instance(self, instance, using_transactions, dry_run):
        """
        Override to add additional logic.
        """
        if not settings.REPANIER_SETTINGS_STOCK:
            if instance.manage_replenishment:
                raise ValueError(
                    _("Manage replenishment must be set to False because this option is not activated."
                      ))
        producer_qs = Producer.objects.filter(
            short_profile_name=instance.short_profile_name).order_by('?')
        if instance.id is not None:
            producer_qs = producer_qs.exclude(id=instance.id)
        if producer_qs.exists():
            raise ValueError(
                _("The short_basket_name {} is already used by another producer."
                  ).format(instance.short_profile_name))

    class Meta:
        model = Producer
        fields = ('id', 'short_profile_name', 'long_profile_name', 'email',
                  'email2', 'email3', 'language', 'phone1', 'phone2', 'fax',
                  'address', 'invoice_by_basket', 'manage_replenishment',
                  'sort_products_by_reference', 'producer_pre_opening',
                  'producer_price_are_wo_vat', 'price_list_multiplier',
                  'is_resale_price_fixed', 'reference_site', 'bank_account',
                  'date_balance', 'balance', 'represent_this_buyinggroup',
                  'is_active')
        export_order = fields
        import_id_fields = ('id', )
        skip_unchanged = True
        report_skipped = False
        use_transactions = False