Esempio n. 1
0
def install():
  logging.error(">> installing post")
  params = {
    "name":"Hello world!",
    "slug":"hello-world",
    "plain_description":"Welcome to ContentQ CMS. This is your first post. Edit or delete it, then start blogging!",
    "description":"Welcome to ContentQ CMS. This is your first post. Edit or delete it, then start blogging!",
    "status":"published",
    "tags":[],
    "meta_desc":"hello world",
    "category":"uncategorized",
    "body":"<p>this is an example content</p>"
  }
  post_ref = PostItem(**params)
  post_ref.put()
  category_ref = PostCategory(name='Uncategorized', slug='uncategorized')
  category_ref.put()

  latestpost_ref = Block.add_model('latestpost', 'blog.blocks.LatestPostBlock')
  postcategories_ref = Block.add_model('postcategories', 'blog.blocks.PostCategoriesBlock')
  
  block = Block(name='Post Categories', slug='post-categories',
                position='rightsidebar', model='blog.blocks.PostCategoriesBlock',
                args={})
  block.save()
Esempio n. 2
0
def get_category_and_posts(category_name):
    posts = Post.objects.filter(published=True)
    if category_name == post_category_all.slug():
        category = PostCategory(name=category_name)
    else:
        try:
            category = PostCategory.objects.get(name__iexact=category_name)
            posts = posts.filter(category=category)
        except PostCategory.DoesNotExist:
            category = PostCategory(name=category_name)
            posts = Post.objects.none()

    posts = posts.order_by('-created_at')
    return category, posts
Esempio n. 3
0
def get_category_and_posts(category_name):
    posts = Post.objects.filter(published=True)

    if category_name == post_category_all.slug():
        category = post_category_all

    else:
        try:
            category = PostCategory.objects.get(name__iexact=category_name)
            posts = posts.filter(category=category)
        except PostCategory.DoesNotExist:
            # Return an empty iterable list (allow the order by later instead of empty list)
            category = PostCategory(name=category_name)
            posts = Post.objects.none()

    posts = posts.order_by('-created_at')
    return category, posts
Esempio n. 4
0
def get_category_and_posts(category_name):
    # posts contents all posts published
    posts = Post.objects.filter(published=True)
    # use pass variable if don't know what treatment done
    if category_name == post_category_all.slug():
        category = post_category_all
    #  if category differ to post_category_all
    else:
        try:
            category = PostCategory.objects.get(name__iexact=category_name)
            # test of category name not consider case sensitive (name__iexact)
            posts = posts.filter(category=category)
        except PostCategory.DoesNotExist:
            #  create fictive category
            category = PostCategory(name=category_name)
            posts = Post.objects.none()  # empty list in Django iterable to make possible use order_by

    #  reverse chronology order
    posts = posts.order_by('-date')
    return category, posts
Esempio n. 5
0
from blog.models import Post, PostCategory

post_category_all = PostCategory(name='All')


def get_category_and_posts(category_name):
    posts = Post.objects.filter(published=True)
    if category_name == post_category_all.slug():
        category = PostCategory(name=category_name)
    else:
        try:
            category = PostCategory.objects.get(name__iexact=category_name)
            posts = posts.filter(category=category)
        except PostCategory.DoesNotExist:
            category = PostCategory(name=category_name)
            posts = Post.objects.none()

    posts = posts.order_by('-created_at')
    return category, posts


def get_categories():
    categories = list(PostCategory.objects.all().order_by('name'))
    categories.insert(0, post_category_all)
    return categories
Esempio n. 6
0
from blog.models import Post, PostCategory

post_category_all = PostCategory(name="All")


def get_category_and_posts(category_name):
    posts = Post.objects.filter(published=True)

    if category_name == post_category_all.slug():
        category = post_category_all
    else:
        try:
            category = PostCategory.objects.get(name__iexact=category_name)
            posts = posts.filter(category=category)
        except PostCategory.DoesNotExist:
            category = PostCategory(name=category_name)
            posts = Post.objects.none()
    posts = posts.order_by('-created_at')
    return category, posts


def get_categories():
    categories = list(PostCategory.objects.all().order_by('name'))
    categories.insert(0, post_category_all)
    return categories
Esempio n. 7
0
def get_content():
  return {"Post Item":PostItem.all(), "Post Category":PostCategory.all()}
Esempio n. 8
0
 def render(cls, context, * args, ** kwargs):
   categories_list = PostCategory.all()
   return cls.render_block(template_name='block_blogcategories.html',
                           block_title=_('Categories'),
                           context={'categories_list': categories_list})
Esempio n. 9
0
from blog.models import Post, PostCategory

category_name_all = PostCategory(name="All")


def get_category_and_posts(category_name):

    posts = Post.objects.filter(published=True)

    if category_name == category_name_all.slug():
        category = category_name_all

    else:

        try:
            category = PostCategory.objects.get(name__iexact=category_name)
            posts = posts.filter(category=category)
            print(category)

        except PostCategory.DoesNotExist:
            category = PostCategory(name=category_name)
            posts = Post.objects.none()

    posts = posts.order_by("-created_at")
    return category, posts


def get_categories():
    cateroties = list(PostCategory.objects.all().order_by("name"))
    cateroties.insert(0, category_name_all)
    return cateroties