Example #1
0
def show(work_id):
    schema = WorkSchema()
    work = Work.get(id=work_id)

    if not work:
        abort(404)

    return schema.dumps(work)
Example #2
0
def delete(work_id):
    work = Work.get(id=work_id)

    if not work:
        abort(404)

    work.delete()
    db.commit()

    return '', 204
Example #3
0
 def update_from_json(self, data):
     self.name = data['name']
     self.factor = data['factor']
     self.salary_factor = data['salaryFactor']
     self.type_id = data['roomType']
     self.works = Work.array_from_json(data['works'], self.works)
     self.elements = Element.array_from_json(data['elements'],
                                             self.elements)
     self.parameter_values = ParameterValue.array_from_json(
         data['parameters'], self.parameter_values)
Example #4
0
def show(work_id):
    # This will serialize our data
    schema = WorkSchema()
    # This gets a work by ID
    work = Work.get(id=work_id)

    # If we can't find a work, send a 404 response
    if not work:
        abort(404)

    # otherwise, send back the work data as JSON
    return schema.dumps(work)
Example #5
0
def update(work_id):
    schema = WorkSchema()
    work = Work.get(id=work_id)

    if not work:
        abort(404)

    try:
        data = schema.load(request.get_json())
        work.set(**data)
        db.commit()
    except ValidationError as err:
        return jsonify({
            'message': 'Validation failed',
            'errors': err.messages
        }), 422

    return schema.dumps(work)
Example #6
0
def create():

    schema = WorkSchema()

    try:

        data = schema.load(request.get_json())

        work = Work(**data)

        db.commit()
    except ValidationError as err:

        return jsonify({
            'message': 'Validation failed',
            'errors': err.messages
        }), 422

    return schema.dumps(work), 201
Example #7
0
def create():
    # This will deserialize the JSON from insomnia
    schema = WorkSchema()

    try:
        # attempt to convert the JSON into a dict
        data = schema.load(request.get_json())
        # Use that to create a work object
        work = Work(**data, createdBy=g.current_user)
        # store it in the database
        db.commit()
    except ValidationError as err:
        # if the validation fails, send back a 422 response
        return jsonify({
            'message': 'Validation failed',
            'errors': err.messages
        }), 422

    # otherwise, send back the work data as JSON
    return schema.dumps(work), 201
Example #8
0
def draw_pastell(nx=900, ny=1600, CL=180, rshift=3):
    nz = 3
    mid = nx // 2
    dCL = 50
    #---- start the coloring ----------
    A = np.ones((nx, ny, nz)) * CL  # initialize the image matrix
    #np.random.seed(1234)                  # initialize RNG

    #---- initialize the lower part ----
    ix = slice(0, mid - 1)
    iz = slice(0, nz)  # color the left boundary
    A[ix, 0, iz] = CL + np.cumsum(
        np.random.randint(-rshift, rshift + 1, size=(mid - 1, nz)), axis=0)

    #---- initialize the upper part ----
    ix = slice(mid, nx)
    iz = slice(0, nz)  # color the left boundary
    A[ix, 0, iz] = CL - dCL + np.cumsum(
        np.random.randint(-rshift, rshift + 1, size=(nx - mid, nz)), axis=0)

    #---- march to the right boundary -------------
    ix = slice(1, nx - 1)
    ixm = slice(0, nx - 2)
    ixp = slice(2, nx)
    for jy in range(1, ny):  # smear the color to the right boundary
        A[ix, jy, iz] = 0.3333 * (A[ixm, jy - 1, iz] + A[ix, jy - 1, iz] +
                                  A[ixp, jy - 1, iz]) + np.random.randint(
                                      -rshift, rshift + 1, size=(nx - 2, nz))

    #---- show&save grafics ---------
    im1 = Image.fromarray(A.astype(np.uint8)).convert('RGBA')
    draw1 = ImageDraw.Draw(im1, "RGBA")
    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)
    for i in range(randint(0, 10)):
        draw1.rectangle(((randint(0, 6000), randint(0, 6000)),
                         (randint(0, 100), randint(0, 100))),
                        fill=tuple(np.random.randint(256, size=3)) + (60, ))
    im1 = im1.filter(ImageFilter.CONTOUR)
    im1 = im1.filter(ImageFilter.EMBOSS)

    for i in range(randint(0, 500)):
        im1 = im1.filter(ImageFilter.BLUR)
    for i in range(randint(0, 500)):
        im1 = im1.filter(ImageFilter.EDGE_ENHANCE_MORE)
    for i in range(randint(0, 500)):
        im1 = im1.filter(ImageFilter.CONTOUR)
    for i in range(randint(0, 500)):
        im1 = im1.filter(ImageFilter.EDGE_ENHANCE_MORE)

    for i in range(randint(0, 500)):
        im1 = im1.filter(ImageFilter.BLUR)
    for i in range(randint(0, 1000)):
        im1 = im1.filter(ImageFilter.EDGE_ENHANCE_MORE)

    buf = io.BytesIO()
    im1.save(buf, format='PNG')
    thing = buf.getvalue()
    db.drop_all_tables(with_all_data=True)
    db.create_tables()
    with db_session():

        Work(dat=str(base64.b64encode(buf.getvalue()))),

        db.commit()
