Beispiel #1
0
class ReclamationSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Reclamation
        include_fk = True
        include_relationships = True
        load_instance = True
        exclude = (
            "customer_id",
            "part_sn_id",
            "requester",
            "tickets",
            "reclamation_requester",
            "note_rec",
        )

    # reclamation_requester = fields.Nested(UserSchema, only=('username', 'first_name', 'last_name'))
    reclamation_customer = fields.Nested(CustomerSchema, only=("name", ))
    # how to show part model?
    reclamation_part_sn_id = fields.Nested(PartDetailsSchema,
                                           only=("part_sn", "part_no.model"))

    _links = Hyperlinks({
        "self":
        URLFor("reclamation_bp.reclamation", reclamation_number="<id>")
    })
Beispiel #2
0
class CoursesSchema(Schema):
    class Meta:
        ordered = True

    @staticmethod
    def ratings_average_calculate(obj):
        point = []
        for rating in obj.ratings:
            point.append(rating.points)
        return np.average(point)

    id = fields.UUID()

    name = fields.String()
    # https://stackoverflow.com/questions/53606872/datetime-format-in-flask-marshmallow-schema
    created_on = fields.DateTime()
    updated_on = fields.DateTime()

    platform = fields.Nested('PlatformsSchema')
    publisher = fields.Nested('PublishersSchema')

    ratings = fields.Nested('RatingsSchema', many=True)
    ratings_count = fields.Function(lambda obj: len(obj.ratings))

    reviews = fields.Nested('ReviewsSchema', many=True)
    reviews_count = fields.Function(lambda obj: len(obj.reviews))

    tags = fields.Nested('TagsSchema', many=True)

    keywords = fields.Nested('KeywordsSchema', many=True)
    releases = fields.Nested('ReleasesSchema', many=True)

    _links = Hyperlinks(
        {"self": URLFor("courses.get", id="<id>"), "collection": URLFor("courses.get_all")}
    )
Beispiel #3
0
class MeetingSchemaUser(MeetingSchema):
    completed = ma.Boolean(dump_only=True)

    _links = Hyperlinks({
        'user':
        URLFor('Users.MyUserDetails', values=None),
        'agendas':
        URLFor('Meetings.MeetingAgendas', values=dict(meeting_id='<id>')),
    })
Beispiel #4
0
class PageSchema(Schema):
    id = fields.Integer()
    title = fields.String()
    content = fields.String()
    actual = fields.Integer()

    _links = Hyperlinks({
        'self': URLFor('page', page_id='<id>'),
        'collection': URLFor('page'),
        'revisions': URLFor('revisions', page_id='<id>')
    })
Beispiel #5
0
class PlaylistsSchema(Schema):
    name = fields.String(required=True)
    description = fields.String(required=True)

    _links = Hyperlinks(
        {
            "self":
            URLFor("playlistapi",
                   values=dict(playlist_id="<id>"),
                   _external=True,
                   required=True),
        },
        required=True)
class ReleaseTypesSchema(Schema):
    class Meta:
        ordered = True

    id = fields.UUID()

    name = fields.String()
    description = fields.String()
    created_on = fields.DateTime()
    updated_on = fields.DateTime()

    _links = Hyperlinks(
        {"self": URLFor("release_types.get", id="<id>"), "collection": URLFor("release_types.get_all")}
    )
Beispiel #7
0
class PlatformsSchema(Schema):
    class Meta:
        ordered = True

    id = fields.UUID()

    name = fields.String()
    created_on = fields.DateTime()
    updated_on = fields.DateTime()

    _links = Hyperlinks({
        "self": URLFor("platforms.get", id="<id>"),
        "collection": URLFor("platforms.get_all")
    })
class ProjectSchema(Schema):
    _id = fields.Str()
    timestamp = fields.Str()
    user_ID = fields.Str(required=True)
    project_name = fields.Str(required=True)
    project_data = fields.Raw()

    _links = Hyperlinks({
        'self':
        URLFor("projects.get_withUserAndProject",
               user_ID='<user_ID>',
               project_name='<project_name>'),
        'owner':
        URLFor("projects.getUser", user_ID='<user_ID>')
    })
Beispiel #9
0
class RevisionSchema(Schema):
    id = fields.Integer()
    add_date = fields.DateTime()
    title = fields.String()
    text = fields.String()
    actual = fields.Boolean()

    _links = Hyperlinks({
        'self':
        URLFor('revisions', page_id='<page_id>', revision_id='<id>'),
        'make-actual':
        URLFor('revisions/set', page_id='<page_id>', revision_id='<id>'),
        'page-revisions':
        URLFor('revisions', page_id='<id>')
    })
