Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        """initialize properties"""
        self.articles = []  # only articles in default language
        self.translations = []
        self.dates = {}
        self.categories = defaultdict(list)
        self.authors = defaultdict(list)
        super(ButterGenerator, self).__init__(*args, **kwargs)

        # 'cause settings is initialized in super
        self.client = ButterCMS(self.settings.get('BUTTER_CONFIG')['api_key'])
from butter_cms import ButterCMS
from flask import Blueprint, render_template, abort
from jinja2 import TemplateNotFound
import os

blog = Blueprint('blog', __name__, template_folder='templates/blog')

client = ButterCMS(os.environ["BUTTER_CMS_AUTH"])


@blog.route('/')
@blog.route('/page/<int:page>')
def home(page=1):
    response = client.posts.all({'page': 1, 'page_size': 10})
    posts = response['data']
    next_page = response['meta']['next_page']
    previous_page = response['meta']['previous_page']
    return render_template('blog.html',
                           posts=posts,
                           next_page=next_page,
                           previous_page=previous_page)


@blog.route('/<slug>')
def show_post(slug):
    response = client.posts.get(slug)
    try:
        post = response['data']
    except:
        # Post was not found
        abort(404)
Esempio n. 3
0
import os

from butter_cms import ButterCMS
from django.http import HttpResponse
from django.template import loader

client = ButterCMS(os.environ['BUTTERCMS_API_TOKEN'])


def index(request):
    template = loader.get_template('blogs_index.html')
    response = client.posts.all({'page': 1, 'page_size': 10, 'order': '-date_published'})
    posts = response['data']
    context = {
        'posts': posts,
    }
    return HttpResponse(template.render(context, request))


def post(request, slug):
    template = loader.get_template('blogs_post.html')
    response = client.posts.get(slug)
    post = response['data']
    context = {
        'post': post,
    }
    print(post)
    return HttpResponse(template.render(context, request))
Esempio n. 4
0
from django.shortcuts import render
from django.http import Http404
from django.conf import settings

from butter_cms import ButterCMS
from datetime import datetime
import pprint

client = ButterCMS(settings.BUTTER_CMS_KEY)


def home(request):
    return render(request, 'index.html', {})


def blog(request):
    response = client.posts.all()
    pprint.pprint(response)

    try:
        recent_posts = response['data']
    except:
        # In the event we request an invalid page number, no data key will exist in response.
        raise Http404('Page not found')

    context = {
        'recent_posts': recent_posts,
    }
    return render(request, 'blog.html', context)

Esempio n. 5
0
from os import path# afin de vérifier si un fichier existe dans le répertoire
import logging.config #afin de faire du log
import logging# idem qu'au dessus
#from flask import Flask
from butter_cms import ButterCMS
from flask import Flask

client = ButterCMS('your_api_token')
from model import session as db  # python class who flush changes to database
#from flask_debugtoolbar import DebugToolbarExtension # afin de faire du debug dans flask
# for use the ini/config file :
log_file_path = path.join(path.dirname(path.abspath(__file__)), 'log.config') # associe le path.abspath(__file__) faisant référence au répertoire courant, au 'log.config' faisant référence au fichier du même nom grâce au path.join
logging.config.fileConfig(log_file_path) # configure des logs à partir du fichier passé en paramètre
log = logging.getLogger(__name__)  # return a logger which current class is the root logger


app = Flask(__name__)  # for Flask to knows where to look for templates and files # ici on instancie et crée un serveur flask
# app.debug = True  # to activate debugtoolbar in navigators #lié au debugtoolbar
# secret key is needed to keep the client-side sessions secure :
#app.config['SECRET_KEY'] = 'Tandis que les crachats rouges de la mitraille' #lié au debugtoolbar
#toolbar = DebugToolbarExtension(app) #lié au debugtoolbar

'''
    The @app.teardown_appcontext decorator will cause the supplied callback, cleanup, 
    to be executed when the current application context is torn down. This happens 
    after each request. That way we make sure to release the resources used by a 
    session after each request :
'''

Esempio n. 6
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import Http404
from butter_cms import ButterCMS

# Create your views here.

client = ButterCMS('6be81632a73268ce51f81fb5031d3e8946d8b116')


def home(request, page=1):
    response = client.posts.all({'page_size': 10, 'page': page})

    try:
        recent_posts = response['data']
    except:
        # In the event we request an invalid page number, no data key will exist in response.
        raise Http404('Page not found')

    next_page = response['meta']['next_page']
    previous_page = response['meta']['previous_page']
    categories = client.categories.all()
    tags = client.tags.all()

    return render(
        request, 'blog_base.html', {
            'recent_posts': recent_posts,
            'next_page': next_page,
            'previous_page': previous_page
        })
Esempio n. 7
0
from django.http import Http404
from django.shortcuts import render
from butter_cms import ButterCMS

client = ButterCMS('3af08233eb3984f6590f8cd06f6eca9b86e95c42')


def home(request, page=1):
    response = client.posts.all({'page_size': 3, 'page': page})

    try:
        recent_posts = response['data']
    except:
        # In the event we request an invalid page number, no data key will exist in response.
        raise Http404('Page not found')

    next_page = response['meta']['next_page']
    previous_page = response['meta']['previous_page']

    return render(request, 'blog/blog_base.html', {
        'recent_posts': recent_posts,
        'next_page': next_page,
        'previous_page': previous_page
    })


def post(request, slug):
    try:
        response = client.posts.get(slug)
    except:
        raise Http404('Post not found')
Esempio n. 8
0
from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.decorators import api_view

from butter_cms import ButterCMS

client = ButterCMS('14841f69b217e959bf8be2ba42a2d203fc814e45')

# Create your views here.


