def view_feedback(id, idc): """ View the feedbacks and the publishing of a publishing that has already been moderated and accepted :param id: post id :param idc: channel id :return: the publishing with the feedbacks or an error message if the publishing hasn't yet been moderated """ pub = db.session.query(Publishing).filter( Publishing.post_id == id, Publishing.channel_id == idc).first() c = db.session.query(Channel).filter(Channel.id == pub.channel_id).first() # Only publishing that have yet to be moderated can be viewed if pub.state == State.NOTVALIDATED.value: flash('This publication has not yet been moderated.', category='info') return redirect(url_for('index')) mod = get_moderation(pub) time_until = str_time_converter(pub.date_until) time_from = str_time_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) pub.date_from = str_converter(pub.date_from) if request.method == "GET": return render_template('show_message.html', pub=pub, mod=mod, chan=c, time_from=time_from, time_until=time_until)
def rework_publishing(id, idc): """ Rework a publishing that has been refused by a moderator :param id: post id :param idc: channel id :return: display an error message if the publishing hasn't been refused else render rework_publishing.html """ pub = db.session.query(Publishing).filter( Publishing.post_id == id, Publishing.channel_id == idc).first() c = db.session.query(Channel).filter(Channel.id == pub.channel_id).first() # Only refused publishings can be reworked # NOTE We could also allow unmoderated publishings to be reworked, but this overlaps the "editing" feature. if pub.state != State.REFUSED.value: flash('This publication has not been refused and cannot be reworked.', category='info') return redirect(url_for('index')) mod = get_moderation(pub) time_until = str_time_converter(pub.date_until) time_from = str_time_converter(pub.date_from) pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) if request.method == "GET": return render_template('rework_publishing.html', pub=pub, mod=mod, chan=c, time_until=time_until, time_from=time_from)
def view_publishing(id, idc): """ View a publishing that has not yet been moderated with post_id = id and channel_id = idc :param id: post id :param idc: channel id :return: the actual publishing """ pub = db.session.query(Publishing).filter( Publishing.post_id == id, Publishing.channel_id == idc).first() c = db.session.query(Channel).filter(Channel.id == pub.channel_id).first() time_until = str_time_converter(pub.date_until) time_from = str_time_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) pub.date_from = str_converter(pub.date_from) if request.method == "GET": return render_template('show_message.html', pub=pub, chan=c, time_until=time_until, time_from=time_from)
def moderate_publishing(id, idc): pub = db.session.query(Publishing).filter( Publishing.post_id == id, Publishing.channel_id == idc).first() # Only publishing that have yet to be moderated can be viewed if pub.state != State.NOTVALIDATED.value: flash("This publication has already been moderated", category='info') return redirect(url_for('index')) c = db.session.query(Channel).filter(Channel.id == pub.channel_id).first() plugin_name = c.module c_conf = c.config from importlib import import_module plugin = import_module(plugin_name) mod = get_moderation(pub) if len(mod) > 0: mod.remove(mod[-1]) time_until = str_time_converter(pub.date_until) time_from = str_time_converter(pub.date_from) pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) if request.method == "GET": error_msg = channels.check_config_and_validity(plugin, c_conf) if error_msg is not None: flash(error_msg, category='error') chan_not_conf = True else: chan_not_conf = False return render_template('moderate_publishing.html', pub=pub, chan=c, mod=mod, chan_not_conf=chan_not_conf, time_from=time_from, time_until=time_until)
def resubmit_publishing(id): pub = db.session.query(Publishing).filter(Publishing.publishing_id == id).first() chn = db.session.query(Channel).filter(Channel.id == pub.channel_id).first() if request.method == "POST": new_pub = create_a_resubmit_publishing(pub, chn, request.form) db.session.add(new_pub) pub.state = State.OLD_VERSION.value db.session.commit() user_comment = "" if request.form.get('user_comment'): user_comment = request.form.get('user_comment') date_user_comment = str_converter_with_hour(datetime_now()) comm = Comment(publishing_id=new_pub.publishing_id, user_comment=user_comment, date_user_comment=date_user_comment) db.session.add(comm) db.session.commit() return redirect(url_for('index')) else: pub_versions = db.session.query(Publishing).filter(Publishing.post_id == pub.post_id, Publishing.channel_id == pub.channel_id). \ order_by(Publishing.num_version.desc()).all() pub_ids = [] for pub_ver in pub_versions: pub_ids.insert(0, pub_ver.publishing_id) pub_comments = db.session.query(Comment).filter(Comment.publishing_id.in_(pub_ids)).all() pub_versions = json.dumps(pub_versions, cls=AlchemyEncoder) pub_comments_json = json.dumps(pub_comments, cls=AlchemyEncoder) pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) pub.start_hour = str_time_converter(pub.start_hour) pub.end_hour = str_time_converter(pub.end_hour) post_form_validations = get_post_form_validations() return render_template('resubmit_post.html', pub=pub, channel=chn, pub_versions=pub_versions, pub_comments=pub_comments_json, comments=pub_comments, post_form_validations=post_form_validations)
def moderate_publishing(id, idc): pub = db.session.query(Publishing).filter( Publishing.post_id == id, Publishing.channel_id == idc).order_by( Publishing.num_version.desc()).first() if pub.state != State.NOT_VALIDATED.value: flash("This publication has already been moderated", category='info') return redirect(url_for('index')) chn = db.session.query(Channel).filter(Channel.id == idc).first() plugin_name = chn.module c_conf = chn.config plugin = import_module(plugin_name) notconfig = not valid_conf(c_conf, plugin.CONFIG_FIELDS) # TEAM6 gcal Moved the acquisition of the credentials here since it makes more sense if plugin_name.endswith('gcal') and get_user_credentials() is None: return generate_user_credentials( c_conf, id, idc) # Return the user to Google's authorization page # TEAM6 gcal """ FROM THIS : SHOULD BE IN THE if request.method == 'GET' (BUT pub.date_from = str_converter(pub.date_from) PREVENT US)""" pub_versions = db.session.query(Publishing).filter(Publishing.post_id == id, Publishing.channel_id == idc). \ order_by(Publishing.num_version.desc()).all() pub_ids = [] for pub_ver in pub_versions: pub_ids.insert(0, pub_ver.publishing_id) pub_comments = db.session.query(Comment).filter( Comment.publishing_id.in_(pub_ids)).all() """TO THIS""" pub_versions = json.dumps(pub_versions, cls=AlchemyEncoder) pub_comments_json = json.dumps(pub_comments, cls=AlchemyEncoder) pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) pub.start_hour = str_time_converter(pub.start_hour) pub.end_hour = str_time_converter(pub.end_hour) if request.method == "GET" or notconfig: """SHOULD PREPARE THE pub_versions AND pub_comments""" post_form_validations = get_post_form_validations() return render_template('moderate_post.html', pub=pub, channel=chn, pub_versions=pub_versions, pub_comments=pub_comments_json, comments=pub_comments, post_form_validations=post_form_validations, notconf=notconfig) else: pub.title = request.form.get('titlepost') pub.description = request.form.get('descrpost') pub.link_url = request.form.get('linkurlpost') pub.image_url = request.form.get('imagepost') pub.date_from = datetime_converter(request.form.get('datefrompost')) pub.date_until = datetime_converter(request.form.get('dateuntilpost')) pub.start_hour = time_converter( request.form.get('starthour')) if request.form.get( 'starthour') is not None else time_converter("00:00") pub.end_hour = time_converter( request.form.get('endhour')) if request.form.get( 'endhour') is not None else time_converter("23:59") if pub.state == State.EDITED.value: # EDITION try: can_edit = plugin.can_edit(pub, c_conf) if can_edit: plugin.edit(pub, c_conf) pub.state = State.VALIDATED.value db.session.commit() else: pub.state = State.VALIDATED.value db.session.commit() except AttributeError: pub.state = State.VALIDATED.value flash("Error : module don't implement can_edit or edit method") db.session.commit() else: # try to run the plugin try: plug_exitcode = plugin.run(pub, c_conf) except Exception as e: # unexpected exception flash( "An unexpected error occurred while publishing, please contact an admin.", category='error') import sys print(str(e), file=sys.stderr) return redirect( url_for('publishings.moderate_publishing', id=id, idc=idc)) if type(plug_exitcode) is tuple and len( plug_exitcode ) >= 2 and plug_exitcode[0].value == StatusCode.ERROR.value: # well known exception flash(plug_exitcode[1], category='error') return redirect( url_for('publishings.moderate_publishing', id=id, idc=idc)) # If we reach here, the publication was successfull pub.state = State.VALIDATED.value db.session.commit() flash("The publishing has successfully been published.", category='success') return redirect(url_for('index'))
def build_full_date_from(publishing): return str_converter(publishing.date_from) + "T" + str_time_converter( publishing.start_hour) + ':00Z'
def build_full_date_until(publishing): return str_converter(publishing.date_until) + "T" + str_time_converter( publishing.end_hour) + ':00Z'