예제 #1
0
def simple_page(page=None, section=None):
    page_id = request.path.strip('/') if page else 'home'
    page = Page.get_latest(page_id)    
    try:
        return template('%s.html' % page_id, page=page)        
    except TemplateError:
        if not page:
            return abort(404, "Page not found")        
        return template('default.html', page=page, page_id=page_id)
예제 #2
0
def simple_page(page, section=None):
    template_context = c = dict(
        show_editor = True,
        page = Page.get_latest(g.page_id)
    )
    try:
        return template('%s.html' % g.page_id, **template_context)
    except TemplateError:
        c['default'] = True
        return template('default.html', **template_context)
예제 #3
0
def save_comment():
    text = request.POST.get('text', None)
    print text
    comment = Comment({'text': text, 'id': 'comment/new', 'meta': {'title': '', 'description': ''}})
    comment.save()
    print comment
    return template('simple_comment.html', {'comment': comment})
예제 #4
0
def manage_gallery(id):
    template_context = dict(
        gallery = db.galleries.find_one({ 'id': id }),
        id=id,
        size=admin_app.config['size']
    )
    return template('admin/gallery.html', **template_context)    
예제 #5
0
파일: blog.py 프로젝트: ivanm11/dataflytest
def blog():
    posts = (
        db.pages
          .find({ 'id': { '$regex': 'blog' }, 'current': True })
          .sort('meta.created', -1)
    )
    return template('admin/blog.html', posts=posts)
예제 #6
0
def show_comments(page=1, slug=None):
    c = template_context = dict(
        addthis_id = public_app.config.get('addthis_id'),
        fb_id = public_app.config.get('fb_id')
    )
    page = int(page)

    query = {
        'id': { '$regex': 'comment' },
        'current': True,
        'meta.hide': { '$ne': True }
    }

    c['latest_posts'] = db.comments.find(query).sort('meta.created', -1)[0:5]

    c['query'] = search = request.query.get('q', '')
    c['author'] = author = request.query.get('author', None)

    if author:
        query['meta.author'] = author
        comments = db.comments.find(query).sort('meta.created', -1)
    elif len(search):
        # posts from search
        regex = re.compile(search, re.IGNORECASE)
        query['content'] = { '$regex': regex }
        comments = db.comments.find(query).sort('meta.created', -1)
    elif slug:
        # single post
        c['single_comment'] = True
        c['slug'] = slug        
        comment = Comment.get_latest('comments/' + slug)
        hidden = comment['meta'].get('hide', False)
        if hidden == True:
            return abort(404, "Page not found")
        c['comments'] = [comment]
        c['page'] = comment
    else:
        # list
        comments = db.comments.find(query).sort('meta.created', -1)

    if slug is None:
        # pagination
        c['current_page'] = page
        per_page = 100
        skip = (page-1) * per_page
        c['count'] = count = comments.count()
        c['comments'] = comments[skip:skip+per_page]
        c['pages'] = count // 5 + 1 if (count % 5 == 0) else count // 5 + 2

    c['home'] = Comment.get_latest('home')
    print c
    return template('comment.html', **template_context)
예제 #7
0
def sitemap():   
    urlset = []
    pages = db.pages.find({ 'current': True, 'meta.hide': { '$ne': True } })
    for page in pages:
        if page['id'] == 'home':
            continue
        urlset.append(dict(
            location = page['id'],
            lastmod = page['published'].strftime('%Y-%m-%dT%H:%M:%S'),
            changefreq = 'weekly'
        ))    
    response.headers['Content-Type'] = 'application/xml'
    return template('sitemap.html', urlset=urlset)
예제 #8
0
def home():
    # getting tasks list and changing date format (date -> str)
    tasks_list = list(db.tasks_list.find().sort([("date", 1)]))

    for task in tasks_list:
        try:
            task["date"] = task["date"].strftime("%Y-%m-%d")
        except:
            pass
    
    template_context = dict(
        tasks_list = tasks_list,
        page = Page.get_latest('home')
    )
    return template('home.html', **template_context)
