Exemple #1
0
def configure_channel(id):
    c = Channel.query.get(id)
    m = c.module
    clas = get_instance_from_module_path(m)
    config_fields = clas.CONFIG_FIELDS

    if request.method == 'GET':
        if (c.config is not ""):
            d = ast.literal_eval(c.config)
            setattr(c, "config_dict", d)
        return render_template("channel_configure.html", channel=c, config_fields=config_fields)
    '''
    str_conf = "{"
    cfield = 0
    for field in config_fields:
        if cfield > 0:
            str_conf += ","
        str_conf += "\'" + field + "\' : \'" + request.form.get(field) + "\'"
        cfield += 1
    str_conf += "}"
    c.config = str_conf
    '''
    cfg = {}
    for field in config_fields:
        cfg[field] = request.form.get(field)
    c.config = json.dumps(cfg)
    db.session.commit()
    return redirect(url_for('channels.channel_list'))
def configure_channel(id):
    c = Channel.query.get(id)
    m = c.module
    clas = get_instance_from_module_path(m)
    config_fields = clas.CONFIG_FIELDS

    if request.method == 'GET':
        if (c.config is not ""):
            d = ast.literal_eval(c.config)
            setattr(c, "config_dict", d)
        return render_template("channel_configure.html",
                               channel=c,
                               config_fields=config_fields,
                               archival_f_dict=FREQUENCIES,
                               archival_f=c.archival_frequency,
                               archival_d=c.archival_date)
    str_conf = "{"
    cfield = 0
    for field in config_fields:
        if cfield > 0:
            str_conf += ","
        str_conf += "\"" + field + "\" : \"" + request.form.get(field) + "\""
        cfield += 1
    str_conf += "}"
    c.config = str_conf
    # Archival Module :
    arch_config = configure_job_from_form(id, request.form)
    if arch_config:
        c.archival_frequency = arch_config[0]
        if arch_config[0] != -1:
            c.archival_date = arch_config[1]
    # End of Archival Module
    db.session.commit()
    return redirect(url_for('channels.channel_list'))
Exemple #3
0
def new_post():
    user_id = session.get("user_id", "") if session.get("logged_in",
                                                        False) else -1
    list_of_channels = channels_available_for_user(user_id)
    extraForms = {}
    for elem in list_of_channels:
        m = elem.module
        plugin = import_module(m)
        extraForms[elem.name] = plugin.get_template_new()
        clas = get_instance_from_module_path(m)
        unaivalable_fields = ','.join(clas.FIELDS_UNAVAILABLE)
        setattr(elem, "unavailablefields", unaivalable_fields)

    if request.method == "GET":

        post_form_validations = dict()

        print(post_form_validations)
        return render_template('new.html',
                               extra_forms=extraForms,
                               l_chan=list_of_channels,
                               post_form_validations=post_form_validations)
    else:
        create_a_post(request.form)
        return redirect(url_for('index'))
def new_post():
    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)

    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)

        return render_template('new.html',
                               l_chan=list_of_channels,
                               ictv_data=ictv_data,
                               new=True)
    else:
        # Save as draft
        # FIXME Maybe refactor the code so that this part is not too confusing?
        create_a_post(request.form)
        flash("The post was successfully saved as draft", category='success')
        return redirect(url_for('index'))
Exemple #5
0
def configure_channel(id):
    c = Channel.query.get(id)
    m = c.module
    clas = get_instance_from_module_path(m)
    config_fields = clas.CONFIG_FIELDS

    if request.method == 'GET':
        if c.config is not "":
            d = ast.literal_eval(c.config)
            setattr(c, "config_dict", d)
        try:
            return clas.render_specific_config_page(c, config_fields)
        except AttributeError:
            return render_template("channel_configure.html", channel=c, config_fields=config_fields)
    str_conf = "{"
    cfield = 0
    for field in config_fields:
        if cfield > 0:
            str_conf += ","
        str_conf += "\"" + field + "\" : \"" + request.form.get(field) + "\""
        cfield += 1
    str_conf += "}"
    c.config = str_conf
    db.session.commit()
    return redirect(url_for('channels.channel_list'))
