예제 #1
0
def postmaker(query):
    #get main info
    results = [
        dict(id=row[0],
             title=row[1],
             ctitle=row[2],
             author=row[3],
             date=dateit(row[4]).read,
             category=row[5],
             tags=row[6].split(','),
             pic=row[7],
             picinfo=row[8],
             desc=row[9]) for row in query
    ]

    #get num of comments for article and misc
    for row in results:
        row['comments'] = query_db(
            'SELECT COUNT(*) FROM comments WHERE ArticleID = ?',
            [row['id']])[0][0]
        row['author'] = [
            dict(name=ro[0], pic=ro[1])
            for ro in query_db('SELECT Name, Picture FROM users WHERE ID = ?',
                               [row['author']])
        ][0]  #clumsy way of selecting first row > array > name
        row['scategory'] = ''.join(e for e in row['category'] if e.isalnum())
        row['color'] = query_db('SELECT Color FROM category WHERE Name = ?',
                                [row['category']])

    return results
예제 #2
0
def index():
    if not session.get('user'): return redirect(url_for('pkd.login'))

    #get main info
    results = [
        dict(id=row[0],
             title=row[1],
             ctitle=row[2],
             author=row[3],
             date=dateit(row[4]).read,
             category=row[5],
             tags=row[6].split(','),
             pic=row[7],
             picinfo=row[8],
             desc=row[9])
        for row in query_db(
            'SELECT ID, Title, SafeTitle, AuthorID, Date, Category, Tags, CoverURL, CoverInfo, Description FROM articles ORDER BY ID DESC'
        )
    ]

    #get num of comments for article
    for row in results:
        row['comments'] = query_db(
            'SELECT COUNT(*) FROM comments WHERE ArticleID = ?',
            [row['id']])[0][0]
        row['author'] = query_db(
            'SELECT Name FROM users WHERE ID = ?',
            [row['author']
             ])[0][0]  #clumsy way of selecting first row > array > name

    #output everything
    return render_template('admin/index.html',
                           user=get_user(),
                           results=results)
예제 #3
0
def archives():
    g = [
        dict(id=row[0],
             name=row[1],
             cname=row[2],
             authorid=row[3],
             date=dateit(row[4]).read,
             year=dateit(row[4]).year,
             month=dateit(row[4]).month,
             monthnum=dateit(row[4]).monthnum,
             category=row[5],
             scategory=''.join(e for e in row[4] if e.isalnum()))
        for row in query_db(
            'SELECT ID, Title, SafeTitle, AuthorID, Date, Category FROM articles'
        )
    ]

    #----sort by date----#
    a = defaultdict(list)

    #sort by year > monthnum > id, and newest on top

    for d in sorted(g, key=itemgetter('year', 'monthnum', 'id'), reverse=True):
        #add to defaultdict with the key(year) => dictionary of results
        a[d['year']].append(d)

    #final default dict to be outputted
    q = defaultdict(list)
    #for each year in a (list of tuples) version of the default dict above
    for v in a.items():
        #new defaultdict for each month
        s = defaultdict(list)
        #for each dict in the year
        for e in v[1]:
            #create new default dict key(month) => dictionary of results (this is inside each year's dict!)
            s[e['month']].append(e)
        #add the results to the new defaultdict
        q[v[0]].append(s)
    #FIN~

    return render_template('archives.html',
                           categories=get_category(),
                           archives=q)