예제 #9
0
파일: mail.py 프로젝트: ivanm11/dataflytest
def send_email(mailto, subject, template_name, subject_override=False,
               template_context=None, from_email=None, premailer=True):
    """ Shortcut to send emails """
    if not subject_override:        
        subject = """%s / %s""" % (Config.WEBSITE, subject)
    if template_context is None:
        template_context = {}
    template_context['subject'] = subject
    template_context['base_url'] = Config.BASE_URL
    html = template(template_name if 'html' in template_name else
                    'mail/%s.html' % template_name, **template_context)
    if premailer:
        from premailer import transform
        html = transform(html)
    try:
        if Config.__name__ != 'Production':
            raise Exception("Sent real emails only in Production env")
        mc = Mandrill(Config.MANDRILL_API_KEY)
        if from_email is None:
            from_email = Config.EMAIL
        message = {
            'to': [{'email': mailto}],
            'from_email': from_email,
            'from_name': Config.WEBSITE,
            'subject': subject,
            'html': html
        }
        mc.messages.send(message = message)
        return { 'error': False }
    except:
        log_msg = {
            'mailto': mailto,
            'subject': subject,
            'html': html,
            'sent_at': datetime.now()
        }
        db.testmail.insert(log_msg)
예제 #10
0
def ajaxtest():
    return template('ajaxtest.html')    
예제 #11
0
def page404(code):
    return template('404.html')
예제 #12
0
def view_gallery(id):    
    gallery = db.galleries.find_one({ 'id': id })
    return template('gallery.html', gallery=gallery)
예제 #13
0
def custom_admin_page():    
    return template('admin/custom.html')
예제 #14
0
def login():    
    if g.admin:
        return redirect('/admin/home')
    return template('admin/login.html')
예제 #15
0
파일: blog.py 프로젝트: ivanm11/dataflytest
def show_posts(page=1, slug=None, year=None, month=None):
    c = template_context = dict(
        addthis_id = public_app.config.get('addthis_id'),
        fb_id = public_app.config.get('fb_id')
    )
    page = int(page)

    query = {
        'id': { '$regex': 'blog' },
        'current': True,
        'meta.hide': { '$ne': True }
    }

    c['latest_posts'] = db.pages.find(query).sort('meta.created', -1)[0:5]

    c['query'] = search = request.query.get('q', '')
    c['author'] = author = request.query.get('author', None)

    if author:
        query['meta.author'] = author
        posts = db.pages.find(query).sort('meta.created', -1)
    elif len(search):
        # posts from search
        regex = re.compile(search, re.IGNORECASE)
        query['content'] = { '$regex': regex }
        posts = db.pages.find(query).sort('meta.created', -1)
    elif slug:
        # single post
        c['single_post'] = True
        c['slug'] = slug        
        post = Page.get_latest('blog/' + slug)
        hidden = post['meta'].get('hide', False)
        if hidden == True:
            return abort(404, "Page not found")
        c['posts'] = [post]
        c['page'] = post
    elif year and month:
        # from archive
        date_from = datetime(year, month, 1)
        c['month_link'] = '/archive/%s/%s' % (year, month)
        c['month'] = date_from.strftime('%B %Y')
        date_to = date_from + relativedelta(months=+1)
        query['meta.created'] = {
            '$gte': date_from,
            '$lt': date_to
        }
        posts = db.pages.find(query).sort('meta.created', -1)
    else:
        # list
        posts = db.pages.find(query).sort('meta.created', -1)

    if slug is None:
        # pagination
        c['current_page'] = page
        per_page = 5
        skip = (page-1) * per_page
        c['count'] = count = posts.count()
        c['posts'] = posts[skip:skip+per_page]
        c['pages'] = count // 5 + 1 if (count % 5 == 0) else count // 5 + 2

    c['home'] = Page.get_latest('home')

    return template('blog.html', **template_context)
예제 #16
0
파일: blog.py 프로젝트: ivanm11/dataflytest
def edit_blog_post(page):
    return template('admin/blog-post.html',
                    editor = True,
                    page = Page.get_latest(g.page_id))