Esempio n. 1
0
def category(category=None):
    results = [
        dict(name=row[0], desc=row[1], color=row[2], pic=row[3])
        for row in query_db(
            'SELECT Name, Description, Color, Picture FROM category where Name = ?',
            [category])
    ]

    articles = postmaker(
        query_db(
            'SELECT ID, Title, SafeTitle, AuthorID, Date, Category, Tags, CoverURL, CoverInfo, Description, Content FROM articles WHERE Category = ? ORDER BY ID DESC LIMIT ?',
            [category, numarticles[0]]))
    tags = taggin(
        query_db('SELECT Tags FROM articles WHERE Category = ?', [category]))

    amount = True if len(articles) == 0 else False

    if len(results) == 0 or len(results) > 1: return abort(404)

    return render_template('category.html',
                           categories=get_category(),
                           category=results[0],
                           article=articles,
                           amount=amount,
                           na=numarticles,
                           tags=tags,
                           args=','.join(['Category', results[0]['name']]))
Esempio n. 2
0
def about():
    #get authors
    authors = (
        dict(name=row[0], pic=row[1], desc=row[2])
        for row in query_db('SELECT Name, Picture, Description FROM users'))
    return render_template('about.html',
                           categories=get_category(),
                           authors=authors)
Esempio n. 3
0
def index():
    g = postmaker(
        query_db(
            'SELECT ID, Title, SafeTitle, AuthorID, Date, Category, Tags, CoverURL, CoverInfo, Description, Content FROM articles ORDER BY ID DESC LIMIT ?',
            [numarticles[0]]))
    tags = taggin(query_db('SELECT Tags FROM articles'))
    amount = True if len(g) == 0 else False

    #output everything
    return render_template('index.html',
                           results=g,
                           amount=amount,
                           categories=get_category(),
                           na=numarticles,
                           args=None,
                           tags=tags)
Esempio n. 4
0
def tags(tag=None):
    results = postmaker(
        query_db(
            'SELECT ID, Title, SafeTitle,AuthorID, Date, Category, Tags, CoverURL, CoverInfo, Description, Content FROM articles WHERE Tags LIKE ? ORDER BY ID DESC LIMIT ?',
            ['%' + tag + '%', numarticles[0]]))
    if len(results) == 0: return abort(404)
    articles = [result for result in results if str(tag) in result['tags']]

    amount = True if len(articles) == 0 else False

    return render_template('tag.html',
                           categories=get_category(),
                           tag=tag,
                           article=articles,
                           amount=amount,
                           na=numarticles,
                           args=','.join(['Tags', tag]))
Esempio n. 5
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)
Esempio n. 6
0
def policy():
    return render_template('policy.html', categories=get_category())
Esempio n. 7
0
def contact():
    return render_template('contact.html', categories=get_category())
Esempio n. 8
0
def projects():
    return render_template('projects.html', categories=get_category())
Esempio n. 9
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)