`first_published_at` not working properly in Wagtail - wagtail

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.

Related

Edit the url sent in confirmation email dj_rest_auth

When I register a new user the confirmation email sent in the email template contains the url of backend but i need to handle that in forntend. Anyone know how to edit that email template of dj_rest_auth by jazzband?
The email template is:
Hello from example.com!
You're receiving this e-mail because user Pinon has given yours as an
e-mail address to connect their account.
To confirm this is correct, go to
http://localhost:8000/auth/registration/account-confirm-email/Nw:1kO3gI:PQDfxEOyklUYIxpjNN_011ZxGQYPJRdNomzzOFjtXA0/
Thank you from example.com! example.com
But i need it to be like this:
Hello from example.com!
You're receiving this e-mail because user Pinon has given yours as an
e-mail address to connect their account.
To confirm this is correct, go to
http://localhost:3000/account-confirm-email/Nw:1kO3gI:PQDfxEOyklUYIxpjNN_011ZxGQYPJRdNomzzOFjtXA0/
Thank you from example.com! example.com
Ok, this thing is handled by django_allauth package. So you have to do so as they suggested in their (django_allauth) documentation
So I have created my dir like this: templates/account/email/email_confirmation_message.txt then added this code to the file:
{% load account %}{% user_display user as user_display %}{% load i18n %}{% autoescape off %}{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Hello from {{ site_name }}!
You're receiving this e-mail because user {{ user_display }} has given your e-mail address to register an account on {{ site_domain }}.
To confirm this is correct, Click here.
{% endblocktrans %}
{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you from {{ site_name }}!
{{ site_domain }}{% endblocktrans %}
{% endautoescape %}
That
{{ key }}
is the main thing to find 😉.

How can I loop around an array in this situation?

I have the following variables in my playbook:
frontends:
- domain01.fr
- domain02.fr
- domain03.fr
- domain04.fr
I need to be able to write the following in a file via an Ansible playbook step:
tcp://domain01.fr:11211,tcp://domain02.fr:11211,tcp://domain03.fr:11211,tcp://domain04.fr:11211
I came up with the following solution, but I'm not pleased with it.
- name: Setting up Apache (2/2)
lineinfile:
path: /etc/opt/rh/rh-php56/php.ini
regexp: '^session.save_path ='
line: "session.save_path = 'tcp://{{ frontends | join(':11211,tcp://') }}'"
I can't hardwrite the domains inside the lineinfile method, because it depends a lot, plus there are situations where I only have 2 domains instead of 4.
Is it possible to have something like the following:
- name: Setting up Apache (2/2)
lineinfile:
path: /etc/opt/rh/rh-php56/php.ini
regexp: '^session.save_path ='
line: "session.save_path = '{% for frontend in frontends %} tcp://{% frontend %}:11211,{% endfor %}'"
Thank you in advance
Yes. It's possible. The line below
regexp: '^session.save_path ='
line: >-
session.save_path ={% for frontend in frontends %}
tcp://{{ frontend }}:11211{% if not loop.last %},{% endif %}{% endfor %}
gives
session.save_path = tcp://domain01.fr:11211, tcp://domain02.fr:11211, tcp://domain03.fr:11211, tcp://domain04.fr:11211

collections pages loop not working on github

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

How to add a new hugo static page?

From the "getting started" section it seems this should work, but it doesn't.
hugo new site my-site
hugo new privacy.md
hugo server --watch --includeDrafts
curl -L localhost:1313/privacy/index.html
# 404 page not found
curl -L localhost:1313/privacy.html
# 404 page not found
curl -L localhost:1313/privacy/
# 404 page not found
How can I add a new page?
This is the best tutorial how to create static "landing pages" on Hugo: https://discuss.gohugo.io/t/creating-static-content-that-uses-partials/265/19?u=royston
Basically, you create .md in /content/ with type: "page" in front matter, then create custom layout for it, for example layout: "simple-static" in front matter, then create the layout template in themes/<name>/layouts/page/, for example, simple-static.html. Then, use all partials as usual, and call content from original .md file using {{ .Content }}.
All my static (landing) pages are using this method.
By the way, I'm not using hugo new, I just clone .md file or copy a template into /content/ and open it using my iA Writer text editor. But I'm not using Hugo server either, adapted npm-build-boilerplate is running the server and builds.
Just tested OK with this on Hugo 0.13:
hugo new site my-site
cd my-site
hugo new privacy.md
hugo server -w -D
curl -L localhost:1313/privacy/
Note: You have to either use a theme or provide your own layout template to get something more than a blank page. And of course, some Markdown in privacy.md would also make it even nicer.
See http://gohugo.io/overview/introduction for up-to-date documentation.
I had a similar requirement, to add static page (aboutus in this case). Following steps did the trick,
Created an empty file content/aboutus/_index.md
Created aboutus.html page layouts/section/aboutus.html
Make you have some default frontmatter set in archetypes/default.md
# archetypes/default.md
+++
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
+++
And the single layout in layouts/_default/single.html to render some variable or content
# tags to render markdown content
<h1>{{ .Title }}</h1>
<p>{{ .Content }}</p>
<span>{{ .Params.date }}</span>
Now type hugo new privacy.md which will create a new page on the following directory in content/privacy.md
Take "About" as example:
# will create content/about.md
hugo new about.md
Edit about.md and add the last 2 lines, the metadata/front matter looks like:
title: "About"
date: 2019-03-26
menu: "main"
weight: 50
That should work.

Can't disable the autoescape in jinja2

In GAE I use jinja2 with the autoescape, and everything works well.
import jinja2
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = True)
In one template I don't want the autoescape, so I tried to disable it like this:
{% autoescape false %}
{{content}}
{% endautoescape %}
When it's time to render this template I get the message Encountered unknown tag 'autoescape'.
Try this:
{{ content | safe}}
docs:
Flask — Controlling Autoescaping
Jinja2 — Filters — safe
In order for the autoescape tag to be recognized, you need to enable the autoescape extension when setting up jinja2, like this:
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
autoescape = True,
extensions = ['jinja2.ext.autoescape'])
Also, make sure you're using jinja2 version 2.4 or higher in your app.yaml (the current version is GAE is 2.6):
libraries:
- name: jinja2
version: "2.6"
For more information, see the documentation for the autoescape extension.

Resources