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 generate_event(publishing): return { 'summary': publishing.title, 'description': publishing.description, 'attachments': [{ "fileUrl": publishing.link_url, }], 'start': { 'dateTime': str_converter(publishing.date_from) + ':00Z', 'timeZone': 'Europe/Zurich', }, 'end': { 'dateTime': str_converter(publishing.date_until) + ':00Z', 'timeZone': 'Europe/Zurich', }, 'reminders': { 'useDefault': False, 'overrides': [ { 'method': 'email', 'minutes': 24 * 60 }, { 'method': 'popup', 'minutes': 10 }, ], }, }
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 test_run_gcal(client): user, channel, post, pub = setup_db(channel_name='test_gcal', channel_module='gcal_plugin') login(client, user.id) rv = client.post('/moderate/' + str(post.id) + '/' + str(channel.id), data=dict(titlepost=pub.title, descrpost=pub.description, linkurlpost=pub.link_url, imagepost=pub.image_url, datefrompost=str_converter(pub.date_from), dateuntilpost=str_converter(pub.date_until))) creds = gcal_plugin.get_user_credentials(user.id) service = build('calendar', 'v3', credentials=creds) events = service.events().list(calendarId='primary', pageToken=None).execute() page_token, goal = None, None while True: events = service.events().list(calendarId='primary', pageToken=page_token).execute() for event in events['items']: if ('summary' in event and event['summary'] == pub.title): goal = event break page_token = events.get('nextPageToken') if not page_token: break delete_db(user, channel, post, pub) if goal: service.events().delete(calendarId='primary', eventId=goal['id']).execute() assert goal != None
def moderate_publishing(id,idc): pub = db.session.query(PubGCal).filter(PubGCal.post_id==id,PubGCal.channel_id==idc).first() pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) if request.method=="GET": return render_template('moderate_post.html', pub=pub) else: pub.title = request.form.get('titlepost') pub.description = request.form.get('descrpost') pub.link_url = request.form.get('linkurlpost') pub.datedebut=datetime_converter(request.form.get('datedebut')) pub.heuredebut=request.form.get('heuredebut') pub.datefin=datetime_converter(request.form.get('datefin')) pub.heurefin=request.form.get('heurefin') pub.location = request.form.get('location') pub.color = request.form.get('color') pub.visibility = request.form.get('visibility') pub.availability = request.form.get('availability') pub.guests = request.form.get('guests') 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')) #state is shared & validated pub.state = 1 db.session.commit() #running the plugin here c=db.session.query(Channel).filter(Channel.name == pub.channel_id).first() plugin_name = c.module c_conf = c.config from importlib import import_module plugin = import_module(plugin_name) plugin.run(pub, c_conf) return redirect(url_for('index'))
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 update_pub(pub, state): """ Update the publication with the new values in the form :param pub: the publication to update :param state: the new state of the publication """ pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) 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.rss_feed = request.form.get('linkrssfeedpost') pub.date_from = datetime_converter(request.form.get('datefrompost')) time_from = time_converter( request.form.get('timefrompost')) if request.form.get( 'timefrompost') is not None else time_converter("0:0") pub.date_from = pub.date_from.replace(hour=time_from.hour, minute=time_from.minute) pub.date_until = datetime_converter(request.form.get('dateuntilpost')) time_until = time_converter( request.form.get('timeuntilpost')) if request.form.get( 'timeuntilpost') is not None else time_converter("0:0") pub.date_until = pub.date_until.replace(hour=time_until.hour, minute=time_until.minute) pub.state = state
def moderate_publishing(id, idc): pub = db.session.query(Publishing).filter(Publishing.post_id == id, Publishing.channel_id == idc).first() c = db.session.query(Channel).filter(Channel.id == idc).first() pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) plugin_name = c.module c_conf = c.config from importlib import import_module plugin = import_module(plugin_name) if request.method == "GET": if channels.valid_conf(c_conf, plugin.CONFIG_FIELDS): return render_template('moderate_post.html', pub=pub, notconf=False, chan=c) else: return render_template('moderate_post.html', pub=pub, notconf=True, chan=c) 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')) if channels.valid_conf(c_conf, plugin.CONFIG_FIELDS): # state is shared & validated pub.state = 1 db.session.commit() # running the plugin here plugin.run(pub, c_conf) else: return render_template('moderate_post.html', pub=pub, notconf=True, chan=c) return redirect(url_for('index'))
def post_validate_rework_publishing(client, pub, chan): return client.post('/rework/' + str(pub.post_id) + '/' + str(chan.id) + '/validate_edit_publishing', data=dict(titlepost=pub.title, descrpost=pub.description, linkurlpost=pub.link_url, imagepost=pub.image_url, datefrompost=str_converter(pub.date_from), dateuntilpost=str_converter(pub.date_until)), follow_redirects=True)
def post_validate_publishing(client, post, chan, commentpub): return client.post('/moderate/' + str(post.id) + '/' + str(chan.id) + '/validate_publishing', data=dict(titlepost=post.title, descrpost=post.description, linkurlpost=post.link_url, imagepost=post.image_url, datefrompost=str_converter(post.date_from), dateuntilpost=str_converter(post.date_until), commentpub=commentpub), follow_redirects=True)
def records(): """ This methods is called for the creation of the Records page """ # FIXME Essayez de suivre le pattern PRG (post-redirect-get) pour éviter des misbehaviors # FIXME en cas de rechargement de la page # Check if there is any publishing to pass as archived publishings = db.session.query(Publishing).filter(Publishing.state == 1)\ .filter(Publishing.date_until <= datetime.datetime.now()) publishings.update({Publishing.state: 2}) db.session.commit() # Check if a user is an admin admin = session.get("admin", False) if session.get("logged_in", False) else False # Check if a post has been send to delete an archive if request.method == "POST" and request.form.get('@action', '') == "delete": if admin: id = request.form.get("id") idc = request.form.get("idc") pub = db.session.query(Publishing).filter( Publishing.post_id == id, Publishing.channel_id == idc) pub.delete() db.session.commit() else: # TODO, it seems like we have some cheater here pass user_id = session.get("user_id", "") if session.get("logged_in", False) else -1 list_of_channels = channels_available_for_user(user_id) # Query all the archived publishings archives = db.session.query(Publishing)\ .filter(Publishing.state >= 1)\ .filter(Publishing.date_until <= str(datetime.datetime.now())[0:19]) # Take all archives and format the dates entries records = [] for a in archives: allowed = False for channel in list_of_channels: if channel.id == a.channel_id: allowed = True break if allowed: date_from = str_converter(a.date_from) date_until = str_converter(a.date_until) records.append((a, date_from, date_until)) return render_template('records.html', records=records, admin=admin)
def moderate_publishing(id, idc): pub = db.session.query(Publishing).filter( Publishing.post_id == id, Publishing.channel_id == idc).first() chan = db.session.query(Channel).filter(Channel.id == idc).first() pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) if request.method == "GET": plugin = import_module(chan.module) if pub.misc is not None: misc = json.loads( pub.misc) # adding extra fields to context (might be empty) else: misc = {} print('get moderate_publishing') return render_template('moderate_post.html', extra=misc, template=plugin.get_template_mod(), pub=pub, chan=chan) else: print('post moderate_publishing') 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')) # state is shared & validated """pub.state = 1 db.session.commit() """ # running the plugin here c = db.session.query(Channel).filter( Channel.id == pub.channel_id).first() plugin_name = c.module c_conf = c.config plugin = import_module(plugin_name) #every plugin should implement the autheticate method that redirect to the plugin authentication process #if it is required or necessary (no token available or expired)! url = plugin.authenticate(c.name, (id, idc)) if url != "AlreadyAuthenticated": print("url", url) return plugin.auto_auth(url, pub.channel_id) print('publishing publishings.py', pub) plugin.run(pub, c_conf) return redirect(url_for('index'))
def test_GCAL_post(client): user, channel, post, pub = setup_db(channel_name='test_gcal', channel_module='gcal') with app.test_request_context('/make_report/2017', data={'format': 'short'}): session[ "user_id"] = user.id # Fix: the test_request_context created here doesn't contain the user_id k = stats.number_of_accepted() # ------------------------- login(client, user.id) rv = client.post('/moderate/' + str(post.id) + '/' + str(channel.id), data=dict(titlepost=pub.title, descrpost=pub.description, linkurlpost=pub.link_url, imagepost=pub.image_url, datefrompost=str_converter(pub.date_from), dateuntilpost=str_converter(pub.date_until))) creds = gcal.get_user_credentials(user.id) service = build('calendar', 'v3', credentials=creds) events = service.events().list(calendarId='primary', pageToken=None).execute() page_token, goal = None, None while True: events = service.events().list(calendarId='primary', pageToken=page_token).execute() for event in events['items']: if 'summary' in event and event['summary'] == pub.title: goal = event break page_token = events.get('nextPageToken') if not page_token: break # ------------------------------- with app.test_request_context('/make_report/2017', data={'format': 'short'}): session[ "user_id"] = user.id # Fix: the test_request_context created here doesn't contain the user_id k2 = stats.number_of_accepted() - 1 test_gcal.delete_db(user, channel, post, pub) if goal: service.events().delete(calendarId='primary', eventId=goal['id']).execute() assert goal is not None assert k == k2
def copy_new_post(post_id): """ This method copy the content of a post (defined by his post_id) and open the new post tab with all the informations of the original post copied in it (and with the title modified) :param post_id: id of the original post to be copied :return: """ user_id = session.get("user_id", "") if session.get("logged_in", False) else -1 list_of_channels = channels_available_for_user(user_id) ictv_chans = [] for elem in list_of_channels: m = elem.module clas = get_instance_from_module_path(m) unavailable_fields = '.'.join(clas.FIELDS_UNAVAILABLE) setattr(elem, "unavailablefields", unavailable_fields) if 'ictv_data_form' in unavailable_fields: ictv_chans.append(elem) # Query the data from the original post original_post = db.session.query(Post).filter(Post.id == post_id).first() post = Post(user_id=user_id, title="Copy of " + original_post.title, description=original_post.description, link_url=original_post.link_url, image_url=original_post.image_url, date_from=original_post.date_from, date_until=original_post.date_until) if request.method == "GET": ictv_data = None if len(ictv_chans) != 0: from plugins.ictv import process_ictv_channels ictv_data = process_ictv_channels(ictv_chans) post.date_from = str_converter(post.date_from) post.date_until = str_converter(post.date_until) return render_template('new.html', l_chan=list_of_channels, ictv_data=ictv_data, post=post, new=True) else: create_a_post(request.form) flash("The post was successfully copied.", category='success') return redirect(url_for('index'))
def test_date_converters(): t = datetime_converter("2017-06-02") assert t.day == 2 assert t.month == 6 assert t.year == 2017 assert isinstance(t, datetime.datetime) st = str_converter(t) assert isinstance(st,str)
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 moderate_publishing(id, idc): try: pub = db.session.query(Publishing).filter( Publishing.post_id == id, Publishing.channel_id == idc).first() pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) if request.method == "GET": print("RENDER") return render_template('moderate_post.html', pub=pub) else: print("PUBLISH") 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_time = hour_converter(request.form.get('starttime')) #pub.end_time = hour_converter(request.form.get('endtime')) #state is shared & validated #running the plugin here 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) plugin.run(pub, c_conf) pub.state = 1 db.session.commit() return redirect(url_for('index')) except facebook.GraphAPIError: flash( 'Access token error, please refresh your tokens and fill the publication date again' ) return render_template('moderate_post.html', pub=pub) return redirect(url_for('index'))
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 default(self, obj): if isinstance(obj.__class__, DeclarativeMeta): # an SQLAlchemy class fields = {} for field in [x for x in vars(obj) if not x.startswith('_') and x != 'metadata']: data = obj.__getattribute__(field) try: if data.__class__ == datetime.datetime: fields[field] = str_converter(data) else: json.dumps(data) # this will fail on non-encodable values, like other classes fields[field] = data except TypeError: fields[field] = None # a json-encodable dict return fields return json.JSONEncoder.default(self, obj)
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 moderate_publishing(id, idc): pub = db.session.query(Publishing).filter(Publishing.post_id == id, Publishing.channel_id == idc).first() chan = db.session.query(Channel).filter(Channel.id == idc).first() pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) if request.method == "GET": date_f = pub.date_from date_u = pub.date_until pub.date_from = datetime_converter(pub.date_from) pub.date_until = datetime_converter(pub.date_until) v = db.session.query(Channel).filter(Channel.id == pub.channel_id).first() pub.date_from = date_f pub.date_until = date_u if v.module == "superform.plugins.facebook": session["facebook_running"] = True else: session["facebook_running"] = False if pub.extra is not None: pub.extra = json.loads(pub.extra) return render_template('moderate_post.html', pub=pub, chan=chan) else: pub.date_from = datetime_converter(pub.date_from) pub.date_until = datetime_converter(pub.date_until) c = db.session.query(Channel).filter(Channel.id == pub.channel_id).first() if c.module == "superform.plugins.facebook": from superform.plugins.facebook import fb_token session["facebook_running"] = True if fb_token == 0: return redirect(url_for('publishings.moderate_publishing', id=id, idc=idc)) else: session["facebook_running"] = False 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')) extra = dict() 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) if 'get_channel_fields' in dir(plugin): extra = plugin.get_channel_fields(request.form, None) pub.extra = json.dumps(extra) # state is shared & validated pub.state = 1 db.session.commit() # running the plugin here if (pub.date_until <= datetime.now() - timedelta(days=1)): pub.state = 0 db.session.commit() flash('Too late to publish') pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) if pub.extra is not None: pub.extra = json.loads(pub.extra) return render_template('moderate_post.html', pub=pub, chan=chan) from importlib import import_module plugin = import_module(plugin_name) try: plugin.run(pub, c_conf) except RunPluginException as e: pub.state = 0 db.session.commit() flash(str(e)) pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) if pub.extra is not None: pub.extra = json.loads(pub.extra) return render_template('moderate_post.html', pub=pub, chan=chan) return redirect(url_for('index'))
def moderate_publishing(id, idc): chn = db.session.query(Channel).filter(Channel.id == idc).first() """ 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 = db.session.query(Publishing).filter( Publishing.post_id == id, Publishing.channel_id == idc).order_by( Publishing.num_version.desc()).first() pub.date_from = str_converter(pub.date_from) pub.date_until = str_converter(pub.date_until) if request.method == "GET": """SHOULD PREPARE THE pub_versions AND pub_comments""" post_form_validations = get_post_form_validations() plugin = import_module(chn.module) if pub.misc is not None: misc = json.loads( pub.misc) # adding extra fields to context (might be empty) else: misc = {} return render_template('moderate_post.html', extra=misc, template=plugin.get_template_mod(), pub=pub, channel=chn, pub_versions=pub_versions, pub_comments=pub_comments_json, comments=pub_comments, post_form_validations=post_form_validations) 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') if chn.module == 'superform.plugins.ICTV': pub.logo = request.form.get('logo') pub.subtitle = request.form.get('subtitle') pub.duration = request.form.get('duration') pub.date_from = datetime_converter( request.form.get('datefrompost')) pub.date_until = datetime_converter( request.form.get('dateuntilpost')) else: pub.date_from = datetime_converter( request.form.get('datefrompost')) pub.date_until = datetime_converter( request.form.get('dateuntilpost')) # state is shared & validated """pub.state = 1 db.session.commit() """ # running the plugin here c = db.session.query(Channel).filter( Channel.id == pub.channel_id).first() plugin_name = c.module c_conf = c.config plugin = import_module(plugin_name) # every plugin should implement the autheticate method that redirect to the plugin authentication process # if it is required or necessary (no token available or expired)! url = plugin.authenticate(c.id, (id, idc)) if url != "AlreadyAuthenticated": return plugin.auto_auth(url, pub.channel_id) if pub.state == 66: try: can_edit = plugin.can_edit(pub, c_conf) if can_edit: plugin.edit(pub, c_conf) pub.state = 1 db.session.commit() else: pub.state = 1 db.session.commit() except AttributeError: pub.state = 1 print("Error : module don't implement can_edit or edit method") db.session.commit() else: plugin.run(pub, c_conf) return redirect(url_for('index'))
def edit_post(post_id): """ This method allow the editing the content of a post (defined by his post_id) and opens the new post tab with all the information about the post in it :param post_id: id of the post to be edited :return: """ user_id = session.get("user_id", "") if session.get("logged_in", False) else -1 list_of_channels = channels_available_for_user(user_id) ictv_chans = [] for elem in list_of_channels: m = elem.module clas = get_instance_from_module_path(m) unavailable_fields = '.'.join(clas.FIELDS_UNAVAILABLE) setattr(elem, "unavailablefields", unavailable_fields) if 'ictv_data_form' in unavailable_fields: ictv_chans.append(elem) # Query the data from the post post = db.session.query(Post).filter(Post.id == post_id).first() # Query the publishing of the post list_publishing = db.session.query(Publishing).filter( Publishing.post_id == post_id) # Get list of channels with publishing not yet publish or validated # and list of channels with not yet publishing list_chan_id_selected = [] list_already_pub = [] for pub in list_publishing: list_chan_id_selected.append(pub.channel_id) if pub.state == State.PUBLISHED.value or pub.state == State.VALIDATED.value: list_already_pub.append(pub.channel_id) list_chan_selected = [] list_chan_not_selected = [] for chan in list_of_channels: if list_chan_id_selected.__contains__(chan.id): if not list_already_pub.__contains__(chan.id): list_chan_selected.append(chan) else: list_chan_not_selected.append(chan) if request.method == "GET": ictv_data = None if len(ictv_chans) != 0: from plugins.ictv import process_ictv_channels ictv_data = process_ictv_channels(ictv_chans) post.date_from = str_converter(post.date_from) post.date_until = str_converter(post.date_until) return render_template('new.html', l_chan=list_chan_selected, ictv_data=ictv_data, post=post, new=False, l_chan_not=list_chan_not_selected) else: modify_a_post(request.form, post_id) flash("The post was successfully edited.", category='success') return redirect(url_for('index'))
def build_full_date_until(publishing): return str_converter(publishing.date_until) + "T" + str_time_converter( publishing.end_hour) + ':00Z'