示例#1
0
    def test_pop_large(self):

        # Area assuming margin of 2
        # 1 = 130
        # 2 = 238
        # 3 = 120
        # 4 = 208
        # 5 = 99
        # 6 = 221
        # 7 = 418
        # 8 = 270

        wkspc = ar.Workspace(1)
        arngr = ar.Arranger(wkspc)

        returned = arngr.pop_large()
        self.assertIn(returned, [7, 8])
        self.assertNotIn(returned, arngr.pics_remaining)

        returned = arngr.pop_large()
        self.assertIn(returned, [7, 8])
        self.assertNotIn(returned, arngr.pics_remaining)

        returned = arngr.pop_large()
        self.assertEqual(returned, 2)
        self.assertNotIn(returned, arngr.pics_remaining)

        returned = arngr.pop_large()
        self.assertEqual(returned, 6)
        self.assertNotIn(returned, arngr.pics_remaining)
示例#2
0
def get_arranged_data():
    """Get the information needed for displaying a gallery.

    Response to an AJAX request.
    """

    gallery_id = int(request.form.get('gallery_id'))
    # margin = request.form.get('margin')
    wkspc = ar.Workspace(gallery_id)

    algorithm_type = request.form.get('algorithm_type')

    if algorithm_type == 'linear':
        arr = ar.LinearArranger(wkspc)
    elif algorithm_type == 'column':
        arr = ar.ColumnArranger(wkspc)
    elif algorithm_type == 'grid':
        arr = ar.GridArranger(wkspc)
    else:
        # Default to column arrangement
        arr = ar.ColumnArranger(wkspc)

    arr.arrange()

    wall_id = Wall.init_from_workspace(wkspc)

    new_wall_data = {'id': wall_id}

    return jsonify(new_wall_data)
示例#3
0
    def test_wall_size(self):

        # Test Gallery (11)
        # 11 | 49, 42, 41
        # 41  |   1   |   4   |   4   |   love_4x4.jpg    |   love    |   @elsabirch  |   public
        # 42  |   1   |   6   |   6   |   banana_6x6.jpg  |   banana  |   @elsabirch  |   public
        # 49  |   1   |   10  |   8   |   wave_10x8.jpg   |   wave    |   @elsabirch  |   public

        wkspc = ar.Workspace(11)
        arngr = ar.Arranger(wkspc)

        wkspc.pics[41].x1 = 0
        wkspc.pics[41].y1 = 0
        wkspc.pics[41].x2 = wkspc.pics[41].x1 + wkspc.pics[41].w
        wkspc.pics[41].y2 = wkspc.pics[41].y1 + wkspc.pics[41].h

        wkspc.pics[42].x1 = 9
        wkspc.pics[42].y1 = 0
        wkspc.pics[42].x2 = wkspc.pics[42].x1 + wkspc.pics[42].w
        wkspc.pics[42].y2 = wkspc.pics[42].y1 + wkspc.pics[42].h

        wkspc.pics[49].x1 = 0
        wkspc.pics[49].y1 = 9
        wkspc.pics[49].x2 = wkspc.pics[49].x1 + wkspc.pics[49].w
        wkspc.pics[49].y2 = wkspc.pics[49].y1 + wkspc.pics[49].h

        arngr.get_wall_size()

        self.assertEqual(wkspc.height, 19)
        self.assertEqual(wkspc.width, 17)
示例#4
0
    def display_wall_id(self):

        wall_id = (db.session.query(Wall.wall_id)
                             .join(Gallery)
                             .filter(Gallery.gallery_id == self.gallery_id,
                                     Wall.gallery_display == True)
                             .first())

        if not wall_id:

            arrange_options = {}

            lazy_load_of_workspace()
            wkspc = ar.Workspace(self.gallery_id)
            arranger_instance = ar.GalleryFloorArranger(wkspc)
            # import pdb
            # pdb.set_trace()
            arranger_instance.arrange()
            wall_id = Wall.init_from_workspace(wkspc)
            # db.session.flush()
            Wall.query.get(wall_id).set_gallery_display()

        else:
            # TODO: there should be a more graceful way to deal with that query
            # returning either None or a tuple
            wall_id = wall_id[0]

        return wall_id
示例#5
0
    def test_pop_widest(self):

        wkspc = ar.Workspace(1)
        arngr = ar.Arranger(wkspc)

        returned = arngr.pop_widest()
        self.assertEqual(returned, 7)
        self.assertNotIn(returned, arngr.pics_remaining)

        returned = arngr.pop_widest()
        self.assertEqual(returned, 6)
        self.assertNotIn(returned, arngr.pics_remaining)
