예제 #1
0
 def pages_kml_link(self, almanac_slug, query):
     almanac = h.get_almanac_by_slug(almanac_slug)
     c.query = query
     c.name = almanac.name
     c.slug = almanac_slug
     response.content_type = 'application/vnd.google-earth.kml+xml kml'
     return render('/page/kml_link.mako')
예제 #2
0
    def _do_new_form_map(self, almanac_slug, page_slug=None):
        c.almanac = h.get_almanac_by_slug(almanac_slug)
        page = self._retrieve_page(c.almanac, page_slug)
        json = request.POST.get('feature')
        if json is None:
            abort(400)
        shape = simplejson.loads(json)
        # Stupid asShape returns a PointAdapter instead of a Point.  We round
        # trip it through wkb to get the correct type.
        location = wkb.loads(asShape(shape).to_wkb())
        location.srid = 4326

        c.map = map = Map()
        map.location = location
        map.page_id = page.id
        map.order = len(page.media)
        meta.Session.add(map)
        meta.Session.commit()

        geometry = c.map.location_4326.__geo_interface__

        c.editable = True
        return dict(html=render('/media/map/item.mako'),
                    map_id='pagemedia_%d' % map.id,
                    geometry=geometry,
                    )
예제 #3
0
 def sort(self, almanac_slug, page_slug):
     almanac = h.get_almanac_by_slug(almanac_slug)
     if page_slug:
         page = h.get_page_by_slug(almanac, page_slug)
     else:
         page = almanac.new_page(self.ensure_user)
     return self._sort(page)
예제 #4
0
    def view(self, almanac_slug):
        c.almanac = h.get_almanac_by_slug(almanac_slug)
        loc = c.almanac.location_4326
        c.lng, c.lat = loc.x, loc.y

        page_idx = request.GET.get('page', 1)
        try:
            page_idx = int(page_idx)
        except ValueError:
            page_idx = 1

        pages_query = meta.Session.query(Page).filter(Page.almanac_id==c.almanac.id).filter(Page.published == True).order_by(Page.modified.desc())
        try:
            c.next_page = pages_query[:1][0]
        except IndexError:
            pass
        else:
            c.next_page_url = h.url_for('page_view', almanac=c.almanac, page=c.next_page)
            c.next_page_text = c.next_page.name

        per_page = 10
        pagination = PaginationPage(pages_query, page=page_idx, items_per_page=per_page)
        c.toc_pagination_data = h.pagination_data(pagination)
        c.pages = pagination.items
        c.npages = pagination.item_count
        return render('/almanac/view.mako')
예제 #5
0
 def pages_kml(self, almanac_slug, query):
     c.almanac = h.get_almanac_by_slug(almanac_slug)
     if query:
         c.pages = c.almanac.search(query).all()
     else:
         c.pages = c.almanac.pages
     response.content_type = 'application/vnd.google-earth.kml+xml kml'
     return render('/page/kml.mako')
예제 #6
0
 def _do_edit(self, almanac_slug, page_slug):
     c.almanac = h.get_almanac_by_slug(almanac_slug)
     c.page = h.get_page_by_slug(c.almanac, page_slug)
     name = request.POST.get('name', u'')
     if name:
         # all we have to save is the name here for now
         c.page.name = name
         meta.Session.commit()
     h.flash(u'Page edited')
     redirect_to(h.url_for('page_view', almanac=c.almanac, page=c.page))
예제 #7
0
 def new_form_text(self, almanac_slug, page_slug=None):
     c.almanac = h.get_almanac_by_slug(almanac_slug)
     page = self._retrieve_page(c.almanac, page_slug)
     c.legend = u'Text'
     new_uuid = str(uuid.uuid4())
     c.textarea_id = 'mceSimple_%s' % new_uuid
     return dict(html=render('/media/story/form.mako'),
                 storyinput_id=c.storyinput_id,
                 textarea_id=c.textarea_id,
                 )
