Esempio n. 1
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')
Esempio n. 2
0
 def _do_contact(self):
     name = request.POST.get('name')
     email = request.POST.get('email')
     message = request.POST.get('message')
     self._send_message(name, email, message)
     h.flash(u'Thank you for contacting us')
     redirect_to(h.url_for('home'))
Esempio n. 3
0
 def login(self):
     c.no_maps = True
     c.active_section = request.params.get('show','login-new')
     c.captcha_html = h.literal(recaptcha.client.captcha.displayhtml(
               g.captcha_pubkey))
     if request.environ.get('repoze.who.identity') == None:
         return render('/user/login.mako')
     redirect(request.params.get('came_from', h.url_for('home')))
Esempio n. 4
0
 def edit_form_map(self, media_id):
     c.media_item = c.map = h.get_media_by_id(media_id)
     geometry = c.map.location_4326.__geo_interface__
     c.view_url = h.url_for('media_map_view', media_id=c.media_item.id)
     c.legend = u'Map'
     return dict(html=render('/media/map/form.mako'),
                 map_id='pagemedia_%d' % c.map.id,
                 geometry=geometry,
                 )
Esempio n. 5
0
 def register(self):
     c.no_maps = True
     if request.environ.get('repoze.who.identity') == None:
         c.active_section = request.params.get('show','login-new')
         c.captcha_html = h.literal(recaptcha.client.captcha.displayhtml(
                   g.captcha_pubkey))
         return render('/user/login.mako')
     h.flash(u'Can\'t register while logged in.  Please logout first.')
     redirect_to(h.url_for('home'))
Esempio n. 6
0
 def edit_form_text(self, media_id):
     c.media_item = h.get_media_by_id(media_id)
     c.view_url = h.url_for('media_story_view', media_id=c.media_item.id)
     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,
                 )
Esempio n. 7
0
 def edit_form_image(self, media_id):
     c.media_item = c.image = h.get_media_by_id(media_id)
     c.file_id = str(uuid.uuid4())
     c.file_upload_url = request.path_url
     c.view_url = h.url_for('media_image_view', media_id=c.media_item.id)
     c.legend = u'Image'
     return dict(html=render('/media/image/form.mako'),
                 file_id=c.file_id,
                 file_upload_url=c.file_upload_url,
                 )
Esempio n. 8
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))
Esempio n. 9
0
 def edit_form_pdf(self, media_id):
     c.media_item = c.pdf = h.get_media_by_id(media_id)
     c.file_id = str(uuid.uuid4())
     c.file_upload_url = request.path_url
     c.view_url = h.url_for('media_pdf_view', media_id=c.media_item.id)
     c.legend = u'PDF'
     return dict(html=render('/media/pdf/form.mako'),
                 file_id=c.file_id,
                 file_upload_url=c.file_upload_url,
                 )
Esempio n. 10
0
    def _request_reset(self):
        login = self.form_result['login']
        try:
            user = meta.Session.query(FullUser).filter(or_(FullUser.username==login, FullUser.email_address==login)).one()
        except (orm.exc.NoResultFound, orm.exc.MultipleResultsFound):
            h.flash("Unable to find the username or email supplied.")
            redirect_to(h.url_for('home'))
        user.generate_key()
        meta.Session.commit()

        c.username = user.username
        c.key = user.reset_key

        message = mailer.Message()
        message.From = "Community Alamanc <noreply@%s>" % "communityalmanac.org"
        message.To = user.email_address
        message.Subject = "Community Almanac account details"
        message.Body, message.Html = self._email_strip(render('/email/account_details.mako'), message)
        server = mailer.Mailer(config['smtp_server'])
        server.send(message)

        h.flash(u'A password reset has been sent. Please check your email.')
        redirect_to(h.url_for('home'))
Esempio n. 11
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))
Esempio n. 12
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))
Esempio n. 13
0
 def edit_form_audio(self, media_id):
     c.media_item = c.audio = h.get_media_by_id(media_id)
     c.file_id = str(uuid.uuid4())
     c.file_upload_url = request.path_url
     c.flowplayer_id = 'pagemedia_%s' % c.media_item.id
     c.audio_url = request.application_url + c.audio.url
     c.view_url = h.url_for('media_audio_view', media_id=c.media_item.id)
     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,
                 flowplayer_id=c.flowplayer_id,
                 audio_url=c.audio_url,
                 )
Esempio n. 14
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))
Esempio n. 15
0
 def _search(self, almanac_slug, query=''):
     redirect_to(h.url_for('almanac_search', almanac_slug=almanac_slug, query=request.params.get('query','')))
Esempio n. 16
0
 def logout(self):
     # The logout/forget process is handled by repoze.who.
     redirect_to(h.url_for('home'))
Esempio n. 17
0
 def _all_pages(self, query=''):
     redirect_to(h.url_for('site_search', query=request.params.get('query','')))
Esempio n. 18
0
 def edit_form_video(self, media_id):
     c.media_item = h.get_media_by_id(media_id)
     c.view_url = h.url_for('media_video_view', media_id=c.media_item.id)
     c.legend = u'Video'
     return dict(html=render('/media/video/form.mako'))
Esempio n. 19
0
 def create(self):
     redirect_to(h.url_for('home'))
Esempio n. 20
0
 def url(self):
     import communityalmanac.lib.helpers as h
     return h.url_for('view_media_audio', media=self)
Esempio n. 21
0
    def _perform_reset(self, username, key):
        myparams = dict(request.params)
        myparams['username'] = username
        myparams['key'] = key
        schema = PerformResetSchema()
        try:
            form_result = schema.to_python(myparams)
        except validators.Invalid, error:
            c.form_result = error.value
            c.form_errors = error.error_dict or {}
            return render('/user/perform_reset.mako')
        password = form_result['password']
        try:
            user = meta.Session.query(FullUser).filter(and_(FullUser.username==username, FullUser.reset_key==key)).one()
        except (orm.exc.NoResultFound, orm.exc.MultipleResultsFound):
            h.flash("Invalid reset key.")
            redirect_to(h.url_for('home'))
        user.reset_key = None
        if password:
            user.set_password(password)
        meta.Session.commit()
        self._login(username)

        h.flash(u'Your password has been reset')
        redirect_to(h.url_for('home'))

    def test(self):
        if request.environ.get('repoze.who.identity') == None:
            abort(401)
        return 'Success'