class TodoExportResource(resources.ModelResource):
    user = Field(attribute='user', column_name='User')
    text = Field(attribute='text', column_name='Todo')
    is_completed = Field(attribute='is_completed', column_name='Status')
    created_time = Field(attribute='created_time',
                         column_name='Created',
                         widget=DateTimeWidget(format='%d-%m-%Y %H:%M:%S'))
    last_updated = Field(attribute='last_updated',
                         column_name='Updated',
                         widget=DateTimeWidget(format='%d-%m-%Y %H:%M:%S'))

    class Meta:
        model = Todo
        exclude = ('id', )
        export_order = (
            'user',
            'text',
            'is_completed',
            'created_time',
            'last_updated',
        )

    def dehydrate_is_completed(self, todo):
        if todo.is_completed:
            return '%s' % ('Completed')
        else:
            return '%s' % ('Not Completed')
Exemple #2
0
class CouponResource(resources.ModelResource):
    # shop = fields.Field(
    #     widget=ForeignKeyWidget(Shop, 'title'))
    number = fields.Field(column_name='number', attribute='number')
    deadline = fields.Field(column_name='deadline',
                            attribute='deadline',
                            widget=DateTimeWidget("%d-%m-%Y %H:%M:%S"))
    used = fields.Field(column_name='used',
                        attribute='used',
                        saves_null_values=True,
                        default=None,
                        widget=DateTimeWidget("%d-%m-%Y %H:%M:%S"))
    shop = fields.Field(column_name='shop',
                        attribute='shop',
                        widget=ForeignKeyWidget(Shop, 'title'))

    class Meta:
        model = Coupon
        exclude = ('id', )
        import_id_fields = (
            'number',
            'deadline',
            'used',
            'shop',
        )
        # fields = ('shop',)
        widgets = {
            'deadline': {
                'format': '%d/%m/%Y'
            },
            'used': {
                'format': '%d/%m/%Y'
            },
        }
Exemple #3
0
class ReservationResource(resources.ModelResource):

    user = fields.Field(
        column_name='user',
        attribute='user',
        widget=ForeignKeyWidget(User, 'email'),
    )

    cancelation_reason = fields.Field(
        column_name='cancelation_reason',
        attribute='get_cancelation_reason_display',
    )

    start_time = fields.Field(
        column_name='start_time',
        attribute='timeslot__start_time',
        widget=DateTimeWidget(),
    )

    end_time = fields.Field(
        column_name='end_time',
        attribute='timeslot__end_time',
        widget=DateTimeWidget(),
    )

    class Meta:
        model = Reservation
        fields = (
            'id',
            'user',
            'timeslot',
            'start_time',
            'end_time',
            'cancelation_date',
            'cancelation_reason',
            'is_active',
            'is_present',
        )
        export_order = (
            'id',
            'user',
            'timeslot',
            'start_time',
            'end_time',
            'cancelation_date',
            'cancelation_reason',
            'is_active',
            'is_present',
        )
class WaitQueueNotificationResource(resources.ModelResource):

    user = fields.Field(
        column_name='user',
        attribute='user',
        widget=ForeignKeyWidget(User, 'email'),
    )

    retreat = fields.Field(
        column_name='retreat',
        attribute='retreat',
        widget=ForeignKeyWidget(Retreat, 'name'),
    )

    created_at = fields.Field(
        column_name='created_at',
        attribute='created_at',
        widget=DateTimeWidget(),
    )

    class Meta:
        model = Retreat
        fields = (
            'id',
            'user',
            'retreat',
            'created_at',
        )
        export_order = (
            'id',
            'user',
            'retreat',
            'created_at',
        )
Exemple #5
0
class RecordResource(resources.ModelResource):

    id = fields.Field(column_name='ID', attribute='id')
    record = fields.Field(column_name='记录', attribute='record')
    project = fields.Field(column_name='项目',
                           attribute='project',
                           widget=ForeignKeyWidget(Project, 'name'))
    add_time = fields.Field(column_name='创建时间',
                            attribute='add_time',
                            widget=DateTimeWidget('%Y-%m-%d %H:%M:%S'))
    last_modify_time = fields.Field(column_name='最后修改时间',
                                    attribute='last_modify_time',
                                    widget=DateTimeWidget('%Y-%m-%d %H:%M:%S'))
    type = fields.Field(column_name='类型', attribute='type')
    source = fields.Field(column_name='来源', attribute='source')

    class Meta:
        model = Record
class DegradacionResource(resources.ModelResource):
    perfil = fields.Field(column_name='perfil',
                          attribute='perfil',
                          widget=ForeignKeyWidget(Perfil, 'nombre_completo'))
    estacion = fields.Field(
        column_name='estacion',
        attribute='estacion__nombre',
    )
    actividad = fields.Field(column_name='actividad',
                             attribute='actividad',
                             widget=ForeignKeyWidget(Actividad, 'pk'))
    wp = fields.Field(column_name='wp', attribute='wp', widget=IntegerWidget())
    contenido = fields.Field(
        column_name='contenido',
        attribute='contenido',
    )
    creado = fields.Field(column_name='creado',
                          attribute='creado',
                          widget=DateTimeWidget(format='%d/%m/%Y %H:%M:%S'))
    actualizado = fields.Field(
        column_name='actualizado',
        attribute='actualizado',
        widget=DateTimeWidget(format='%d/%m/%Y %H:%M:%S'))

    class Meta:
        model = Degradacion
        exclude = ('imagen')
        export_order = (
            'id',
            'perfil',
            'estacion',
            'actividad',
            'wp',
            'contenido',
            'creado',
            'actualizado',
        )