예제 #8
0
 def new_form_map(self, almanac_slug, page_slug=None):
     c.almanac = h.get_almanac_by_slug(almanac_slug)
     page = self._retrieve_page(c.almanac, page_slug)
     loc = c.almanac.location_4326
     c.map_id = str(uuid.uuid4())
     c.legend = u'Map'
     return dict(html=render('/media/map/form.mako'),
                 lat=loc.y, lng=loc.x,
                 map_id=c.map_id,
                 )
예제 #9
0
 def new_form_audio(self, almanac_slug, page_slug=None):
     c.almanac = h.get_almanac_by_slug(almanac_slug)
     page = self._retrieve_page(c.almanac, page_slug)
     c.file_id = str(uuid.uuid4())
     c.file_upload_url = request.path_url
     c.legend = u'MP3 Audio'
     return dict(html=render('/media/audio/form.mako'),
                 file_id=c.file_id,
                 file_upload_url=c.file_upload_url,
                 )
예제 #10
0
 def pages_atom(self, almanac_slug, query):
     c.almanac = h.get_almanac_by_slug(almanac_slug)
     if query:
         c.pages = c.almanac.search(query).all()
     else:
         c.pages = c.almanac.pages
     c.query = query
     c.name = c.almanac.name
     c.slug = almanac_slug
     response.content_type = 'application/atom+xml'
     return render('/page/atom.mako')
예제 #11
0
 def edit(self, almanac_slug, page_slug):
     c.almanac = h.get_almanac_by_slug(almanac_slug)
     c.page = h.get_page_by_slug(c.almanac, page_slug)
     c.media_items = h.render_media_items(c.page.media, editable=True)
     map_features = h.map_features_for_media(c.page.media)
     c.map_features = h.literal(simplejson.dumps(map_features))
     flow_data = h.flowplayer_data_for_media(c.page.media)
     c.flow_data = h.literal(simplejson.dumps(flow_data))
     c.is_add = False
     c.behalf = render('/page/behalf.mako')
     return render('/page/add_edit.mako')
예제 #12
0
 def create(self, almanac_slug):
     c.almanac = h.get_almanac_by_slug(almanac_slug)
     c.page = page = c.almanac.new_page(self.ensure_user)
     media_items = page.media
     c.media_items = h.render_media_items(media_items, editable=True)
     map_features = h.map_features_for_media(media_items)
     c.map_features = h.literal(simplejson.dumps(map_features))
     flow_data = h.flowplayer_data_for_media(media_items)
     c.flow_data = h.literal(simplejson.dumps(flow_data))
     c.is_add = True
     c.behalf = render('/page/behalf.mako')
     return render('/page/add_edit.mako')
예제 #13
0
    def _do_comment(self, almanac_slug, page_slug):
        almanac = h.get_almanac_by_slug(almanac_slug)
        page = h.get_page_by_slug(almanac, page_slug)

        comment = Comment(fullname=self.form_result['fullname'],
                          email=self.form_result['email'],
                          website=self.form_result['website'],
                          text=self.form_result['text'],
                          )
        comment.page_id = page.id
        meta.Session.add(comment)
        meta.Session.commit()
        h.flash(u'Comment added')
        redirect_to(h.url_for('page_view', almanac=almanac, page=page))
예제 #14
0
    def _do_publish(self, almanac_slug):
        c.almanac = almanac = h.get_almanac_by_slug(almanac_slug)
        name = request.POST.get('name', u'')
        if not name:
            name = u'Unnamed'

        slug = Page.name_page(almanac, name)
        page = c.almanac.new_page(self.ensure_user, name=name, slug=slug)
        page.published = True

        meta.Session.commit()

        h.flash(u'Page created')
        redirect_to(h.url_for('page_view', almanac=almanac, page=page))
예제 #15
0
    def _do_new_form_image(self, almanac_slug, page_slug=None):
        c.almanac = h.get_almanac_by_slug(almanac_slug)
        image_file = request.POST.get('userfile')
        if image_file is None:
            c.error = u'No file uploaded'
            response.content_type = 'application/javascript'
            return simplejson.dumps(dict(html=render('/media/error.mako')))

        page = self._retrieve_page(c.almanac, page_slug)

        try:
            c.image = image = Image.from_file(image_file.filename, page, upload=image_file)
        except (ValueError, IOError), e:
            c.error = str(e.message) or str(e)
            response.content_type = 'application/javascript'
            return simplejson.dumps(dict(html=render('/media/error.mako')))