Exemple #6
0
def configure_channel(id):
    c = Channel.query.get(id)
    m = c.module
    clas = get_instance_from_module_path(m)
    config_fields = clas.CONFIG_FIELDS
    if request.method == 'GET':
        if c.config is not "":
            d = ast.literal_eval(c.config)
            setattr(c, "config_dict", d)
            # TEAM06: addition for LinkedIn plugin
            if str(m) == "superform.plugins.LinkedIn":
                last_status = request.cookies.get(LAST_STATUS)
                return linkedin_plugin(id, c, config_fields, last_status)
            # TEAM06: addition for pdf feature
            if str(m) == 'superform.plugins.pdf':
                return pdf_plugin(id, c, config_fields)
            # TEAM06: end addition

        return render_template("channel_configure.html", channel = c,
                               config_fields = config_fields)
    str_conf = "{"
    cfield = 0
    for field in config_fields:
        if cfield > 0:
            str_conf += ","

        # TEAM06: changes for the pdf feature
        if str(m) == "superform.plugins.pdf":
            if field == "Format":
                str_conf += "\"" + field + "\" : \"" + request.form['format'] + "\""
            else:
                str_conf += "\"" + field + "\" : \"" + request.form[
                    'logo'] + "\""
            print('field=%s\nstr_conf=%s' %(field,str_conf))
        else:
            str_conf += "\"" + field + "\" : \"" + request.form.get(field) + "\""
        # TEAM06: end changes
        cfield += 1

    # If any LinkedIn session cookie is present we add them to the
    # data-base.

    last_access_token = request.cookies.get(LAST_ACCESS_TOKEN)
    last_creation_time = request.cookies.get(LAST_CREATION_TIME)
    last_channel_id = request.cookies.get(LAST_CHANNEL_ID)

    if str(m) == "superform.plugins.LinkedIn" and str(last_channel_id) == str(
            id) and last_access_token is not None and last_creation_time is not None:
        print("Saving LinkedIn channel data")
        if cfield > 0:
            str_conf += ","
        str_conf += "\"" + "token" + "\" : \"" + last_access_token + "\""
        str_conf += ","
        str_conf += "\"" + "creationTime" + "\" : \"" + last_creation_time + "\""
        cfield = cfield + 2
    str_conf += "}"
    c.config = str_conf
    db.session.commit()
    return redirect(url_for('channels.channel_list'))
Exemple #7
0
def get_post_form_validations():
    mods = get_modules_names(current_app.config["PLUGINS"].keys())
    post_form_validations = dict()
    for m in mods:
        full_name = get_module_full_name(m)
        clas = get_instance_from_module_path(full_name)
        fields = clas.POST_FORM_VALIDATIONS
        post_form_validations[m] = fields
    return post_form_validations
Exemple #8
0
def display_rss_feed(id):
    c = Channel.query.get(id)
    if c is None or c.module != "superform.plugins.rss":
        return render_template("404.html")
    clas = get_instance_from_module_path('superform.plugins.rss')
    config_fields = clas.CONFIG_FIELDS
    d = {}  # ['channel_title', 'channel_description', 'channel_author']
    if c.config is not "":
        d = ast.literal_eval(c.config)

    Pubdb = db.session.query(Publishing).filter(Publishing.channel_id == id)
    items = []
    for Publi in Pubdb:
        if Publi.state == 1 and Publi.date_from <= datetime.now(
        ) <= Publi.date_until:  # check if send
            author = db.session.query(Post).filter(
                Post.id == Publi.post_id).first()
            item1 = Item(
                title=Publi.title,
                link=Publi.image_url,
                description=Publi.description,
                author=author,  # channel_config['channel_author'],
                guid=Guid(Publi.link_url),
                pubDate=Publi.date_from)  # datetime(2017, 8, 1, 4, 0))
            items.append(item1)

    feed = Feed(
        title=d['channel_title'],  # channel name
        link='',  # channel_config['channel_location'],
        description=d[
            'channel_description'],  # channel_config['channel_decription'],
        language="en-US",
        lastBuildDate=datetime.now(),
        items=items)

    generated_file = feed.rss()

    proxy = io.StringIO()
    proxy.write(generated_file)

    mem = io.BytesIO()
    mem.write(proxy.getvalue().encode('utf-8'))

    mem.seek(0)
    proxy.close()

    return send_file(mem,
                     as_attachment=True,
                     attachment_filename='feed.xml',
                     mimetype='text/xml')
def new_post():
    user_id = session.get("user_id", "") if session.get("logged_in", False) else -1
    list_of_channels = channels_available_for_user(user_id)
    for elem in list_of_channels:
        m = elem.module
        clas = get_instance_from_module_path(m)
        unaivalable_fields = ','.join(clas.FIELDS_UNAVAILABLE)
        setattr(elem, "unavailablefields", unaivalable_fields)

    if request.method == "GET":
        return render_template('new.html', l_chan=list_of_channels)
    else:
        create_a_post(request.form)
        return redirect(url_for('index'))
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'))
Exemple #11
0
def new_post(dial_data=None):
    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)

    if request.method == "GET" or dial_data is not None:  # when clicking on the new post tab
        ictv_data = None
        if len(ictv_chans) != 0:
            from superform.plugins.ictv import process_ictv_channels
            ictv_data = process_ictv_channels(ictv_chans)

        # set default date
        default_date = {'from': date.today(), 'until': date.today() + timedelta(days=7)}
        post_form_validations = get_post_form_validations()

        # dial
        dial_title = ""
        dial_description = ""
        dial_link = ""
        if dial_data is not None:
            dial_title = dial_data[0]
            dial_description = dial_data[1]
            dial_link = dial_data[2]

        return render_template('new.html', l_chan=list_of_channels, ictv_data=ictv_data,
                               post_form_validations=post_form_validations,
                               date=default_date, dial_title=dial_title, dial_description=dial_description,
                               dial_link=dial_link)
    else:
        # Save as draft
        create_a_post(request.form)
        flash("The post was successfully saved as draft", category='success')
        return redirect(url_for('index'))
