I have below PageDetail model defined:
class PostDetail(Page):
template = "Post_Detail.html"
body = RichTextField(blank=True)
search_fields = Page.search_fields + [
index.SearchField("body"),
]
content_panels = Page.content_panels + [
FieldPanel("body"),
]
but when I added 2 PageDetail pages (with 15 mins time interval), I found first_published_at was not working properly.
Q1: first_published_at of above 2 newly-added pages are the same Date and Time instead of 15 mins difference.
Q2: Even though I have WAGTAIL_USER_TIME_ZONES = ['Asia/Singapore'] in settings.py of Django Project and restarted the Django server, the first_published_at is still not in correct timezone.
Problem Solved
It turned out to be my silly mistake. In the template file (see below) of Post Index page, problem was fixed after I changed page.first_published_at to post.first_published_at.
{% for post in page.get_children %}
<h2>{{ post.title }}</h2>
<p>{{ post.first_published_at }}</p>
<!-- {{ post.specific.body|richtext }} -->
{% endfor %}
What are your Django settings for timezones? Do you have:
TIME_ZONE = ['Asia/Singapore']
USE_TZ = True
From the docs it looks to me like WAGTAIL_USER_TIME_ZONES is about the admin display parameter rather than what timezone the server is using.
Logged-in users can choose their current time zone for the admin interface in the account settings.
Having the following file in the data folder:
# data/files.json
{
"test/file1.txt": "abcd/1234567890.txt",
"test/file2.txt": "bcde/1234567890.txt"
}
How do I obtain the value of "test/file1.txt" from the map? For example from this file
// layout/index.ace
= doctype html
html lang={{ .Site.Language.Lang }}
body
p {{ .Site.Data.files.????? }}
This is my environment:
$ go version
go version go1.9.2 linux/amd64
$ hugo version
Hugo Static Site Generator v0.35-DEV linux/amd64 BuildDate:
// layout/index.ace
= doctype html
html lang={{ .Site.Language.Lang }}
body
p {{ index .Site.Data.files "test/file1.txt" }}
does the trick.
Jekyll Version: 2.4.0
github pages Version: 35
My Reproduction Steps
Build on locally and the looping of collections site.collections.guides.docs shown, generated the correct .html in _site folder as well.
However, when I deploy to github, it doesn't show the loop content.
The Output I Wanted
shown the loop in github pages, appreciate if someone have a look on my repo.
my codes:
// index.html
{% for doc in site.collections.guides.docs %}
{{ doc.content }}
{% endfor %}
// _config.yml
collections :
guides:
output: true
I would write it like this:
{% for doc in site.guides %}
{{ doc.content }}
{% endfor %}
And the config like this:
collections:
guides:
output: true
I've been following an earlier post to check if an asset exists, which works great when using specific filenames.
Symfony2 and Twig - Check if an asset exists
However instead of checking for a specific image filename, how do you check for an image type? (all files with the .jpg extension)
Example: *.jpg (which doesn't work neither does .jpg)
{% if asset_exists('/images/*.jpg') %}
<div class="entry-thumbnail">
<img width="230" height="172" src="{{ asset(['images/', post.image]|join) }}" class="" alt=""/>
</div>
{% endif %}
As soon as you are using:
{{ asset(['images/', post.image]|join) }}`
Why not using:
{% if asset_exists(['images/', post.image]|join) %}
Tip: replace ['images/', post.image]|join by using the concat operator ~: 'images/' ~ post.image
You'd have to modify the Twig Extension and replace !is_file($toCheck) with count(glob($toCheck)) < 1
glob function (php.net)
I use Jinja2 compiled templates and a module loader to load the compiled templates (python code) from the datastore. But when my template contains a macro it does not work on app engine: TypeError: 'NoneType' object is not callable
But in the app engine SDK it works fine.
And when I skip the macro call, i receive the same error.
Without the macro it works fine. Without a solution for this macro problem, I call a python function in my template to implement the functionality of the macro.
Update: This is the template source code which results in an error:
{% extends "mainpage.html" %}
{% block form %}
{% macro test_macro(name) %}
<p>{{ name }}</p>
{% endmacro %}
<div>
{{ test_macro('John Doe') }}
</div>
{% endblock %}
And this is the compiled template code (the form block part):
def block_form(context, environment=environment):
if 0: yield None
yield u'\n'
def macro(l_name):
t_1 = []
pass
t_1.extend((
u'\n<p>',
to_string(l_name),
u'</p>\n',
))
return concat(t_1)
l_test_macro = Macro(environment, macro, 'test_macro', ('name',), (), False, False, False)
yield u'\n<div>\n\t%s\n</div>\n' % (
context.call(l_test_macro, 'John Doe'),
)
Update: After some debugging it worked. But I do understand it!!!
The problem: I lose my imports. And when I redefine my imports in the code. It worked.
The top of the module:
from __future__ import division
from jinja2.runtime import LoopContext, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join, to_string, identity, TemplateNotFound
__jinja_template__ = None
To make it work I had to add an inline import:
from jinja2.runtime import Macro # import again ?????
l_test_macro = Macro(environment, macro, 'test_macro', ('name',), (), False, False, False)
Can somebody explain, how I can lose my imports ??? I have this problem only in app engine and NOT in the SDK ??? Is this a namespace problem?
I was able to solve it, by adding the module to the sys.modules. But I do not understand why it worked in the SDK and not in GAE when I use a macro
Here is the code of my changed module loader.
def get_module(self, environment, template):
# Convert the path to a module name
name = template.replace('.html', '').replace('.txt','').replace('/', '.') # NO extensions
module = None
if self.package == None : # load from db and not from package
logging.info('load module : ' + name) # load module from runtimes db
if name in sys.modules : return sys.modules[name] # already imported
try :
runtime = models.Runtimes.rtimes_get_by_key_name(template)
module_code = db.Text(runtime.compiled)
module = imp.new_module(name)
exec module_code in module.__dict__
sys.modules[name] = module # add to sys modules, so no import again
return module
except (ImportError, AttributeError):
logging.error('load failed : ' + name)
else : .... # load from package
raise TemplateNotFound(template)