@api_view(['GET'])
def BlogView(request):
    data = client.posts.all({'page_size': 10, 'page': 1})
    return Response(data)
Esempio n. 9
0
from django.http import Http404
from django.conf import settings
from django.views.generic import TemplateView

from butter_cms import ButterCMS

butter_client = ButterCMS(settings.BUTTER_CMS.get('KEY'))


class ButterPageDetailView(TemplateView):
    client = butter_client
    butter_type = 'pages'

    def get_template_names(self):
        templates = ['butter/{}_detail.html'.format(self.butter_type)]
        if self.template_name:
            templates.insert(0, self.template_name)
        return templates

    def get_butter(self):
        return self.client.pages.get(self.butter_type, self.kwargs.get('slug'))

    def render_to_response(self, context, **response_kwargs):
        butter = self.get_butter()

        if 'page not found' in butter.get('detail', '').lower():
            raise Http404("An error occurred: {}".format(butter))

        try:
            context['object'] = butter.get('data', {}).get('fields', {})
        except Exception as e:
Esempio n. 10
0
from butter_cms import ButterCMS
from flask import Blueprint, render_template, abort
from jinja2 import TemplateNotFound
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import config
import datetime

blog_app = Blueprint('blog', __name__, template_folder='templates/blog')

client = ButterCMS(config.BUTTERCMS_KEY)

#blog_app.jinja_env.globals.update(convert_unicode_datetime=convert_unicode_datetime)


@blog_app.route('/')
@blog_app.route('/page/<int:page>')
def home(page=1):
    response = client.posts.all({'page': 1, 'page_size': 10})
    posts = response['data']
    next_page = response['meta']['next_page']
    previous_page = response['meta']['previous_page']
    return render_template('blog.html',
                           posts=posts,
                           next_page=next_page,
                           previous_page=previous_page,
                           convert_unicode_datetime=convert_unicode_datetime)


@blog_app.route('/<slug>')
def show_post(slug):
Esempio n. 11
0
from flask import Flask, render_template
from butter_cms import ButterCMS
client = ButterCMS('fe24aecaf5a4ed78ad167e1a820b3e7fd04b90b2')

app=Flask(__name__)

@app.route('/', methods=['POST'])
def home():
    homepage = client.posts.get('about-us')
    return render_template('home.html', obj=homepage['data']['body'])

if __name__ == "__main__": app.run(debug=True)
Esempio n. 12
0
from django.shortcuts import render, get_object_or_404
from django.http import Http404

from butter_cms import ButterCMS


client = ButterCMS('bb642c7222ed11498c5aa3d59ab90870ede2e615')

def tactics(request, page=1):
    response = client.posts.all({'page_size': 10, 'page': page})

    try:
        recent_posts = response['data']
    except:
        # In the event we request an invalid page number, no data key will exist in response.
        raise Http404('Page not found')

    next_page = response['meta']['next_page']
    previous_page = response['meta']['previous_page']

    return render(request, 'tactics/tactics.html', {
        'recent_posts': recent_posts,
        'next_page': next_page,
        'previous_page': previous_page
    })


def tactic(request, slug):
    try:
        response = client.posts.get(slug)
    except:
Esempio n. 13
0
from django.shortcuts import render, redirect
from butter_cms import ButterCMS
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth import logout, authenticate, login
from django.contrib.auth.forms import AuthenticationForm
from .forms import RegisterForm, ContactForm
from django.conf import settings

client = ButterCMS('a9c6436fe45c3afafed88780f488c53142d9f269')


def home(request):
    result = client.pages.get('*', 'mycv')
    data = result['data']['fields']
    dati = data['dati_personali']
    formazione = data['formazione']
    lingue = data['lingue']

    if request.method == 'GET':
        form = ContactForm()
    else:
        form = ContactForm(request.POST)
        if form.is_valid():
            subject = form.cleaned_data['subject']
            from_email = form.cleaned_data['from_email']
            message = form.cleaned_data['message']
            try:
                send_mail(subject, message + "\nfrom " + from_email,
                          settings.EMAIL_HOST_USER,
                          ['*****@*****.**'])
Esempio n. 14
0
from butter_cms import ButterCMS
from flask import Blueprint, render_template, abort
from jinja2 import TemplateNotFound

blog = Blueprint('blog',
                 __name__,
                 template_folder='templates/blog',
                 static_folder='static')

auth_token = "771757d6e39f01f870e7f82c11c6ff2e87d6428c"
client = ButterCMS(auth_token)


@blog.route('/')
@blog.route('/page/<int:page>')
def home(page=1):
    response = client.posts.all({'page': 1, 'page_size': 10})
    posts = response['data']
    next_page = response['meta']['next_page']
    previous_page = response['meta']['previous_page']
    return render_template('blog.html',
                           posts=posts,
                           next_page=next_page,
                           previous_page=previous_page)


@blog.route('/<slug>')
def show_post(slug):
    response = client.posts.get(slug)
    try:
        post = response['data']
Esempio n. 15
0
from django.http import Http404
from django.shortcuts import render
from butter_cms import ButterCMS

client = ButterCMS('9ba26871533ad7885b6f90db109a275451d03851')


def home(request, page=1):
    response = client.posts.all({'page_size': 10, 'page': page})

    try:
        recent_posts = response['data']
    except:
        # In the event we request an invalid page number, no data key will exist in response.
        raise Http404('Page not found')

    next_page = response['meta']['next_page']
    previous_page = response['meta']['previous_page']

    return render(
        request, 'blog_base.html', {
            'recent_posts': recent_posts,
            'next_page': next_page,
            'previous_page': previous_page
        })


def post(request, slug):
    try:
        response = client.posts.get(slug)
    except: