def create_a_publishing(post, chn, form):
    chan = str(chn.name)
    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
    date_from = datetime_converter(
        form.get(chan + '_datefrompost')) if datetime_converter(
            form.get(chan + '_datefrompost')) is not None else post.date_from
    date_until = datetime_converter(
        form.get(chan + '_dateuntilpost')) if datetime_converter(
            form.get(chan + '_dateuntilpost')) is not None else post.date_until
    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)

    db.session.add(pub)
    db.session.commit()
    return pub
Ejemplo n.º 2
0
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 get_moderation(pub):
    """
    get the moderations of the publishing
    :param pub: the publishing from whom we want to get the moderations
    :return: a list of moderations
    """
    pub.date_until = pub.date_until if type(
        pub.date_until) == datetime.datetime else datetime_converter(
            pub.date_until)
    pub.date_from = pub.date_from if type(
        pub.date_from) == datetime.datetime else datetime_converter(
            pub.date_from)
    mod = [
        mod for _, _, _, mod in (
            db.session.query(Post, Channel, User, Moderation).filter(
                Moderation.post_id == pub.post_id).filter(
                    Moderation.channel_id == pub.channel_id))
    ]
    new_mod = list()
    if len(mod) > 0:
        new_mod.append(mod[0])
        while new_mod[0] and new_mod[0].parent_post_id:
            parent_mod = db.session.query(Moderation).filter(
                Moderation.post_id == new_mod[0].parent_post_id).first()
            new_mod.insert(0, parent_mod)

    return new_mod
Ejemplo n.º 4
0
def test_delete_post(client):
    user_id = "myself"
    login(client, user_id)

    title_post = "title_test"
    descr_post = "description"
    link_post = "link"
    image_post = "img"
    date_from = datetime_converter("2018-01-01")
    date_until = datetime_converter("2018-01-10")
    p = Post(user_id=user_id,
             title=title_post,
             description=descr_post,
             link_url=link_post,
             image_url=image_post,
             date_from=date_from,
             date_until=date_until)
    db.session.add(p)
    db.session.commit()

    id_post = p.id

    path = '/delete_post/' + str(id_post)

    # verify that something has been posted/published
    assert db.session.query(Post).filter_by(id=id_post).first() is not None

    client.get(path)

    deleted_post = db.session.query(Post).filter_by(id=id_post).first()
    assert deleted_post is None
Ejemplo n.º 5
0
def create_a_post(form):  # called in publish_from_new_post() & new_post()
    user_id = session.get("user_id", "") if session.get("logged_in", False) else -1
    title_post = form.get('titlepost')
    descr_post = form.get('descriptionpost')
    link_post = form.get('linkurlpost')
    image_post = form.get('imagepost')

    # set default date if none was chosen
    if form.get('datefrompost') is '':
        date_from = date.today()
    else:
        date_from = datetime_converter(form.get('datefrompost'))
    if form.get('dateuntilpost') is '':
        date_until = date.today() + timedelta(days=7)
    else:
        date_until = datetime_converter(form.get('dateuntilpost'))

    # set hour to a default value since form doesn't provide one
    start_hour = time_converter("00:00")
    end_hour = time_converter("23:59")

    p = Post(user_id=user_id, 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)
    db.session.add(p)
    db.session.commit()
    return p
def prefill_db(client):
    post = Post(user_id='myself',
                title='title_post',
                description='descr_post',
                link_url='link_post',
                image_url='image_post',
                date_from=datetime_converter('2020-01-01'),
                date_until=datetime_converter('2020-01-01'))
    db.session.add(post)
    db.session.commit()
    chan = Channel(
        name='my_mail',
        id=-1,
        module='superform.plugins.mail',
        config='{"sender":"*****@*****.**", "receiver":"*****@*****.**"}')
    db.session.add(chan)
    db.session.commit()
    pub = Publishing(post_id=post.id,
                     channel_id=chan.id,
                     state=0,
                     title=post.title,
                     description=post.description,
                     link_url=post.link_url,
                     image_url=post.image_url,
                     date_from=post.date_from,
                     date_until=post.date_until)
    db.session.add(pub)
    db.session.commit()

    return post, chan, pub
Ejemplo n.º 7
0
def create(client):
    post = Post(user_id='myself',
                title='title_post',
                description='descr_post',
                link_url='link_post',
                image_url='image_post',
                date_from=datetime_converter('2017-06-02'),
                date_until=datetime_converter('2017-06-03'))
    db.session.add(post)
    db.session.commit()
    chan = Channel(
        name='rss',
        id=-1,
        module='superform.plugins.rss',
        config='{"feed_title": "test_title", "feed_description": "test_desc"}')
    db.session.add(chan)
    db.session.commit()
    pub = Publishing(post_id=post.id,
                     channel_id=chan.id,
                     state=0,
                     title=post.title,
                     description=post.description,
                     link_url=post.link_url,
                     image_url=post.image_url,
                     date_from=post.date_from,
                     date_until=post.date_until)
    db.session.add(pub)
    db.session.commit()

    return post, chan, pub
Ejemplo n.º 8
0
def edit_a_publishing(post, chn, form):
    pub = db.session.query(Publishing).filter(
        Publishing.post_id == post.id
    ).filter(Publishing.channel_id == chn.id).first(
    )  # ici ca renvoie None quand on modifie un publishing d'un channel qui n'existait pas encore: normal...
    if pub is None:
        return create_a_publishing(post, chn, form)
    else:
        chan = str(chn.name)
        pub.title = form.get(chan +
                             '_titlepost') if (form.get(chan + '_titlepost')
                                               is not None) else post.title
        pub.description = form.get(chan + '_descriptionpost') if form.get(
            chan + '_descriptionpost') is not None else post.description
        pub.link_url = form.get(chan + '_linkurlpost') if form.get(
            chan + '_linkurlpost') is not None else post.link_url
        pub.image_url = form.get(chan + '_imagepost') if form.get(
            chan + '_imagepost') is not None else post.image_url
        pub.date_from = datetime_converter(
            form.get(chan + '_datefrompost')) if form.get(
                chan + '_datefrompost') is not None else post.date_from
        pub.date_until = datetime_converter(
            form.get(chan + '_dateuntilpost')) if form.get(
                chan + '_dateuntilpost') is not None else post.date_until
        pub.rss_feed = form.get(chan + '_linkrssfeedpost')
        db.session.commit()
        return pub
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
Ejemplo n.º 10
0
def test_delete_not_author(client):
    user_id = "myself"
    user_id_author = "1"
    login(client, user_id)

    title_post = "title_test"
    descr_post = "description"
    link_post = "link"
    image_post = "img"
    date_from = datetime_converter("2018-01-01")
    date_until = datetime_converter("2018-01-10")
    p = Post(user_id=user_id_author, title=title_post, description=descr_post, link_url=link_post, image_url=image_post,
             date_from=date_from, date_until=date_until)
    db.session.add(p)
    db.session.commit()

    id_post = p.id

    path = '/delete/' + str(id_post)

    client.get(path)

    deleted_post = db.session.query(Post).filter_by(id=id_post).first()

    assert deleted_post is None

    db.session.delete(p)
    db.session.commit()
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'))
Ejemplo n.º 12
0
def create_a_resubmit_publishing(pub, chn, form):

    validate = pre_validate_post(chn, pub)
    if validate == -1 or validate == 0:
        return validate

    title_post = form.get('titlepost')
    descr_post = form.get('descrpost')
    link_post = form.get('linkurlpost')
    image_post = form.get('imagepost')
    if chn.module == 'superform.plugins.gcal':
        pub.date_start = datetime_converter(form.get('datedebut'))
        pub.hour_start = form.get('heuredebut')
        pub.date_end = datetime_converter(form.get('datefin'))
        pub.hour_end = form.get('heurefin')
        pub.location = form.get('location')
        pub.color = form.get('color')
        pub.visibility = form.get('visibility')
        pub.availability = form.get('availability')
    else:
        date_from = datetime_converter(form.get('datefrompost'))
        date_until = datetime_converter(form.get('dateuntilpost'))

    latest_version_publishing = db.session.query(Publishing).filter(Publishing.post_id == pub.post_id,
                                                                    Publishing.channel_id == chn.id).order_by(
                                                                    Publishing.num_version.desc()
                                                                    ).first()
    new_pub = Publishing(num_version=latest_version_publishing.num_version + 1, post_id=pub.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)
    return new_pub
Ejemplo n.º 13
0
def test_access_moderate_publishing(client):
    login(client, "myself")
    post, chan, pub = create(client)

    response = get_moderation(client, post, chan, pub)
    assert response.status_code == 200

    pub.date_from = datetime_converter(pub.date_from)
    pub.date_until = datetime_converter(pub.date_until)
