Exemplo n.º 1
0
def admin_userfeeds():
    """ Present menu page of user account feed related options """

    feeds = UFeeds.all_list()
    return render_template(
        "admin_user_feeds.html",
        feeds=feeds
    )
Exemplo n.º 2
0
def admin_userfeeds():
    """ Present menu page of user account feed related options """

    feeds = UFeeds.all_list()
    return render_template(
        "admin_user_feeds.html",
        feeds=feeds
    )
Exemplo n.º 3
0
def users_update_from_feed(upids):
    """ Given a list of upids, go through and try to fetch details from
        feed, updating/creating the accounts if needed.
    """
    for upid in upids:
        user_id = Users2.uid_by_uname(upid)
        if not user_id:  # we don't know who they are, so create them.
            for feed in UFeeds.all_list():

                try:
                    out = feeds_run_user_script(feed.script, args=[upid, ])
                except BaseException as err:
                    L.error("Exception in user feed '%s': %s" % (feed.script, err))
                    continue

                res = out.splitlines()
                if res[0].startswith("ERROR"):
                    L.error("Error running user feed '%s': %s" % (feed.script, res))
                    continue

                line = res[1]
                studentid = ""
                try:
                    (upid, name, email, studentid) = line.split(',')

                except ValueError:
                    try:
                        (upid, name, email) = line.split(',')
                    except ValueError:
                        continue

                given = name.split(" ")[0]
                try:
                    family = " ".join(name.split(" ")[1:])
                except ValueError:
                    family = ""
                Users2.create(upid,
                              '',
                              given,
                              family,
                              2,
                              studentid,
                              email,
                              None,
                              'feed',
                              '',
                              True)
                break
        else:
            L.error("Error running user feed for existing account %s" % user_id)
    return
Exemplo n.º 4
0
def users_update_from_feed(upids):
    """ Given a list of upids, go through and try to fetch details from
        feed, updating/creating the accounts if needed.
    """
    for upid in upids:
        user_id = Users2.uid_by_uname(upid)
        if not user_id:  # we don't know who they are, so create them.
            for feed in UFeeds.all_list():

                try:
                    out = feeds_run_user_script(feed.script, args=[upid, ])
                except BaseException as err:
                    L.error("Exception in user feed '%s': %s" % (feed.script, err))
                    continue

                res = out.splitlines()
                if res[0].startswith("ERROR"):
                    L.error("Error running user feed '%s': %s" % (feed.script, res))
                    continue

                line = res[1]
                studentid = ""
                try:
                    (upid, name, email, studentid) = line.split(',')

                except ValueError:
                    try:
                        (upid, name, email) = line.split(',')
                    except ValueError:
                        continue

                given = name.split(" ")[0]
                try:
                    family = " ".join(name.split(" ")[1:])
                except ValueError:
                    family = ""
                Users2.create(upid,
                              '',
                              given,
                              family,
                              2,
                              studentid,
                              email,
                              None,
                              'feed',
                              '',
                              True)
                break
        else:
            L.error("Error running user feed for existing account %s" % user_id)
    return
Exemplo n.º 5
0
def admin_edit_userfeed(feed_id):
    """ Present page to edit a user feed in the system """
    try:
        feed = UFeeds.UFeed(f_id=feed_id)
    except KeyError:
        return abort(404)
    try:
        scripts = External.feeds_available_user_scripts()
    except OSError as err:
        flash(err)
        scripts = []
    return render_template(
        "admin_edit_user_feed.html",
        feed=feed,
        scripts=scripts
    )
Exemplo n.º 6
0
def user_update_details_from_feed(uid, upid):
    """ Refresh the user's details from feed. Maybe their name or ID changed.
    """
    for feed in UFeeds.all_list():
        try:
            out = feeds_run_user_script(feed.script, args=[upid, ])
        except BaseException as err:
            L.error("Exception running user feed '%s': %s" % (feed.script, err))
            continue

        res = out.splitlines()
        if res[0].startswith("ERROR"):
            L.error("Error running user feed '%s': %s" % (feed.script, res))
            continue

        line = res[1]
        studentid = ""
        try:
            (upid, name, email, studentid) = line.split(',')

        except ValueError:
            try:
                (upid, name, email) = line.split(',')
            except ValueError:
                continue

        given = name.split(" ")[0]
        try:
            family = " ".join(name.split(" ")[1:])
        except ValueError:
            family = ""

        Users.set_email(uid, email)
        Users.set_givenname(uid, given)
        Users.set_familyname(uid, family)
        Users.set_studentid(uid, studentid)
Exemplo n.º 7
0
def user_update_details_from_feed(uid, upid):
    """ Refresh the user's details from feed. Maybe their name or ID changed.
    """
    for feed in UFeeds.all_list():
        try:
            out = feeds_run_user_script(feed.script, args=[upid, ])
        except BaseException as err:
            L.error("Exception running user feed '%s': %s" % (feed.script, err))
            continue

        res = out.splitlines()
        if res[0].startswith("ERROR"):
            L.error("Error running user feed '%s': %s" % (feed.script, res))
            continue

        line = res[1]
        studentid = ""
        try:
            (upid, name, email, studentid) = line.split(',')

        except ValueError:
            try:
                (upid, name, email) = line.split(',')
            except ValueError:
                continue

        given = name.split(" ")[0]
        try:
            family = " ".join(name.split(" ")[1:])
        except ValueError:
            family = ""

        Users.set_email(uid, email)
        Users.set_givenname(uid, given)
        Users.set_familyname(uid, family)
        Users.set_studentid(uid, studentid)
Exemplo n.º 8
0
def admin_edit_user_feed_submit(feed_id):
    """ Submit edit user feed form """
    if "cancel" in request.form:
        flash("Edit cancelled!")
        return redirect(url_for("admin_userfeeds"))

    name = request.form.get('name', '')
    title = request.form.get('title', '')
    script = request.form.get('script', '')
    envvar = request.form.get('envvar', '')
    comments = request.form.get('comments', '')
    freq = int(request.form.get('freq', 1))
    priority = int(request.form.get('priority', 1))
    regex = request.form.get('regex', '')
    active = request.form.get('active', 'inactive') == 'active'

    if feed_id == 0:  # It's a new one being created
        feed = UFeeds.UFeed(
            f_id=0,
            name=name,
            title=title,
            script=script,
            envvar=envvar,
            comments=comments,
            freq=freq,
            active=active,
            priority=priority,
            regex=regex
        )
    else:
        try:
            feed = UFeeds.UFeed(f_id=feed_id)
        except KeyError:
            return abort(404)

    feed.id = feed_id
    feed.name = name
    feed.title = title
    feed.script = script
    feed.envvar = envvar
    feed.comments = comments
    feed.freq = freq
    feed.active = active
    feed.priority = priority
    feed.regex = regex

    if name == "":
        flash("Can't Save: Name must be supplied")
        return render_template(
            "admin_edit_user_feed.html",
            feed=feed
        )
    try:
        feed.save()
    except ValueError as err:  # Probably a duplicate or something
        flash("Can't Save: %s" % err)
        return render_template(
            "admin_edit_user_feed.html",
            feed=feed
        )
    flash("Changes saved", category='success')
    return redirect(url_for("admin_userfeeds"))