Exemple #12
0
def configure_channel(id):
    c = Channel.query.get(id)
    m = c.module
    clas = get_instance_from_module_path(m)
    config_fields = clas.CONFIG_FIELDS

    if request.method == 'GET':
        if c.config is not "":
            d = ast.literal_eval(c.config)
            setattr(c, "config_dict", d)
            # TEAM 06: pdf custom config page
            # TEAM 07 facebook/linkedin custom config page
            if str(m) == 'superform.plugins.pdf':
                return pdf_plugin(id, c, config_fields)
            elif str(m) == 'superform.plugins.facebook' or str(m) == 'superform.plugins.linkedin':
                return clas.render_specific_config_page(c, config_fields)
            else:
                return render_template("channel_configure.html", channel=c, config_fields=config_fields)
            # TEAM 06: end addition
            # TEAM 07

    str_conf = "{"
    cfield = 0
    for field in config_fields:
        if cfield > 0:
            str_conf += ","

        # TEAM06: changes for the pdf feature
        if str(m) == "superform.plugins.pdf":
            if field == "Format":
                str_conf += "\"" + field + "\" : \"" + request.form['format'] + "\""
            else:
                str_conf += "\"" + field + "\" : \"" + request.form[
                    'logo'] + "\""
        else:
            str_conf += "\"" + field + "\" : \"" + request.form.get(field) + "\""
        # TEAM06: end changes
        cfield += 1
    str_conf += "}"
    c.config = str_conf
    db.session.commit()
    return redirect(url_for('channels.channel_list'))
def new_post():
    user_id = session.get("user_id", "") if session.get("logged_in",
                                                        False) else -1
    module = []
    list_of_channels = channels_available_for_user(user_id)
    for elem in list_of_channels:
        module = {"name": elem.name, "module": elem.module}
        m = elem.module
        clas = get_instance_from_module_path(m)
        unaivalable_fields = ','.join(clas.FIELDS_UNAVAILABLE)
        setattr(elem, "unavailablefields", unaivalable_fields)

    if request.method == "GET":
        #v = db.session.query(Channel).filter(Channel.name == elem.channel_id).first()
        return render_template('new.html',
                               l_chan=list_of_channels,
                               modules=module)
    else:
        create_a_post(request.form)
        return redirect(url_for('archival.update_now'))
Exemple #14
0
def new_post():
    user_id = session.get("user_id", "") if session.get("logged_in", False) else -1
    list_of_channels = channels_available_for_user(user_id)
    extraForms = {}
    for elem in list_of_channels:
        m = elem.module
        plugin = import_module(m)
        extraForms[elem.name] = plugin.get_template_new()
        clas = get_instance_from_module_path(m)
        unavailable_fields = ','.join(clas.FIELDS_UNAVAILABLE)
        setattr(elem, "unavailablefields", unavailable_fields)
        setattr(elem, "plugin_name", str(m))

    if request.method == "GET":  # when clicking on the new post tab
        # set default date
        default_date = {'from': date.today(), 'until': date.today() + timedelta(days=7)}

        post_form_validations = get_post_form_validations()

        return render_template('new.html', extra_forms=extraForms, l_chan=list_of_channels, post_form_validations=post_form_validations,
                               date=default_date)
    else:
        create_a_post(request.form)
        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 channel_list():
    if request.method == "POST":
        action = request.form.get('@action', '')
        if action == "new":
            name = request.form.get('name')
            username = request.form.get('username')
            password = request.form.get('password')
            module = request.form.get('module')
            if module in get_modules_names(
                    current_app.config["PLUGINS"].keys()):
                channel = Channel(name=name,
                                  module=get_module_full_name(module),
                                  config="{}")
                db.session.add(channel)
                db.session.flush()
                keepass.set_entry_from_data(str(channel.id), username,
                                            password)
                keepass.add_entry_in_group(module)
                db.session.commit()

        elif action == "delete":
            channel_id = request.form.get("id")
            channel = Channel.query.get(channel_id)
            if channel:
                db.session.delete(channel)
                db.session.commit()
                keepass.delete_entry(channel_id)
        elif action == "edit":
            channel_id = request.form.get("id")
            channel = Channel.query.get(channel_id)
            name = request.form.get('name')
            username = request.form.get('username')
            password = request.form.get('password')
            if name is not '':
                channel.name = name
                conf = json.loads(channel.config)
                conf["channel_name"] = name
                channel.config = json.dumps(conf)
                db.session.commit()
            if username is not '' or password is not '':
                keepass.set_entry_from_data(str(channel.id), username,
                                            password)
                keepass.modify_entry_in_group(
                    get_modules_names([channel.module])[0], channel.id)

    channels = Channel.query.all()
    mods = get_modules_names(current_app.config["PLUGINS"].keys())

    auth_fields = dict()

    for m in mods:
        full_name = get_module_full_name(m)
        clas = get_instance_from_module_path(full_name)
        fields = clas.AUTH_FIELDS
        auth_fields[m] = fields

    return render_template("channels.html",
                           channels=channels,
                           modules=get_modules_names(
                               current_app.config["PLUGINS"].keys()),
                           auth_fields=auth_fields)