Ejemplo n.º 14
0
def create_a_publishing(post, chn, form):
    chan = str(chn.name)

    plug_name = chn.module
    from importlib import import_module
    plug = import_module(plug_name)

    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

    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
    rss_feed = form.get(chan + '_linkrssfeedpost')
    image_post = form.get(chan + '_imagepost') if form.get(
        chan + '_imagepost') is not None else post.image_url
    date_from = datetime_converter(
        form.get(chan + '_datefrompost')) if form.get(
            chan + '_datefrompost') is not None else post.date_from
    time_from = time_converter(form.get(chan + '_timefrompost')) if form.get(
        chan + '_timefrompost') is not None else None
    if date_from and time_from:
        date_from = date_from.replace(hour=time_from.hour,
                                      minute=time_from.minute)

    date_until = datetime_converter(
        form.get(chan + '_dateuntilpost')) if form.get(
            chan + '_dateuntilpost') is not None else post.date_until
    time_until = time_converter(form.get(chan + '_timeuntilpost')) if form.get(
        chan + '_timeuntilpost') is not None else None
    if date_until and time_until:
        date_until = date_until.replace(hour=time_until.hour,
                                        minute=time_until.minute)

    pub = Publishing(post_id=post.id,
                     channel_id=chn.id,
                     state=State.NOTVALIDATED.value,
                     title=title_post,
                     description=descr_post,
                     link_url=link_post,
                     image_url=image_post,
                     date_from=date_from,
                     date_until=date_until,
                     rss_feed=rss_feed)

    db.session.add(pub)
    db.session.commit()
    return pub
Ejemplo n.º 15
0
def modify_a_post(form, post_id):
    post = db.session.query(Post).filter(Post.id == post_id).first()
    post.user_id = session.get("user_id", "") if session.get(
        "logged_in", False) else -1
    post.title = form.get('titlepost')
    post.description = form.get('descriptionpost')
    post.link_url = form.get('linkurlpost')
    post.image_url = form.get('imagepost')
    post.date_from = datetime_converter(form.get('datefrompost'))
    post.date_until = datetime_converter(form.get('dateuntilpost'))
    db.session.commit()
    return post
Ejemplo n.º 16
0
def create_a_post(form):
    user_id = session.get("user_id", "") if session.get("logged_in", False) else -1
    title_post = form.get('titlepost')
    descr_post = form.get('descriptionpost')
    link_post = form.get('linkurlpost')
    image_post = form.get('imagepost')
    date_from = datetime_converter(form.get('datefrompost'))
    date_until = datetime_converter(form.get('dateuntilpost'))
    p = Post(user_id=user_id, title=title_post, description=descr_post, link_url=link_post, image_url=image_post,
             date_from=date_from, date_until=date_until)
    db.session.add(p)
    db.session.commit()
    return p
Ejemplo n.º 17
0
def test_view_publishing(client):
    login(client, 'myself')
    post, chan, pub = create(client)

    response = get_view_publishing(client, post, chan)
    assert response.status_code == 200

    pub.date_until = datetime_converter(pub.date_until)
    pub.date_from = datetime_converter(pub.date_from)

    new_pub = db.session.query(Publishing).filter(
        Publishing.post_id == post.id,
        Publishing.channel_id == chan.id).first()
    assert new_pub.state == pub.state and new_pub.title == pub.title and new_pub.description == pub.description
Ejemplo n.º 18
0
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'))
Ejemplo n.º 19
0
def create_a_publishing(post, chn, form):
    chan = str(chn.name)
    title_post = form.get(chan + '_titlepost') if (form.get(chan + '_titlepost') is not None) else post.title
    chn.count += 1  # TODO (team02) find utility
    user_id = session.get("user_id", "") if session.get("logged_in", False) else -1

    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

    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
    date_from = datetime_converter(form.get(chan + '_datefrompost')) if datetime_converter(
        form.get(chan + '_datefrompost')) is not None else post.date_from
    date_until = datetime_converter(
        form.get(chan + '_dateuntilpost')) if datetime_converter(
        form.get(chan + '_dateuntilpost')) is not None else post.date_until
    pub = Publishing(post_id=post.id, user_id=user_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)

    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
        # TEAM6: MODIFICATION FOR PDF
        if str(plugin_name).endswith("pdf"):
            c_conf = c.config
            from importlib import import_module
            plugin = import_module(plugin_name)
            plugin.run(pub, c_conf)
            # Does not save the pdf posts
            return pub
        # END OF MODIFICATION

    if is_gcal_channel(chan) and not gcal_plugin.is_valid(pub):
       return None
    if is_gcal_channel(chan):
        generate_google_user_credentials(chan)

    db.session.add(pub)
    db.session.commit()
    return pub
Ejemplo n.º 20
0
def test_view_feedback(client):
    login(client, 'myself')
    post, chan, pub = create(client)

    response = post_validate_publishing(client, post, chan, "")
    assert response.status_code == 200

    response = get_view_feedback(client, post, chan)
    assert response.status_code == 200

    pub.date_from = datetime_converter(pub.date_from)
    pub.date_until = datetime_converter(pub.date_until)

    mod = db.session.query(Moderation).filter(
        Moderation.post_id == post.id,
        Moderation.channel_id == chan.id).first()
    assert mod.message == ""
