예제 #1
0
파일: controllers.py 프로젝트: ccnmtl/maap
    def mbl_index(self):
        all_places = list(Place.select())

        # hard-code the removal of 2 places that aren't ready for the mobile page
        places = [p for p in all_places if (p.name != "lattings" and p.name != "setauket")]

        # compute the number of places in each region for mobile view
        region_counts = {}
        region_counts["all"] = len(places)
        for r in regions_short:
            region_counts[r] = Place.selectBy(region=r).count()

        return dict(places=places, region_counts=region_counts)
예제 #2
0
파일: controllers.py 프로젝트: ccnmtl/maap
    def default(self, place_id, **kwargs):
        place = Place.get(int(place_id))
        # cdata_description = "<blah><![CDATA[" + place.description + "]]></blah>",

        return dict(
            places=list(Place.select()),
            place=place,
            cdata_body="<![CDATA[" + place.body + "]]>",
            patch=place.patch,
            featured_image=place.featured_image,
            featured_video=place.featured_video,
            then_image=place.then_image,
            now_image=place.now_image,
            images=list(place.images),
            videos=list(place.videos),
            related_lessons=list(place.lessons),
        )
예제 #3
0
파일: controllers.py 프로젝트: ccnmtl/maap
 def json(self, callback=True, **kw):
     places = [
         dict(id=p.id, latitude=p.latitude, longitude=p.longitude, title=p.title, color=p.color)
         for p in Place.select()
     ]
     rv = dict(places=places)
     if callback:
         return "loadPlaces(%s)" % serializeJSON(rv)
     else:
         return rv
예제 #4
0
파일: controllers.py 프로젝트: ccnmtl/maap
 def mbl_place(self, place_id, **kwargs):
     try:
         places = Place.selectBy(id=int(place_id))
         if places.count() == 0:
             place = ""
         else:
             place = places[0]
         print "I made it"
     except:
         print "Uh oh"
         raise Exception("help")
     return dict(place=place)
예제 #5
0
파일: controllers.py 프로젝트: ccnmtl/maap
def get_image_options():
    """
	returns options to featured/now/then selection on place admin form 
	"""
    resource, action = request.path.split(";")
    if action == "add_form":
        return [(0, "None")]
    parts = resource.split("/")
    place_id = parts[-2]  # this is (hopefully, my place id)
    place = Place.selectBy(id=int(place_id))
    if place.count() == 0:
        return [(0, "None")]
    else:
        place = place[0]
        return [(0, "None")] + [(image.id, image.name) for image in list(place.images)]
예제 #6
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)
예제 #7
0
파일: controllers.py 프로젝트: ccnmtl/maap
def get_video_options():
    """
	returns options to featured/now/then selection on place admin form 
	"""
    # this is a miserable hack, but the widgets don't pass parameters
    # at render-time, so here I am, figuring out what place I am at from
    # the url
    # also, no convinience methods to discect the url easily
    resource, action = request.path.split(";")
    if action == "add_form":
        return [(0, "None")]
    parts = resource.split("/")
    place_id = parts[-2]  # this is (hopefully, my place id)
    place = Place.selectBy(id=int(place_id))
    if place.count() == 0:
        return [(0, "None")]
    else:
        place = place[0]
        return [(0, "None")] + [(video.id, video.name) for video in list(place.videos)]
예제 #8
0
파일: controllers.py 프로젝트: ccnmtl/maap
    def welcome_places(self, callback=True, **kw):
        FEATURED_PLACE_NAMES = (
            "pierre_toussaint",
            "abyssinian_baptist_church",
            "african_grove_theater",
            "duke_ellington",
            "five_points",
            "fort_amsterdam",
            "harlem",
            "studio_museum",
            "the_african_burial_ground",
            "the_audubon_ballroom",
        )
        featured_places = [Place.selectBy(name=p)[0] for p in FEATURED_PLACE_NAMES]

        places = dict(
            [
                (
                    index,
                    dict(
                        name=p.name,
                        id=p.id,
                        title=p.title,
                        then_text=p.then_text,
                        then_image_id=p.then_image.id,
                        then_image_thumb_url=p.then_image.thennow_url,
                    ),
                )
                for index, p in enumerate(featured_places)
            ]
        )
        rv = dict(places=places)
        if callback:
            return "loadFeaturedPlaces(%s)" % serializeJSON(rv)
        else:
            return rv
예제 #9
0
파일: controllers.py 프로젝트: ccnmtl/maap
 def full_export_mt(self):
     places = list(Place.select())
     return dict(places=places)
예제 #10
0
파일: controllers.py 프로젝트: ccnmtl/maap
 def index(self, order_by="Place.q.name", **kw):
     places = list(Place.select())
     return dict(places=places)
예제 #11
0
파일: controllers.py 프로젝트: ccnmtl/maap
 def list(self, **kw):
     # return self.search(**kw)
     places = list(Place.select())
     return dict(places=places)
예제 #12
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'