def channel_edit(channel): form = ChannelForm(obj=channel) if channel.userid == g.user.userid: form.type.choices = [(1, CHANNEL_TYPE[1])] else: choices = CHANNEL_TYPE.items() choices.pop(0) choices.pop(0) form.type.choices = choices if not channel.channel_logo_filename: del form.delete_logo if form.validate_on_submit(): old_channel = channel form.populate_obj(channel) if form.delete_logo and form.delete_logo.data: try: if old_channel.channel_logo_filename: os.remove( os.path.join(app.static_folder, 'thumbnails', old_channel.channel_logo_filename)) flash(u"Removed channel logo", u"success") else: flash(u"Channel doesn't have logo", u"info") except OSError: flash(u"Channel logo already Removed", u"info") channel.channel_logo_filename = None else: if 'channel_logo' in request.files and request.files[ 'channel_logo']: try: if old_channel.channel_logo_filename: db.session.add(old_channel) try: os.remove( os.path.join( app.static_folder, 'thumbnails', old_channel.channel_logo_filename)) except OSError: old_channel.channel_logo_filename = None flash(u"Unable to delete previous logo", u"error") message = u"Unable to save image" image = resize_image(request.files['channel_logo']) channel.channel_logo_filename = thumbnails.save(image) message = u"Channel logo uploaded" except OSError: flash(message, u"error") channel.channel_logo_filename = None else: message = u"Edited description for channel" flash(message, 'success') db.session.commit() return render_redirect(channel.url_for(), code=303) return render_form(form=form, title=u"Edit channel", submit=u"Save", cancel_url=channel.url_for(), ajax=False)
def channel_edit(channel): form = ChannelForm(obj=channel) if channel.userid == g.user.userid: form.type.choices = [(1, CHANNEL_TYPE[1])] else: choices = CHANNEL_TYPE.items() choices.pop(0) choices.pop(0) form.type.choices = choices if not channel.channel_logo_filename: del form.delete_logo if form.validate_on_submit(): old_channel = channel form.populate_obj(channel) if form.delete_logo and form.delete_logo.data: try: if old_channel.channel_logo_filename: os.remove(os.path.join(app.static_folder, 'thumbnails', old_channel.channel_logo_filename)) flash(u"Removed channel logo", u"success") else: flash(u"Channel doesn't have logo", u"info") except OSError: flash(u"Channel logo already Removed", u"info") channel.channel_logo_filename = None else: if request.files['channel_logo']: try: if old_channel.channel_logo_filename: db.session.add(old_channel) try: os.remove(os.path.join(app.static_folder, 'thumbnails', old_channel.channel_logo_filename)) except OSError: old_channel.channel_logo_filename = None flash(u"Unable to delete previous logo", u"error") message = u"Unable to save image" image = resize_image(request.files['channel_logo']) channel.channel_logo_filename = thumbnails.save(image) message = u"Channel logo uploaded" except OSError: flash(message, u"error") channel.channel_logo_filename = None else: message = u"Edited description for channel" flash(message, 'success') db.session.commit() return render_redirect(channel.url_for(), code=303) return render_form(form=form, title=u"Edit channel", submit=u"Save", cancel_url=channel.url_for(), ajax=False)
def channel_edit(channel): form = ChannelForm(obj=channel) if channel.userid == current_auth.user.userid: form.type.choices = [(1, CHANNEL_TYPE[1])] else: choices = CHANNEL_TYPE.items() choices.pop(0) choices.pop(0) form.type.choices = choices if not channel.channel_logo_filename: del form.delete_logo if request.method == 'GET': html_form = render_form(form=form, title=_("Edit channel"), submit=_("Save"), cancel_url=channel.url_for(), ajax=False, with_chrome=False) return {'channel': dict(channel.current_access()), 'form': html_form} if form.validate_on_submit(): old_channel = channel form.populate_obj(channel) if form.delete_logo and form.delete_logo.data: try: if old_channel.channel_logo_filename: os.remove(os.path.join(app.static_folder, 'thumbnails', old_channel.channel_logo_filename)) message = "Removed channel logo" except OSError: channel.channel_logo_filename = None message = "Channel logo already Removed" else: if 'channel_logo' in request.files and request.files['channel_logo']: try: if old_channel.channel_logo_filename: db.session.add(old_channel) try: os.remove(os.path.join(app.static_folder, 'thumbnails', old_channel.channel_logo_filename)) except OSError: old_channel.channel_logo_filename = None message = "Unable to delete previous logo" image = resize_image(request.files['channel_logo']) channel.channel_logo_filename = thumbnails.save(image) message = "Channel logo uploaded" except OSError: message = "Unable to save image" channel.channel_logo_filename = None else: message = "Edited description for channel" db.session.commit() return {'status': 'ok', 'doc': _(message), 'result': {}} return {'status': 'error', 'errors': form.errors}, 400
def channel_edit(channel): form = ChannelForm(obj=channel) if channel.userid == g.user.userid: form.type.choices = [(1, channel_types[1])] else: choices = channel_types.items() choices.sort() choices.pop(0) choices.pop(0) form.type.choices = choices if form.validate_on_submit(): form.populate_obj(channel) db.session.commit() flash(u"Edited description for channel", 'success') return render_redirect(channel.url_for(), code=303) return render_form(form=form, title=u"Edit channel", submit=u"Save", cancel_url=channel.url_for(), ajax=True)