示例#6
0
    def test_init(self):

        wkspc = ar.Workspace(11)

        self.assertEqual(wkspc.gallery_id, 11)
        self.assertEqual(wkspc.len, 3)
        self.assertEqual(wkspc.margin, 2)

        self.assertIn(41, wkspc.pics)
        self.assertIn(42, wkspc.pics)
        self.assertIn(49, wkspc.pics)

        # All pics are instance of correct class
        for p in wkspc.pics:
            self.assertTrue(isinstance(wkspc.pics[p], ar.Pic))

        # Correct number of pics
        self.assertEqual(len(wkspc.pics), 3)
示例#7
0
    def test_all_quad(self):

        # Test Gallery (11)
        # 11 | 49, 42, 41
        # 41  |   1   |   4   |   4   |   love_4x4.jpg    |   love    |   @elsabirch  |   public
        # 42  |   1   |   6   |   6   |   banana_6x6.jpg  |   banana  |   @elsabirch  |   public
        # 49  |   1   |   10  |   8   |   wave_10x8.jpg   |   wave    |   @elsabirch  |   public

        wkspc = ar.Workspace(11)
        arngr = ar.Arranger(wkspc)

        wkspc.pics[41].x1 = -4
        wkspc.pics[41].y1 = -4
        wkspc.pics[41].x2 = wkspc.pics[41].x1 + wkspc.pics[41].w
        wkspc.pics[41].y2 = wkspc.pics[41].y1 + wkspc.pics[41].h

        wkspc.pics[42].x1 = 5
        wkspc.pics[42].y1 = -4
        wkspc.pics[42].x2 = wkspc.pics[42].x1 + wkspc.pics[42].w
        wkspc.pics[42].y2 = wkspc.pics[42].y1 + wkspc.pics[42].h

        wkspc.pics[49].x1 = -4
        wkspc.pics[49].y1 = 5
        wkspc.pics[49].x2 = wkspc.pics[49].x1 + wkspc.pics[49].w
        wkspc.pics[49].y2 = wkspc.pics[49].y1 + wkspc.pics[49].h

        arngr.realign_to_origin()

        self.assertEqual(wkspc.pics[41].x1, 0)
        self.assertEqual(wkspc.pics[41].y1, 0)
        self.assertEqual(wkspc.pics[41].x2, 6)
        self.assertEqual(wkspc.pics[41].y2, 6)

        self.assertEqual(wkspc.pics[42].x1, 9)
        self.assertEqual(wkspc.pics[42].y1, 0)
        self.assertEqual(wkspc.pics[42].x2, 17)
        self.assertEqual(wkspc.pics[42].y2, 8)

        self.assertEqual(wkspc.pics[49].x1, 0)
        self.assertEqual(wkspc.pics[49].y1, 9)
        self.assertEqual(wkspc.pics[49].x2, 12)
        self.assertEqual(wkspc.pics[49].y2, 19)
示例#8
0
    def test_pop_narrow(self):

        wkspc = ar.Workspace(1)
        arngr = ar.Arranger(wkspc)

        returned = arngr.pop_narrow()
        self.assertIn(returned, [1, 3])
        self.assertNotIn(returned, arngr.pics_remaining)

        returned = arngr.pop_narrow()
        self.assertIn(returned, [1, 3])
        self.assertNotIn(returned, arngr.pics_remaining)

        returned = arngr.pop_narrow()
        self.assertEqual(returned, 5)
        self.assertNotIn(returned, arngr.pics_remaining)

        returned = arngr.pop_narrow()
        self.assertEqual(returned, 4)
        self.assertNotIn(returned, arngr.pics_remaining)
示例#9
0
    def test_pop_any_n(self):

        # 1|2 | 8 | 10.5 |  |  |  |
        # 2|2 | 12 | 15 |  |  |  |
        # 3|2 | 7.5 | 9.5 |  |  |  |
        # 4|2 | 11 | 14 |  |  |  |
        # 5|2 | 8.5 | 6.5 |  |  |  |
        # 6|2 | 15 | 11 |  |  |  |
        # 7|2 | 19.5 | 16.5 |  |  |  |
        # 8|2 | 13 | 15.5 |  |  |  |

        for n in range(8):

            wkspc = ar.Workspace(1)
            arngr = ar.Arranger(wkspc)

            returned = arngr.pop_any_n(n)

            self.assertEqual(len(returned), n)

            for x in returned:
                self.assertIn(x, range(1, 9))
                self.assertNotIn(x, arngr.pics_remaining)