def _do_edit_form_pdf(self, media_id): c.pdf = h.get_media_by_id(media_id) 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'))) pdf_file.make_file() pdf_data = pdf_file.file.read() f = open(c.pdf.path, 'w') f.write(pdf_data) f.close() c.pdf.filename = filename meta.Session.commit() c.editable = True response.content_type = 'application/javascript' return simplejson.dumps(dict(html=render('/media/pdf/item.mako')))
def _do_edit_form_image(self, media_id): c.image = h.get_media_by_id(media_id) 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'))) filename = image_file.filename mimetype, _ = mimetypes.guess_type(filename) if not mimetype.startswith('image/'): c.error = u'Invalid image file' response.content_type = 'application/javascript' return simplejson.dumps(dict(html=render('/media/error.mako'))) image_file.make_file() image_data = image_file.file.read() f = open(c.image.path, 'w') f.write(image_data) f.close() c.image.create_scales(g.images_path) c.image.filename = filename meta.Session.commit() c.editable = True response.content_type = 'application/javascript' return simplejson.dumps(dict(html=render('/media/image/item.mako')))
def _do_edit_form_audio(self, media_id): c.audio = h.get_media_by_id(media_id) 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'))) audio_file.make_file() audio_data = audio_file.file.read() f = open(c.audio.path, 'w') f.write(audio_data) f.close() c.audio.filename = filename 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, ))
def map_view(self, media_id): c.editable = True c.map = h.get_media_by_id(media_id) geometry = c.map.location_4326.__geo_interface__ return dict(html=render('/media/map/item.mako'), map_id='pagemedia_%d' % c.map.id, geometry=geometry, )
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, )
def audio_view(self, media_id): c.editable = True c.audio = h.get_media_by_id(media_id) c.flowplayer_id = 'pagemedia_%s' % c.audio.id c.audio_url = request.application_url + c.audio.url return dict(html=render('/media/audio/item.mako'), flowplayer_id=c.flowplayer_id, audio_url=c.audio_url, )
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, )
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, )
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, )
def _do_edit_form_video(self, media_id): c.video = h.get_media_by_id(media_id) body = request.POST.get('body', u'') if not body: abort(400) c.video.text = h.clean_embed_markup(body) meta.Session.commit() c.editable = True return dict(html=render('/media/video/item.mako'))
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, )
def _do_edit_form_text(self, media_id): c.story = h.get_media_by_id(media_id) 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) c.story.text = cleaned meta.Session.commit() c.editable = True return dict(html=render('/media/story/item.mako'))
def _do_edit_form_map(self, media_id): c.map = h.get_media_by_id(media_id) 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.location = location meta.Session.commit() c.editable = True return dict(html=render('/media/map/item.mako'), map_id='pagemedia_%d' % c.map.order, geometry=json, )
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() media_id = environ['pylons.routes_dict']['media_id'] media = h.get_media_by_id(media_id) if media.page.user_id == user.id: return if credentials and \ 'manage' in credentials.get('permissions'): return self.unmet()
def view_pdf(self, media_id, filename): pdf = h.get_media_by_id(media_id) return self._view_media(pdf.path)
def view_image(self, media_id, filename): image = h.get_media_by_id(media_id) return self._view_media(image.path)
def view_audio(self, media_id, filename): audio = h.get_media_by_id(media_id) return self._view_media(audio.path)
def video_view(self, media_id): c.editable = True c.video = h.get_media_by_id(media_id) return dict(html=render('/media/video/item.mako'))
def delete_video(self, media_id): video = h.get_media_by_id(media_id) meta.Session.delete(video) meta.Session.commit()
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'))
def text_view(self, media_id): c.editable = True c.story = h.get_media_by_id(media_id) return dict(html=render('/media/story/item.mako'))
def delete_text(self, media_id): story = h.get_media_by_id(media_id) meta.Session.delete(story) meta.Session.commit()
def delete_audio(self, media_id): audio = h.get_media_by_id(media_id) audio._remove_media_path(audio.path) meta.Session.delete(audio) meta.Session.commit()
def delete_map(self, media_id): map = h.get_media_by_id(media_id) meta.Session.delete(map) meta.Session.commit()
def image_view(self, media_id): c.editable = True c.image = h.get_media_by_id(media_id) return dict(html=render('/media/image/item.mako'))
def delete_pdf(self, media_id): pdf = h.get_media_by_id(media_id) pdf._remove_media_path(pdf.path) meta.Session.delete(pdf) meta.Session.commit()
def pdf_view(self, media_id): c.editable = True c.pdf = h.get_media_by_id(media_id) return dict(html=render('/media/pdf/item.mako'))
def delete_image(self, media_id): image = h.get_media_by_id(media_id) image._remove_all_scales() meta.Session.delete(image) meta.Session.commit()