예제 #4
0
def edit(article=None):
    if not session.get('user'): return redirect(url_for('pkd.login'))

    if article == None: return redirect(url_for('pkd.index'))

    #get main article info
    results = [
        dict(id=row[0],
             title=row[1],
             author=row[2],
             date=dateit(row[3]).read,
             category=row[4],
             tags=row[5].split(','),
             pic=row[6],
             picinfo=row[7],
             desc=row[8],
             text=row[9])
        for row in query_db(
            'SELECT ID, Title, AuthorID, Date, Category, Tags, CoverURL, CoverInfo, Description, Text FROM articles WHERE Title = ?',
            [article.replace('_', ' ')])
    ]

    #check if article exists
    if len(results) == 0 or len(results) > 1: return abort(404)

    #get comments & author for article
    for row in results:
        row['comment'] = query_db(
            'SELECT COUNT(*) FROM comments WHERE ArticleID = ? ORDER BY ID DESC',
            [row['id']])[0][0]
        author = [
            dict(name=ro[0], pic=ro[1], desc=ro[2]) for ro in query_db(
                'SELECT Name, Picture, Description FROM users WHERE ID = ?',
                [row['author']])
        ]
        category = [
            dict(name=ro[0])
            for ro in query_db('SELECT (Name) FROM category ORDER BY ID DESC')
        ]

    #output everything
    return render_template('admin/editor.html',
                           hidden=True,
                           article=results[0],
                           title=results[0]['title'],
                           author=author[0],
                           user=get_user(),
                           category=category)
예제 #5
0
def article(category=None, article=None):
    if article == None: return redirect(url_for('category', category=category))

    #get main article info
    results = [
        dict(id=row[0],
             title=row[1],
             ctitle=row[2],
             author=row[3],
             date=dateit(row[4]).read,
             category=row[5],
             tags=row[6].split(','),
             pic=row[7],
             picinfo=row[8],
             desc=row[9],
             content=row[10])
        for row in query_db(
            'SELECT ID, Title, SafeTitle, AuthorID, Date, Category, Tags, CoverURL, CoverInfo, Description, Content FROM articles WHERE SafeTitle = ?',
            [article])
    ]

    #check if article exists
    if len(results) == 0 or len(results) > 1: return abort(404)

    #get comments for article THIS BETTER BE 1 ROW!
    for row in results:
        comments = [
            dict(id=ro[0],
                 name=ro[1],
                 date=dateit(ro[2]).read,
                 email=hashlib.md5(ro[3]).hexdigest(),
                 parent=ro[4],
                 level=ro[5],
                 comment=ro[6])
            for ro in query_db(
                'SELECT ID, Name, Date, Email, Parent, Level, Comment FROM comments WHERE ArticleID = ? ORDER BY ID DESC',
                [row['id']])
        ]
        row['comment'] = query_db(
            'SELECT COUNT(*) FROM comments WHERE ArticleID = ? ORDER BY ID DESC',
            [row['id']])[0][0]
        author = [
            dict(name=ro[0], pic=ro[1], desc=ro[2]) for ro in query_db(
                'SELECT Name, Picture, Description FROM users WHERE ID = ?',
                [row['author']])
        ]
        row['scategory'] = ''.join(e for e in row['category'] if e.isalnum())
        row['color'] = query_db('SELECT Color FROM category WHERE Name = ?',
                                [row['category']])[0][0]
        #related articles
        re = [
            dict(name=ro[0],
                 pic=ro[1],
                 tags=ro[2],
                 cname=ro[0].replace(' ', '_'),
                 category=ro[3])
            for ro in query_db(
                'SELECT Title, CoverURL, Tags, Category FROM articles WHERE Category = ?',
                [row['category']])
        ]
        related = []
        others = None
        g = [i.upper() for i in row['tags']]
        for r in re:
            cnt = 0
            for x in r['tags'].split(','):
                if x.upper() in g and r['name'] != row['title']:
                    cnt += 1
            if cnt >= 1:  #if at least 1 tag matched (set up like this so it can be adjusted later)
                related.append(r)
        if len(related) == 0:
            related = None
            others = [
                dict(name=ro[0],
                     pic=ro[1],
                     tags=ro[2],
                     cname=ro[0].replace(' ', '_'),
                     category=ro[3])
                for ro in query_db(
                    'SELECT Title, CoverURL, Tags, Category FROM articles WHERE Title != ? AND Category = ?',
                    [row['title'], row['category']])
            ]
            if len(others) == 0:
                others = None
    #sorting comments
    comments = commentsorter.popcomments(comments)

    #output everything
    return render_template('article.html',
                           categories=get_category(),
                           article=results[0],
                           title=results[0]['title'],
                           author=author[0],
                           related=related,
                           others=others,
                           comments=comments)