예제 #16
0
    def _do_new_form_video(self, almanac_slug, page_slug=None):
        c.almanac = h.get_almanac_by_slug(almanac_slug)
        body = request.POST.get('body', u'')
        if not body:
            abort(400)

        page = self._retrieve_page(c.almanac, page_slug)

        c.video = video = Video()
        video.text = h.clean_embed_markup(body)
        video.page_id = page.id
        video.order = len(page.media)
        meta.Session.add(video)
        meta.Session.commit()

        c.editable = True
        return dict(html=render('/media/video/item.mako'))
예제 #17
0
    def _do_new_form_audio(self, almanac_slug, page_slug=None):
        c.almanac = h.get_almanac_by_slug(almanac_slug)
        audio_file = request.POST.get('userfile')
        if audio_file is None:
            c.error = u'No file uploaded'
            response.content_type = 'application/javascript'
            return simplejson.dumps(dict(html=render('/media/error.mako')))

        filename = audio_file.filename
        mimetype, _ = mimetypes.guess_type(filename)
        if mimetype != 'audio/mpeg':
            c.error = u'Invalid audio file. You must upload an mp3 file'
            response.content_type = 'application/javascript'
            return simplejson.dumps(dict(html=render('/media/error.mako')))

        page = self._retrieve_page(c.almanac, page_slug)

        audio_file.make_file()
        audio_data = audio_file.file.read()
        new_uuid = str(uuid.uuid4())
        fname = '%s.mp3' % new_uuid
        path = os.path.join(g.audio_path, fname)
        f = open(path, 'w')
        f.write(audio_data)
        f.close()

        c.audio = audio = Audio()
        audio.path = path
        audio.page_id = page.id
        audio.order = len(page.media)
        audio.filename = filename
        meta.Session.add(audio)
        meta.Session.commit()

        c.editable = True
        c.flowplayer_id = 'pagemedia_%s' % c.audio.id
        c.audio_url = request.application_url + c.audio.url
        response.content_type = 'application/javascript'
        return simplejson.dumps(dict(html=render('/media/audio/item.mako'),
                                     flowplayer_id=c.flowplayer_id,
                                     audio_url=c.audio_url,
                                     ))
예제 #18
0
    def search(self, almanac_slug, query):
        c.almanac = h.get_almanac_by_slug(almanac_slug)
        loc = c.almanac.location_4326
        c.lng, c.lat = loc.x, loc.y
        page_idx = request.GET.get('page', 1)
        try:
            page_idx = int(page_idx)
        except ValueError:
            page_idx = 1
        per_page = 10
        pagination = PaginationPage(c.almanac.search(query), page=page_idx, items_per_page=per_page)
        c.pagination_data = h.pagination_data(pagination)
        c.pages = pagination.items
        c.npages = pagination.item_count
        c.query = query

        # latest pages for sidebar
        c.latest_pages = Page.latest(limit=10, almanac_id=c.almanac.id)

        return render('/almanac/search.mako')
예제 #19
0
    def _do_new_form_text(self, almanac_slug, page_slug=None):
        c.almanac = h.get_almanac_by_slug(almanac_slug)
        page = self._retrieve_page(c.almanac, page_slug)
        for key in request.POST.keys():
            if key.startswith('mceSimple'):
                body = request.POST.get(key, u'')
                break
        if not body:
            abort(400)

        cleaned = h.clean_html(body)
        # Hack in akismet validation, although we don't have a FormEncode
        # form here.
        from communityalmanac.lib.validators import AkismetValidator
        akismet = AkismetValidator()
        from formencode.validators import Invalid
        user = self.ensure_user
        assert hasattr(user, 'username')
        field_dict = {'fullname': user.username,
                      'website': u'',
                      'email': user.email_address or u'',
                      'text': cleaned}
        try:
            akismet.validate_python(field_dict, state={})
            log.info("akismet says story is OK")
        except Invalid:
            # Not sure what else we can do here.
            abort(400)

        c.story = story = Story()
        story.text = cleaned
        story.page_id = page.id
        story.order = len(page.media)
        meta.Session.add(story)
        meta.Session.commit()

        c.editable = True
        return dict(html=render('/media/story/item.mako'))