Exemple #7
0
class RetreatReservationResource(resources.ModelResource):
    last_name = fields.Field(
        column_name='last_name',
        attribute='user',
        widget=ForeignKeyWidget(User, 'last_name'),
    )

    first_name = fields.Field(
        column_name='first_name',
        attribute='user',
        widget=ForeignKeyWidget(User, 'first_name'),
    )

    email = fields.Field(
        column_name='email',
        attribute='user',
        widget=ForeignKeyWidget(User, 'email'),
    )

    status = fields.Field(
        column_name='status',
        attribute='user',
        widget=ForeignKeyWidget(User, 'membership__name'),
    )

    order_date = fields.Field(
        column_name='order_date',
        attribute='order_line__order__transaction_date',
        widget=DateTimeWidget(),
    )

    promo_code = fields.Field(
        column_name='promo_code',
        attribute='order_line',
        widget=ForeignKeyWidget(OrderLine, 'coupon__code'),
    )

    personnal_restrictions = fields.Field(
        column_name='personnal_restriction',
        attribute='user',
        widget=ForeignKeyWidget(User, 'personnal_restrictions'),
    )

    city = fields.Field(
        column_name='city',
        attribute='user',
        widget=ForeignKeyWidget(User, 'city'),
    )

    phone = fields.Field(
        column_name='phone',
        attribute='user',
        widget=ForeignKeyWidget(User, 'phone'),
    )

    gender = fields.Field(
        column_name='gender',
        attribute='user',
        widget=ForeignKeyWidget(User, 'gender'),
    )

    invitation = fields.Field(
        column_name='invitation',
        attribute='invitation',
        widget=ForeignKeyWidget(RetreatInvitation, 'name'),
    )

    class Meta:
        model = Reservation
        fields = ('last_name', 'first_name', 'email', 'status', 'order_date',
                  'promo_code', 'personnal_restrictions', 'city', 'phone',
                  'is_active', 'is_present', 'invitation', 'gender')
        export_order = ('last_name', 'first_name', 'email', 'status',
                        'order_date', 'promo_code', 'personnal_restrictions',
                        'city', 'phone', 'is_active', 'is_present',
                        'invitation', 'gender')
Exemple #8
0
class ActivitySurveyDecisionResource(resources.ModelResource):

    decision_id = Field(attribute='id', column_name='Decision ID')
    heartsteps_id = Field(column_name='HeartSteps ID')
    decision_date = Field(column_name='Decision Date')
    decision_time = Field(column_name='Decision Time')
    decision_timezone = Field(column_name='Timezone')

    treated = Field(attribute='treated', column_name='Treated')
    treatment_probability = Field(attribute='treatment_probability',
                                  column_name='Treatment Probability')

    fitbit_activity_id = Field(attribute='fitbit_activity__id',
                               column_name='Fitbit Activity ID')
    fitbit_activity_start = Field(
        attribute='fitbit_activity__start_time',
        column_name='Fitbit Activity Start Time',
        widget=DateTimeWidget(format='%Y-%m-%d %H:%M:%S'))
    fitbit_activity_duration = Field(attribute='fitbit_activity__duration',
                                     column_name='Fitbit Activity Duration')
    fitbit_activity_type = Field(attribute='fitbit_activity__type__name',
                                 column_name='Fitbit Activity Type')

    notification_id = Field(attribute='notification__id',
                            column_name='Notification ID')
    notification_sent = Field(
        attribute='notification__sent',
        column_name='Notification Sent',
        widget=DateTimeWidget(format='%Y-%m-%d %H:%M:%S'))
    notification_received = Field(
        attribute='notification__received',
        column_name='Notification Received',
        widget=DateTimeWidget(format='%Y-%m-%d %H:%M:%S'))
    notification_opened = Field(
        attribute='notification__opened',
        column_name='Notification Opened',
        widget=DateTimeWidget(format='%Y-%m-%d %H:%M:%S'))

    class Meta:
        model = Decision
        fields = []

    def format_date(self, _datetime):
        return _datetime.strftime('%Y-%m-%d')

    def format_time(self, _datetime):
        return _datetime.strftime('%H:%M:%S')

    def dehydrate_heartsteps_id(self, decision):
        return decision.user.username

    def dehydrate_decision_date(self, decision):
        return self.format_date(decision.randomized_at)

    def dehydrate_decision_time(self, decision):
        return self.format_time(decision.randomized_at)

    def dehydrate_decision_timezone(self, decision):
        return decision.randomized_at.tzname()

    def after_export(self, queryset, data, *args, **kwargs):
        questions = {}
        for decision in queryset:
            if decision.activity_survey and hasattr(decision.activity_survey,
                                                    '_questions'):
                for question in decision.activity_survey._questions:
                    if question.id not in questions.keys():
                        questions[question.name] = {
                            'name': question.name,
                            'answers': []
                        }
        for decision in queryset:
            if decision.activity_survey and hasattr(decision.activity_survey,
                                                    '_answers'):
                for question_name, answer in decision.activity_survey._answers.items(
                ):
                    questions[question_name]['answers'].append(answer.value)
            else:
                for question in questions.values():
                    question['answers'].append(None)

        for question_key in sorted(questions.keys()):
            question = questions[question_key]
            data.append_col(question['answers'], header=question['name'])