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) 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 unvalidate_publishing(id): """SAVOIR SI ON FAIT POST_ID ET CHANNEL_ID OU PUBLISHING_ID DIRECTLY""" print("pub-id to unvalidate ", id) pub = db.session.query(Publishing).filter( Publishing.publishing_id == id).first() pub.state = State.REFUSED.value """TESTER SI MODERATOR_COMMENT EST NONE""" moderator_comment = "" print('mod', request.form.get('moderator_comment')) if request.form.get('moderator_comment'): moderator_comment = request.form.get('moderator_comment') print('mod_com', moderator_comment) comm = db.session.query(Comment).filter( Comment.publishing_id == pub.publishing_id).first() date_moderator_comment = str_converter_with_hour(datetime_now()) if comm: comm.moderator_comment = moderator_comment comm.date_moderator_comment = date_moderator_comment else: comm = Comment(publishing_id=pub.publishing_id, moderator_comment=moderator_comment, date_moderator_comment=date_moderator_comment) db.session.add(comm) db.session.commit() return redirect(url_for('index'))
def unvalidate_publishing(id): pub = db.session.query(Publishing).filter( Publishing.publishing_id == id).first() pub.state = State.REFUSED.value moderator_comment = "" if request.form.get('moderator_comment'): moderator_comment = request.form.get('moderator_comment') comm = db.session.query(Comment).filter( Comment.publishing_id == pub.publishing_id).first() date_moderator_comment = str_converter_with_hour(datetime_now()) if comm: comm.moderator_comment = moderator_comment comm.date_moderator_comment = date_moderator_comment else: comm = Comment(publishing_id=pub.publishing_id, moderator_comment=moderator_comment, date_moderator_comment=date_moderator_comment) db.session.add(comm) db.session.commit() return redirect(url_for('index'))
def create_a_publishing(post, chn, form): # called in publish_from_new_post() chan = str(chn.name) plug = import_module(chn.module) title_post = form.get(chan + '_titlepost') if (form.get(chan + '_titlepost') is not None) else post.title # Team2 stat chn.count += 1 user_id = session.get("user_id", "") if session.get("logged_in", False) else -1 # Team2 stat # TEAM 10 twitter if "twitter" in chn.module: descr_post = form.get('tweets') elif form.get(chan + '_descriptionpost') is not None: descr_post = form.get(chan + '_descriptionpost') else: descr_post = post.description # TEAM 10 twitter # TEAM 3 ictv if 'forge_link_url' in dir(plug): link_post = plug.forge_link_url(chan, form) else: link_post = form.get(chan + '_linkurlpost') if form.get( chan + '_linkurlpost') is not None else post.link_url # TEAM 3 ictv image_post = form.get(chan + '_imagepost') if form.get( chan + '_imagepost') is not None else post.image_url if form.get(chan + '_datefrompost') is '': date_from = date.today() else: date_from = datetime_converter( form.get(chan + '_datefrompost')) if form.get( chan + '_datefrompost') is not None else post.date_from if form.get(chan + '_dateuntilpost') is '': date_until = date.today() + timedelta(days=7) else: date_until = datetime_converter( form.get(chan + '_dateuntilpost')) if form.get( chan + '_datefrompost') is not None else post.date_until if form.get(chan + '_starthour') is '': start_hour = time_converter("00:00") else: start_hour = time_converter(form.get(chan + '_starthour')) if form.get( chan + '_starthour') is not None else post.start_hour if form.get(chan + '_endhour') is '': end_hour = time_converter("23:59") else: end_hour = time_converter(form.get(chan + '_endhour')) if form.get( chan + '_endhour') is not None else post.end_hour latest_version_publishing = db.session.query(Publishing).filter( Publishing.post_id == post.id, Publishing.channel_id == chn.id).order_by( Publishing.num_version.desc()).first() version_number = 1 if latest_version_publishing is None else latest_version_publishing.num_version + 1 pub = Publishing(num_version=version_number, post_id=post.id, user_id=user_id, channel_id=chn.id, state=State.NOT_VALIDATED.value, title=title_post, description=descr_post, link_url=link_post, image_url=image_post, date_from=date_from, date_until=date_until, start_hour=start_hour, end_hour=end_hour) # TEAM6: MODIFICATION FOR PDF c = db.session.query(Channel).filter(Channel.id == pub.channel_id).first() if c is not None: plugin_name = c.module # If it is a pdf chanel we don't need to save it, printing it would be enough if str(plugin_name).endswith("pdf"): c_conf = c.config plugin = import_module(plugin_name) plugin.run(pub, c_conf) # Does not save the pdf posts return pub # TEAM6: END OF MODIFICATION db.session.add(pub) db.session.commit() if latest_version_publishing is None: user_comment = "" date_user_comment = str_converter_with_hour(datetime_now()) comm = Comment(publishing_id=pub.publishing_id, user_comment=user_comment, date_user_comment=date_user_comment) db.session.add(comm) db.session.commit() return pub
def create_a_publishing(post, chn, form): # called in publish_from_new_post() chan = str(chn.name) validate = pre_validate_post(chn, post) if validate == -1 or validate == 0: return validate title_post = form.get(chan + '_titlepost') if (form.get(chan + '_titlepost') is not None) else post.title descr_post = form.get(chan + '_descriptionpost') if form.get( chan + '_descriptionpost') is not None else post.description link_post = form.get(chan + '_linkurlpost') if form.get(chan + '_linkurlpost') is not None else post.link_url image_post = form.get(chan + '_imagepost') if form.get(chan + '_imagepost') is not None else post.image_url plugin = import_module(chn.module) if "saveExtraFields" in vars(plugin): misc_post = plugin.saveExtraFields(chan, form) # plugin will handle extra fields here if form.get(chan + 'datefrompost') is '': date_from = date.today() else: date_from = datetime_converter(form.get(chan + '_datefrompost')) if datetime_converter( form.get(chan + '_datefrompost')) is not None else post.date_from if form.get(chan + 'dateuntilpost') is '': date_until = date.today() + timedelta(days=7) else: date_until = datetime_converter(form.get(chan + '_dateuntilpost')) if datetime_converter( form.get(chan + '_dateuntilpost')) is not None else post.date_until if chn.module == 'superform.plugins.ICTV': logo = form.get(chan + '_logo') subtitle = form.get(chan + '_subtitle') duration = form.get(chan + '_duration') pub = Publishing(post_id=post.id, channel_id=chn.id, state=0, title=title_post, description=descr_post, link_url=link_post, image_url=image_post, date_from=date_from, date_until=date_until, logo=logo, subtitle=subtitle, duration=duration) db.session.add(pub) db.session.commit() else: latest_version_publishing = db.session.query(Publishing).filter(Publishing.post_id == post.id, Publishing.channel_id == chn.id).order_by( Publishing.num_version.desc()).first() if latest_version_publishing is None: pub = Publishing(post_id=post.id, channel_id=chn.id, state=State.NOT_VALIDATED.value, title=title_post, description=descr_post, link_url=link_post, image_url=image_post, date_from=date_from, date_until=date_until, misc=misc_post) db.session.add(pub) db.session.commit() user_comment = "" date_user_comment = str_converter_with_hour(datetime_now()) comm = Comment(publishing_id=pub.publishing_id, user_comment=user_comment, date_user_comment=date_user_comment) db.session.add(comm) db.session.commit() else: pub = Publishing(num_version=latest_version_publishing.num_version + 1, post_id=post.id, channel_id=chn.id, state=State.NOT_VALIDATED.value, title=title_post, description=descr_post, link_url=link_post, image_url=image_post, date_from=date_from, date_until=date_until, misc=misc_post) db.session.add(pub) db.session.commit() return pub