Ejemplo n.º 1
0
    def _do_create(self):
        name = self.form_result['name']

        # Prevent creation of duplicates
        try:
            almanac = meta.Session.query(Almanac).filter(Almanac.name==name).one()
            return redirect_to(h.url_for('page_create', almanac_slug=almanac.slug))
        except exc.NoResultFound:
            pass

        json = self.form_result['almanac_center']
        shape = simplejson.loads(json)
        # We've requested a LonLat from OpenLayers, so it gives us a point in
        # Plate Carree (4326)
        point = asShape(shape)
        point.srid = 4326
        slug = Almanac.name_almanac(name)
        almanac = Almanac(name, slug)
        almanac.location = point

        meta.Session.save(almanac)
        meta.Session.commit()

        redirect_to(h.url_for('page_create', almanac_slug=slug))
Ejemplo n.º 2
0
def get_almanac_by_slug(almanac_slug):
    try:
        return Almanac.get_by_slug(almanac_slug)
    except exc.NoResultFound:
        abort(404)