Posted by & filed under python.

Простейший способ по поиску во внутренних страницах в Django-cms:

from cms.models.pagemodel import Page
found_entries=Page.objects.search('test')

В Django шаблоне теперь пишем:

{%if found_entries %}
    Query was found in pages:
{% for one in found_entries %} {{ one.get_title }}
{%endfor%} {% else %} Query was not found {% endif %}

Posted by & filed under python.

Встал вопрос как быть с SEO. Точнее с title, meta description, meta keywords. Как оказалось всё это подключается очень просто:
http://docs.django-cms.org/en/2.1.3/getting_started/configuration.html#cms-seo-fields
Точнее в settings.py указываем:

CMS_SEO_FIELDS=True

А потом в шаблоне добавляем:

{% load cms_tags %}
<head>
<title>{% page_attribute page_title %}</title>
<meta name=»description» content=»{% page_attribute meta_description %}»/>
<meta name=»keywords» content=»{% page_attribute meta_keywords %}»/>


</head>

Posted by & filed under python.

Какая разница между block, placeholder, variable? Этот вопрос я задал в официальной группе проекта:

What the main difference between block, placeholder, variable? I can
write {% block content %}{% endblock%}, {%placeholder content%}
{%endplaceholder%}, or {{content}}. But i want to know right way

И вот ответ:

A block is a Django specific thing. It comes with Django’s templating
language. You can define {% block content %} in your base template. Then you
can define a sub template that extends your base template and override {%
block content %} in your sub template.

A placeholder is a django-cms thing. You can place it in your default
template, then create a new page in the cms’ page admin and base that page
on your default template. Now the admin will show all placeholders that you
have placed in your template. Your editors are able to place plugins into
placeholder (i.e. a TextPlugin, followed by a PicturePlugin, followed by two
more TextPlugins).

Variables get added to the context by views and middlewares. Have a look at
the documentation about writing CMSPlugins for django-cms. Plugins are
basically views that add stuff to the context. Whatever you add to the
context dictionary will be available as {{ variablename }}

Вот ссылка на оригинал:
http://groups.google.com/group/django-cms/browse_thread/thread/53419479f144f26a

Posted by & filed under python.

Работа с локалью (locale) в Python.

import locale
loc=locale.getlocale()

#изменяем локаль
locale.setlocale(locale.LC_ALL, ('RU','UTF8'))

#что то делаем
a=time.strptime(datetime,format1)
a=time.strftime (format2,a)

# меняем локаль назад
locale.setlocale(locale.LC_ALL, loc)

Posted by & filed under python.

Официальный ответ с группы Django-cms:

A snippet is just any piece of text. You can define them in your Django admin.

Plugins are pieces of django-cms code (that you can write yourself) that have a template and that can add any variables to the context for that template. You could for example create a cms plugin that displays the last 5 news of your news app. You would just define a latest_news.html template and in the plugin code you would add News.objects.all()[:5] to the context. Plugins can be placed in placeholders, so you are totally free to decide where your latest news should be displayed (can even be displayed on many different places at the same time).

The cms ships with a snippet plugin, so you can place any snippet into any placeholder. This can be useful if you want to place something like <div class=»divider»></div> between two text plugins for example.

An app is just any django application. The great difference between apps and plugins is, that apps have an urls.py and usually handle display (get) and input (post) while plugins are just for rendering a certain template with a certain context. Imaging you have created a nice blog application (like cmsplugin_blog). That would have many urls (for index view, archive views, details view, rss views, blablabla). But django-cms is already taking care of all urls! Therefore you can put an app-hook into any cms page. Let’s say you have created a page «/blog/» in django-cms. If you hook your blog into that page, the urls of your blog will be available under the /page/ url.

When hooking up apps, templating is a bit tricky. Usually your page has a template already. Usually you would define a {% block content %} somewhere in that template. If you add an apphook, you will not see anything about your blog, because the (mostly third party) app you try to hook doesn’t know anything about django-cms and thus doesn’t extend the template you use for your page and doesn’t put anything into the content block tag. That means you would have to override all templates that ship with the app you want to use — but if those apps where done by experienced developers the templates will be simple and ugly anyways and are meant to be overridden.