예제 #1
0
파일: app.py 프로젝트: ngonhi/lmfdb-1
def add_colors():
    # FIXME:
    # - the template should use global variable g.color
    # - try to get the color from
    #       - the cookie
    #       - from the config file
    # - remove cookie at logout (see line 307 of users/main)
    # - add cookie at login or when a color change happens (see line 175 of users/main)
    from lmfdb.utils.color import all_color_schemes
    color = request.args.get('color')
    if color and color.isdigit():
        color = int(color)
    if color not in all_color_schemes:
        color = None
    if color is None:
        from flask_login import current_user
        userid = current_user.get_id()
        if userid is not None:
            from lmfdb.users.pwdmanager import userdb
            color = userdb.lookup(userid).get('color_scheme')
        if color not in all_color_schemes:
            color = None
        if color is None:
            from lmfdb.utils.config import Configuration
            color = Configuration().get_color()
    return dict(color=all_color_schemes[color].dict())
예제 #2
0
 def last_author(self):
     """
     Full names for the last authors.
     (lookup for all full names in just *one* query, hence the or)
     """
     if not self._last_author:
         return ""
     return userdb.lookup(self._last_author)["full_name"]
예제 #3
0
파일: knowl.py 프로젝트: davidfarmer/lmfdb
 def last_author(self):
     """
     Full names for the last authors.
     (lookup for all full names in just *one* query, hence the or)
     """
     if not self._last_author:
         return ""
     return userdb.lookup(self._last_author)["full_name"]
예제 #4
0
파일: main.py 프로젝트: tomgrubbmath/lmfdb
def show(ID):
    timestamp = request.args.get('timestamp')
    if timestamp is not None:
        timestamp = timestamp_in_ms_to_datetime(timestamp)
    k = Knowl(ID, timestamp=timestamp, showing=True)
    if k.exists():
        r = render_knowl(ID, footer="0", raw=True)
        title = k.title or "'%s'" % k.id
        if not is_beta():
            if k.status == 0:
                title += " (awaiting review)"
            else:
                title += " (reviewed)"
    else:
        if current_user.is_admin() and k.exists(allow_deleted=True):
            k = Knowl(ID, showing=True, allow_deleted=True)
            r = render_knowl(ID, footer="0", raw=True, allow_deleted=True)
            title = (k.title or "'%s'" % k.id) + " (DELETED)"
        else:
            return abort(404, "No knowl found with the given id")
    for elt in k.edit_history:
        # We will be printing these within a javascript ` ` string
        # so need to escape backticks
        elt['content'] = json.dumps(elt['content'])
    # Modify the comments list to add information on whether this user can delete
    if k.type != -2:
        for i, (cid, author, timestamp) in enumerate(k.comments):
            can_delete = (current_user.is_admin()
                          or current_user.get_id() == author)
            author_name = userdb.lookup(author)["full_name"]
            k.comments[i] = (cid, author_name, timestamp, can_delete)
    if k.type == 2:
        caturl = url_for('.index', category=k.category, column="on")
    else:
        caturl = url_for('.index', category=k.category)
    b = get_bread([(k.category, caturl), ('%s' % title, url_for('.show',
                                                                ID=ID))])

    return render_template(u"knowl-show.html",
                           title=title,
                           k=k,
                           cur_username=current_user.get_id(),
                           render=r,
                           bread=b)
예제 #5
0
파일: app.py 프로젝트: davidfarmer/lmfdb
def add_colors():
    from lmfdb.utils.color import all_color_schemes
    color = request.args.get('color')
    if color and color.isdigit():
        color = int(color)
    if color not in all_color_schemes:
        color = None
    if color is None:
        from flask_login import current_user
        userid = current_user.get_id()
        if userid is not None:
            from lmfdb.users.pwdmanager import userdb
            color = userdb.lookup(userid).get('color_scheme')
        if color not in all_color_schemes:
            color = None
        if color is None:
            from lmfdb.utils.config import Configuration
            color = Configuration().get_color()
    return dict(color=all_color_schemes[color].dict())
예제 #6
0
파일: main.py 프로젝트: LMFDB/lmfdb
def show(ID):
    timestamp = request.args.get('timestamp')
    if timestamp is not None:
        timestamp = timestamp_in_ms_to_datetime(timestamp)
    k = Knowl(ID, timestamp=timestamp, showing=True)
    if k.exists():
        r = render_knowl(ID, footer="0", raw=True)
        title = k.title or "'%s'" % k.id
        if not is_beta():
            if k.status == 0:
                title += " (awaiting review)"
            else:
                title += " (reviewed)"
    else:
        if current_user.is_admin() and k.exists(allow_deleted=True):
            k = Knowl(ID, showing=True, allow_deleted=True)
            r = render_knowl(ID, footer="0", raw=True, allow_deleted=True)
            title = (k.title or "'%s'" % k.id) + " (DELETED)"
        else:
            return abort(404, "No knowl found with the given id")
    for elt in k.edit_history:
        # We will be printing these within a javascript ` ` string
        # so need to escape backticks
        elt['content'] = json.dumps(elt['content'])
    # Modify the comments list to add information on whether this user can delete
    if k.type != -2:
        for i, (cid, author, timestamp) in enumerate(k.comments):
            can_delete = (current_user.is_admin() or current_user.get_id() == author)
            author_name = userdb.lookup(author)["full_name"]
            k.comments[i] = (cid, author_name, timestamp, can_delete)
    b = get_bread([(k.category, url_for('.index', category=k.category)), ('%s' % title, url_for('.show', ID=ID))])

    return render_template(u"knowl-show.html",
                           title=title,
                           k=k,
                           cur_username=current_user.get_id(),
                           render=r,
                           bread=b)