Example #1
0
 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)
Example #2
0
    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)
Example #3
0
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)]
Example #4
0
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)]
Example #5
0
    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
Example #6
0
    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'