Beispiel #10
0
class TicketSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Ticket
        include_relationships = True
        load_instance = True
        include_fk = True

    ticket_assigned = fields.Nested(UserSchema,
                                    only=("username", "first_name",
                                          "last_name"))
    reclamation = fields.Nested(ReclamationSchema,
                                only=("reclamation_customer",
                                      "reclamation_part_sn_id"))
    _links = Hyperlinks(
        {"self": URLFor("ticket_bp.ticket", ticket_number="<id>")})
Beispiel #11
0
class ProcessSchema(Schema):
    process_id = fields.Int(dump_to='processID')
    reference_year = fields.Function(
        serialize=lambda itm: itm['TemporalScope'], dump_to='referenceYear')
    geography = fields.Function(serialize=lambda itm: itm['SpatialScope'])
    # reference_type_id = SKIP
    # composition_flow_id = SKIP
    data_source = fields.Str(attribute='origin', dump_to='dataSource')
    has_elem = fields.Bool(dump_to='hasElementaryFlows')
    name = fields.Function(serialize=lambda itm: itm['Name'])
    uuid = fields.Str()
    version = fields.Function(serialize=lambda itm: itm['Version'])
    resource_type = fields.Str(attribute='entity_type', dump_to='resourceType')
    is_private = fields.Bool(dump_to='isPrivate')

    _links = Hyperlinks({'self': URLFor('processes', id='<id>')})
Beispiel #12
0
class ReviewsSchema(Schema):
    class Meta:
        ordered = True

    id = fields.UUID()

    description = fields.String()
    created_on = fields.DateTime()
    updated_on = fields.DateTime()

    user = fields.Nested('UsersSchema', many=False)

    _links = Hyperlinks(
        {"self": URLFor("courses.reviews_get", course_id="<course_id>", review_id="<id>"),
         "collection": URLFor("courses.reviews_get_all", course_id="<course_id>")}
    )
class UserSchema(Schema):
    # this class validates the incoming json and creates hyperlinks to connected routes and states
    user_ID = fields.Str()
    amount_of_projects = fields.Integer()
    items = fields.Raw()

    _links = Hyperlinks({
        'self':
        URLFor('projects.getUser', user_ID='<user_ID>'),
        'projects':
        URLFor('projects.get_withUser', user_ID='<user_ID>')
    })

    @pre_dump
    def init_params(self, data, **kwargs):
        # get the projects from the user
        # wrap them with hyperlinks
        # sort the by timestamp
        # count the amount
        userstr = data.get("user_ID")
        projects = []
        temp = Service.query_ProjectsFromUser(userstr)
        log.info('this is the tempdata from userschema')
        log.info(temp)
        newdata = {}
        for project in temp:
            try:
                projects.append(generateProjectLinks(project))
            except ValidationError as e:
                log.info('validator.errors')
                log.info('this data is correct')
                log.info(e.valid_data)
                log.info('this data is not correct')
                log.info(validateProject(project))
                return Standard400ErrorResponse(
                    'Oooops, This Request is not valid',
                    validateProject(project))
        newdata['items'] = sorted(projects,
                                  key=lambda timestamp: timestamp['timestamp'])
        newdata['amount_of_projects'] = len(newdata['items'])
        newdata['user_ID'] = userstr
        log.info('newdata predump')
        log.info(newdata)
        data = newdata

        return data
Beispiel #14
0
class RatingsSchema(Schema):
    class Meta:
        ordered = True

    id = fields.UUID()

    points = fields.Integer()
    created_on = fields.DateTime()
    updated_on = fields.DateTime()

    user = fields.Nested('UsersSchema', many=False)

    _links = Hyperlinks({
        "self":
        URLFor("courses.ratings_get",
               course_id="<course_id>",
               rating_id="<id>"),
        "collection":
        URLFor("courses.ratings_get_all", course_id="<course_id>")
    })
Beispiel #15
0
class UserAgreementsSchema(Schema):
    class Meta:
        ordered = True

    id = fields.UUID()

    is_read = fields.Boolean()
    is_accepted = fields.Boolean()
    created_on = fields.DateTime()
    updated_on = fields.DateTime()
    agreement = fields.Nested('AgreementsSchema',
                              many=False,
                              exclude=['_links'])

    _agreement_links = Hyperlinks({
        "self":
        URLFor("agreements.get", id="<agreements_id>"),
        "collection":
        URLFor("agreements.get_all")
    })