Ejemplo n.º 21
0
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)
Ejemplo n.º 22
0
def test_delete_publishing(client):
    user_id = "myself"
    login(client, user_id)

    title_post = "title_test"
    descr_post = "description"
    link_post = "link"
    image_post = "img"
    date_from = datetime_converter("2018-01-01")
    date_until = datetime_converter("2018-01-10")
    p = Post(user_id=user_id, title=title_post, description=descr_post, link_url=link_post, image_url=image_post,
             date_from=date_from, date_until=date_until)
    db.session.add(p)
    db.session.commit()

    id_post = p.id
    id_channel = 1

    # Try with a publishing submitted for review (state=0)
    pub1 = Publishing(post_id=id_post, channel_id=id_channel, state=0, title=title_post, description=descr_post,
                     link_url=link_post, image_url=image_post, date_from=date_from, date_until=date_until)
    db.session.add(pub1)
    db.session.commit()

    path = '/delete_publishing/' + str(id_post) + '/' + str(id_channel)

    client.get(path)

    deleted_publishing = db.session.query(Publishing).filter(Publishing.post_id == id_post).first()
    assert deleted_publishing is None

    # Try with a publishing already posted (state=1)
    pub2 = Publishing(post_id=id_post, channel_id=id_channel, state=1, title=title_post, description=descr_post,
                      link_url=link_post, image_url=image_post, date_from=date_from, date_until=date_until)
    db.session.add(pub2)
    db.session.commit()

    path = '/delete_publishing/' + str(id_post) + '/' + str(id_channel)

    client.get(path)

    deleted_publishing = db.session.query(Publishing).filter(Publishing.post_id == id_post).first()
    assert deleted_publishing is None

    db.session.delete(p)
    db.session.commit()
Ejemplo n.º 23
0
def create_a_publishing_edit(post, chn, data):
    """
    This method is used in publish_edit_post in order to generate a publication.
    Since the request used in publish_edit_post is different than the request in create_a_publishing in post.py, this
    methode had the same behaviour but instead of using a request.form we use a request.get_json
    :param post : the post linked to the publication, chn : the channel used for the publication, data : data used to
    make the publishing
    :return: the publishing
    """
    field = data.get('fields')
    title_post = field.get('title') if (field.get('title') is not None) else post.title
    descr_post = field.get('description') if field.get('description') is not None else post.description
    link_post = field.get('link_url') if field.get('link_url') is not None else post.link_url
    image_post = field.get('image_url') if field.get('image_url') is not None else post.image_url

    if field.get('date_from') is '':
        date_from = date.today()
    else:
        date_from = datetime_converter(field.get('date_from')) if datetime_converter(
            field.get('date_from')) is not None else post.date_from
    if field.get('date_until') is '':
        date_until = date.today() + timedelta(days=7)
    else:
        date_until = datetime_converter(field.get('date_until')) if datetime_converter(
            field.get('date_until')) is not None else post.date_until
    if chn.module == 'superform.plugins.ICTV':
        logo = field.get('logo')
        subtitle = field.get('subtitle')
        duration = field.get('duration')

        pub = Publishing(user_id=session.get("user_id", ""), 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, logo=logo, subtitle=subtitle, duration=duration)
    else:
        pub = Publishing(user_id=session.get("user_id", ""), 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)

    db.session.add(pub)
    db.session.commit()
    return pub
Ejemplo n.º 24
0
def setup_db(channelName, pluginName):
    global user_admin
    myself_user = db.session.query(User).get('myself')
    if not myself_user:
        myself_user = create_user(id="myself",
                                  name="myself",
                                  first_name="myself",
                                  email="myself")
    user_admin = myself_user.admin
    myself_user.admin = 1

    id_channel = 0

    channel = Channel(id=id_channel,
                      name=channelName,
                      module=pluginName,
                      config="{}")
    db.session.add(channel)
    authorization = Authorization(user_id="myself",
                                  channel_id=id_channel,
                                  permission=2)
    db.session.add(authorization)

    id_post = 0

    post = Post(
        id=id_post,
        user_id="myself",
        title="first title",
        description=
        "That know ask case sex ham dear her spot. Weddings followed the all marianne nor whatever settling. Perhaps six prudent several her had offence. Did had way law dinner square tastes. Recommend concealed yet her procuring see consulted depending. Adieus hunted end plenty are his she afraid. Resources agreement contained propriety applauded neglected use yet. ",
        link_url="http://facebook.com/",
        image_url="pas",
        date_from=datetime_converter("2018-07-01"),
        date_until=datetime_converter("2018-07-01"))
    db.session.add(post)

    try:
        db.session.commit()
    except Exception as e:
        print(str(e))
        db.session.rollback()
    return id_channel, id_post
