예제 #1
0
파일: controllers.py 프로젝트: ccnmtl/maap
    def maap_library(self, type="images", **kw):
        class Asset:
            def __init__(self, asset_type=None, record=None, thumb_url=None, view_url=None):
                self.asset_type = asset_type
                self.record = record
                self.name = record.name
                self.thumb_url = thumb_url
                self.view_url = view_url

            def __cmp__(self, other):
                return cmp(self.name, other.name)

        if type == "maps":
            maps = MapAsset.selectBy()
            assets = [
                Asset(asset_type="map", record=m, thumb_url=m.smallthumb_url, view_url="/place/then#map=%s" % m.name)
                for m in maps
            ]
        elif type == "videos":
            videos = VideoAsset.selectBy()
            assets = [
                Asset(asset_type="video", record=v, thumb_url=v.tiny_url, view_url="/video/view/%s" % v.id)
                for v in videos
            ]
        else:
            images = ImageAsset.selectBy()
            assets = [
                Asset(asset_type="image", record=i, thumb_url=i.thumb_url, view_url="/image/view/%s" % i.id)
                for i in images
            ]

        assets.sort()
        return dict(assets=assets, type=type)
예제 #2
0
파일: controllers.py 프로젝트: ccnmtl/maap
    def maps(self, callback=True, **kw):

        maps = dict(
            [
                (
                    m.name,
                    dict(
                        name=m.name,
                        id=m.id,
                        title=m.title,
                        publisher=m.publisher,
                        date=m.date.isoformat(),
                        year=m.year,
                        thumb_url=m.thumb_url,
                        images=dict(
                            preview=m.src_url,
                            thumb=m.thumb_url,
                            smallthumb=m.smallthumb_url,
                            bigthumb=m.bigthumb_url,
                            big=m.big_url,
                            gigantic=m.gigantic_url,
                        ),
                    ),
                )
                for m in MapAsset.select()
            ]
        )
        # we don't need patches at this moment.  maybe later?
        patches = []  # json.jsonify_sqlobject(mp) for mp in MapPatch.select()]
        rv = dict(maps=maps, patches=patches)
        if callback:
            return "loadMaps(%s)" % serializeJSON(rv)
        else:
            return rv
예제 #3
0
파일: controllers.py 프로젝트: ccnmtl/maap
 def initfields(self, action, field_dict):
     field_dict["parent_mapID"] = SingleSelectField(
         name="parent_mapID",
         label="Map",
         options=[(map.id, map.name) for map in MapAsset.select()],
         validator=validators.Any(validators.Int(), validators.Empty()),
     )
     return field_dict
예제 #4
0
파일: controllers.py 프로젝트: ccnmtl/maap
    def then(self, **kw):
        """What do we need?
		   places: to list them on the right
		   patches: to annotate them on the map
		   maps: to switch between them
		"""
        places = list(Place.select())
        maps = list(MapAsset.select())
        maps = sorted(maps, key=lambda x: x.year)
        map_vert = []
        for i, m in enumerate(maps):
            if i != 0 and m.yearpos - maps[i - 1].yearpos < 5 and map_vert[i - 1] < 4:
                map_vert.append(map_vert[i - 1] + 1)
            else:
                map_vert.append(1)
        return dict(places=places, maps=maps, map_vert=map_vert)
예제 #5
0
파일: controllers.py 프로젝트: ccnmtl/maap
 def default(self, map_id, **kwargs):
     try:
         map = list(MapAsset.selectBy(id=map_id))[0]
     except:
         map = None
     return dict(image=map)
예제 #6
0
파일: controllers.py 프로젝트: ccnmtl/maap
 def get_edit_form(self, table, **kw):
     kw["maps"] = list(MapAsset.select())
     return self.crud.edit_form(self, table, **kw)
예제 #7
0
파일: controllers.py 프로젝트: ccnmtl/maap
 def list(self, **kw):
     # return self.search(**kw)
     maps = list(MapAsset.select())
     return dict(maps=maps)
예제 #8
0
파일: test_model.py 프로젝트: ccnmtl/maap
    def test_relations(self):
        import test_content
        # places = Place.select()

        # test places
        columbia = Place.selectBy(name="columbia")[0]
        assert columbia.name == "columbia"

        lalo = Place.selectBy(name="lalo")[0]
        assert lalo.name == "lalo"


        home = Place.selectBy(name="home")[0]
        assert home.name == "home"

        # map assets and their patches
        maps = MapAsset.select()
        oldmap1 = maps[0]
        # print oldmap1
        patches = oldmap1.patches
        #print patches
        assert patches[0].name == "Columbia Patch"
        
        assert columbia.patch.name == "Columbia Patch"
        
        # images associated with places 
        c_images = columbia.images
        assert c_images[0].name == "butler_a"
        assert c_images[1].name == "butler_b"

        l_images = lalo.images
        assert l_images[0].name == "lalo_a"
        assert l_images[1].name == "lalo_b"
        

        # images associated with places 
        c_videos = columbia.videos
        assert c_videos[0].name == "columbia_video_a"
        assert c_videos[1].name == "columbia_video_b"

        l_videos = lalo.videos
        assert l_videos[0].name == "lalo_video_a"
        assert l_videos[1].name == "lalo_video_b"


        # associated lessons
        c_lessons = list(columbia.lessons)
        assert len(c_lessons) == 1

        c_lessons[0].name == "lesson1a"

        lesson1a = Lesson.selectBy(name="lesson1a")[0]
        l1_places = list(lesson1a.places)
        assert len(l1_places) == 1
        l1_places[0].name == "columbia"
        
        module1 = Module.selectBy(name='module1')[0]
        assert module1.name == "module1"

        lessons = module1.lessons
        lesson1a = lessons[0]
        assert lesson1a.name == "lesson1a"
        assert lesson1a.module.name == "module1"

        # test some date arithmetic
        assert columbia.getMarkerColor() == 'orange'
        assert lalo.getMarkerColor() == 'pink'
        assert home.getMarkerColor() == 'darkgreen'