Example #9
0
def index():
    # This will serialize our data
    # `many=True` because there are many works, ie we expect a list
    schema = WorkSchema(many=True)
    works = Work.select()  # get all the works
    return schema.dumps(works)  # `schema.dumps` converts the list to JSON
Example #10
0
    )

    Work(
        createdBy=Hiro,
        created="2018/07/02",
        name="Python pic 1",
        picture=
        "https://66.media.tumblr.com/2e27aafca3635fc39ed986936b50379e/tumblr_ps9jc4j0UH1w3debko1_1280.png",
        description=
        """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tristique neque ut accumsan tristique. Cras leo felis, semper in eleifend placerat, efficitur a nunc. Morbi fringilla egestas ante, vitae lacinia nunc vestibulum vitae. Mauris auctor dui eget gravida viverra. Pellentesque vel ultricies diam, sit amet dapibus leo. Morbi mattis enim elit, a imperdiet augue tempor ut. Suspendisse suscipit eleifend dui, bibendum consectetur arcu tristique vel. Nam nec risus aliquet, porttitor quam nec, ultrices sapien. Etiam in iaculis enim. Morbi ultricies semper arcu, vel luctus nulla iaculis auctor. Praesent vitae augue vitae lectus ultrices venenatis sit amet non dolor. Fusce dapibus dignissim nulla sit amet lacinia. Fusce non tortor ac quam vestibulum viverra. Praesent a lectus et dolor consequat aliquet vitae non turpis. Nullam et nulla vitae mi ultrices viverra. Integer sodales arcu velit, a faucibus neque dapibus ut.\n\n

        Curabitur tempus risus sit amet mi finibus mattis. Quisque gravida tempor tortor at consequat. Duis vulputate interdum leo id congue. Maecenas rhoncus nec ligula ut malesuada. Pellentesque volutpat felis ligula, vitae dapibus augue faucibus a. Aenean sagittis enim at quam accumsan, a varius lectus dignissim. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Ut imperdiet arcu ipsum, et porttitor velit scelerisque ut. Vivamus vitae semper mi, eu efficitur neque.""",
        medium=illustration,
        code="""from PIL import Image, ImageDraw, ImageFilter


        #im = Image.open("6MzjjikJ_400x400.jpg")
        im = Image.open("29.png")

        im1 = im.filter(ImageFilter.CONTOUR)
        im1 = im.filter(ImageFilter.FIND_EDGES)
        im6 = im1.filter(ImageFilter.BLUR)
        im5 = im6.filter(ImageFilter.CONTOUR)
        im7 = im5.filter(ImageFilter.EDGE_ENHANCE)
        im8 = im7.filter(ImageFilter.EDGE_ENHANCE)
        im2 = im.filter(ImageFilter.MinFilter(3))
        im3 = im.filter(ImageFilter.MinFilter)  # same as MinFilter(3)
        im8.save('29.png')
        """)

    Work(
Example #11
0
def index():
    schema = WorkSchema(many=True)
    works = Work.select()
    return schema.dumps(works)