Ejemplo n.º 25
0
def create_a_resubmit_publishing(pub, chn, form):
    user_id = session.get("user_id", "") if session.get("logged_in", False) else -1
    title_post = form.get('titlepost')
    descr_post = form.get('descrpost')
    link_post = form.get('linkurlpost')
    image_post = form.get('imagepost')
    date_from = datetime_converter(form.get('datefrompost'))
    date_until = datetime_converter(form.get('dateuntilpost'))
    start_hour = time_converter(form.get('starthour'))
    end_hour = time_converter(form.get('endhour'))

    latest_version_publishing = db.session.query(Publishing).filter(Publishing.post_id == pub.post_id,
                                                                    Publishing.channel_id == chn.id).order_by(
        Publishing.num_version.desc()
    ).first()
    new_pub = Publishing(num_version=latest_version_publishing.num_version + 1, post_id=pub.post_id, channel_id=chn.id,
                         state=State.NOT_VALIDATED.value, user_id=user_id, 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)
    return new_pub
Ejemplo n.º 26
0
def create_a_post(form):  # called in publish_from_new_post() & new_post()
    user_id = session.get("user_id", "") if session.get("logged_in", False) else -1
    title_post = form.get('titlepost')
    descr_post = form.get('descriptionpost')
    link_post = form.get('linkurlpost')
    image_post = form.get('imagepost')
    if form.get('datefrompost') is '':
        # set default date if no date was chosen
        date_from = date.today()
    else:
        date_from = datetime_converter(form.get('datefrompost'))
    if form.get('dateuntilpost') is '':
        date_until = date.today() + timedelta(days=7)
    else:
        date_until = datetime_converter(form.get('dateuntilpost'))
    p = Post(user_id=user_id, title=title_post, description=descr_post, link_url=link_post, image_url=image_post,
             date_from=date_from, date_until=date_until)
    db.session.add(p)
    db.session.commit()
    return p
Ejemplo n.º 27
0
def create_a_publishing(post, chn, form):
    chan = str(chn.name)
    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
    date_from = datetime_converter(
        form.get(chan + '_datefrompost')) if datetime_converter(
            form.get(chan + '_datefrompost')) is not None else post.date_from
    date_until = datetime_converter(
        form.get(chan + '_dateuntilpost')) if datetime_converter(
            form.get(chan + '_dateuntilpost')) is not None else post.date_until

    extra = dict()
    plugin_name = chn.module
    from importlib import import_module
    plugin = import_module(plugin_name)

    if 'get_channel_fields' in dir(plugin):
        extra = plugin.get_channel_fields(form, chan)

    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,
                     extra=json.dumps(extra))

    db.session.add(pub)
    db.session.commit()
    return pub
Ejemplo n.º 28
0
def test_refuse_publishing_without_feedback(client):
    login(client, 'myself')
    post, chan, pub = create(client)

    response = post_refuse_publishing(client, post, chan, "")
    assert response.status_code == 200

    pub.date_from = datetime_converter(pub.date_from)
    pub.date_until = datetime_converter(pub.date_until)

    pub1 = db.session.query(Publishing).filter(
        Publishing.post_id == post.id
        and Publishing.channel_id == chan.id).first()
    assert pub1.state == State.NOTVALIDATED.value

    mod = db.session.query(Moderation).filter(
        Moderation.channel_id == chan.id,
        Moderation.post_id == post.id).first()
    assert mod is None

    path = root + "-1.xml"
    del_file([path])
Ejemplo n.º 29
0
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 test_modif_post(client):
    login(client, "myself")
    post, chan, pub = prefill_db(client)
    data1 = {
        'datefrompost': '2021-01-01',
        'dateuntilpost': '2021-01-01',
        'descriptionpost': post.description,
        'titlepost': 'new title',
        'linkurlpost': post.link_url,
        'imagepost': post.image_url
    }
    rv = client.post('/publish/edit/' + str(post.id),
                     data=data1,
                     follow_redirects=True)
    assert rv.status_code == 200
    po = db.session.query(Post).filter(Post.id == post.id).first()
    assert po.date_from == datetime_converter('2021-01-01')
    assert po.date_until == datetime_converter('2021-01-01')
    assert po.description == post.description
    assert po.title == 'new title'
    assert po.link_url == post.link_url
    assert po.image_url == post.image_url