예제 #20
0
    def evaluate(self, environ, credentials):

        user = c.user
        if not user:
            userid = session.setdefault('userid', None)
            if not userid:
                self.unmet()
            user = meta.Session.query(User).get(userid)
            if not user:
                self.unmet()

        almanac_slug = environ['pylons.routes_dict']['almanac_slug']
        page_slug = environ['pylons.routes_dict']['page_slug']

        almanac = h.get_almanac_by_slug(almanac_slug)
        page = h.get_page_by_slug(almanac, page_slug)

        if page.user_id == user.id:
            return
        if credentials and \
           'manage' in credentials.get('permissions'):
            return
        self.unmet()
예제 #21
0
    def view(self, almanac_slug, page_slug):
        c.almanac = h.get_almanac_by_slug(almanac_slug)
        c.page = h.get_page_by_slug(c.almanac, page_slug)
        c.media_items = h.render_media_items(c.page.media, editable=False)
        c.no_maps = True
        for media in c.page.media:
            if isinstance(media, Map):
                c.no_maps = False
                break
        map_features = h.map_features_for_media(c.page.media)
        c.map_features = h.literal(simplejson.dumps(map_features))
        flow_data = h.flowplayer_data_for_media(c.page.media)
        c.flow_data = h.literal(simplejson.dumps(flow_data))

        page_navigation = c.page.page_navigation()
        c.next_page = page_navigation['next']
        c.prev_page = page_navigation['prev']
        c.latest_pages = Page.latest(almanac_id=c.almanac.id)
        if g.captcha_enabled and not c.user:
            c.captcha_html = h.literal(recaptcha.client.captcha.displayhtml(g.captcha_pubkey))
        c.is_page_owner = is_met(is_page_owner())
        c.is_admin = is_met(has_permission('manage'))
        return render('/page/view.mako')
예제 #22
0
    def _do_new_form_pdf(self, almanac_slug, page_slug=None):
        c.almanac = h.get_almanac_by_slug(almanac_slug)
        pdf_file = request.POST.get('userfile')
        if pdf_file is None:
            c.error = u'No file uploaded'
            response.content_type = 'application/javascript'
            return simplejson.dumps(dict(html=render('/media/error.mako')))

        filename = pdf_file.filename
        mimetype, _ = mimetypes.guess_type(filename)
        if mimetype != 'application/pdf':
            c.error = u'Invalid pdf file'
            response.content_type = 'application/javascript'
            return simplejson.dumps(dict(html=render('/media/error.mako')))

        page = self._retrieve_page(c.almanac, page_slug)

        pdf_file.make_file()
        pdf_data = pdf_file.file.read()
        new_uuid = str(uuid.uuid4())
        path = os.path.join(g.pdfs_path, new_uuid) + '.pdf'
        f = open(path, 'w')
        f.write(pdf_data)
        f.close()

        c.pdf = pdf = PDF()
        pdf.path = path
        pdf.page_id = page.id
        pdf.order = len(page.media)
        pdf.filename = filename
        meta.Session.add(pdf)
        meta.Session.commit()

        c.editable = True
        response.content_type = 'application/javascript'
        return simplejson.dumps(dict(html=render('/media/pdf/item.mako')))
예제 #23
0
 def new_form_video(self, almanac_slug, page_slug=None):
     c.almanac = h.get_almanac_by_slug(almanac_slug)
     page = self._retrieve_page(c.almanac, page_slug)
     c.legend = u'Video'
     return dict(html=render('/media/video/form.mako'))
예제 #24
0
 def center(self, almanac_slug):
     c.almanac = h.get_almanac_by_slug(almanac_slug)
     loc = c.almanac.location
     return dict(lat=loc.x, lng=loc.y)