Admin Breaks When Using Jinja2 - jinja2

For some reason my wagtail admin interface is breaking when I try and use Jinja2 as my template engine instead of Django Template Engine. My frontend works just fine, it finds my templates in app/jinja2. This is a Django project with wagtail added on.
Here is the error that I am getting when trying to access /admin,
TemplateDoesNotExist at /admin/wagtailadmin/home.html
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.11
Exception Type: TemplateDoesNotExist
Exception Value: wagtailadmin/home.html
Exception Location: /Users/dbroadlick/Desktop/projects/codero2/virtualenv/lib/python3.6/site-packages/django/template/loader.py in get_template, line 25
Python Executable: /Users/dbroadlick/Desktop/projects/codero2/virtualenv/bin/python
Python Version: 3.6.1
Python Path: ['/Users/dbroadlick/Desktop/projects/codero2',
'/Users/dbroadlick/Desktop/projects/codero2/virtualenv/lib/python36.zip',
'/Users/dbroadlick/Desktop/projects/codero2/virtualenv/lib/python3.6',
'/Users/dbroadlick/Desktop/projects/codero2/virtualenv/lib/python3.6/lib-dynload',
'/Users/dbroadlick/Desktop/projects/codero2/virtualenv/lib/python3.6/site-packages']
Server time: Mon, 24 Jul 2017 21:40:59 +0000
Here is what my template configuration looks like,
TEMPLATES = [
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'APP_DIRS': True,
'OPTIONS': {
'extensions': [
'wagtail.wagtailcore.jinja2tags.core',
'wagtail.wagtailadmin.jinja2tags.userbar',
'wagtail.wagtailimages.jinja2tags.images',
],
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
It also says it is trying to use the jinja2 engine which it should not because wagtail admin is programmed using Django templates.

Your TEMPLATES setting has Jinja2 configured as the only available template engine, so there's nothing to trigger the 'traditional' Django Template engine behaviour that the Wagtail admin relies on (namely: to look inside each app's /template folder for the requested template path wagtailadmin/home.html). As a result, the template never gets found. You need to include configurations for both Jinja2 and DjangoTemplates in your TEMPLATES setting - something like:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'APP_DIRS': True,
'OPTIONS': {
'extensions': [
'wagtail.wagtailcore.jinja2tags.core',
'wagtail.wagtailadmin.jinja2tags.userbar',
'wagtail.wagtailimages.jinja2tags.images',
],
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Note that you'll need to have some convention in place to tell Django which templates should be rendered with which engine - with the above configuration, I believe that putting your Jinja2 templates inside some_app/jinja2/ rather than some_app/templates/ should take care of that.

Related

Can my bot server retrieve any information in the app manifest?

I am adding a new static tab to an existing teams app.
One of the new features is that the chat will publish a deep link to the static tab. This is creating a dilemna when I am contemplating deployment.
Obviously I can’t put my entire application up here, but we can assume a situation like this:
The manifest I have in production that is in the App Store looks like this:
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.9/MicrosoftTeams.schema.json",
"manifestVersion": "1.9",
"version": "2.0.1",
"id": "23232322-7676-4848-5555-44444444444",
"packageName": "xxxxx",
"developer": {
"name": "xxxxx",
"websiteUrl": "https://www.xxxx.com/",
"privacyUrl": "https://www.xxxx.com/legal/privacy",
"termsOfUseUrl": "https://www.xxxxx.com/legal/privacy"
},
"icons": {
"color": "color.png",
"outline": "outline.png"
},
"name": {
"short": "abra",
"full": "abra cadabra"
},
"description": {
"short": "short",
"full": "full"
},
"accentColor": "#FFFFFF",
"bots": [
{
"botId": "11111111-2222-3333-4444-555555555555",
"scopes": [
"personal"
],
"commandLists": [
{
"scopes": [
"personal"
],
"commands": [
{
"title": "Test",
"description": "Test"
}
]
}
],
"supportsFiles": false,
"isNotificationOnly": false
}
],
"permissions": [
"identity",
"messageTeamMembers"
],
"validDomains": [
"token.botframework.com",
"teams.microsoft.com",
"*.ngroc.io"
]
}
And in my bot in response to the “Test” command I return a simple text message, i.e.
return await step.prompt('textPrompt', { prompt: 'In the next version we will have a test tab' })
Now in development, I have added the following section to the manifest (after “bots”)
"staticTabs": [
{
"entityId": "conversations",
"scopes": [
"personal"
]
},
{
"entityId": "testtab”,
"contentBotId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"name": “Go To Test Tab",
"scopes": [ "personal" ]
},
{
"entityId": "about",
"scopes": [
"personal"
]
}
],
And I have updated the value of the version from 2.0.1 to 2.1.0
Now, in response to the “Test” message I am returning an adaptiveCard that looks like this:
{
type: 'AdaptiveCard',
version: '1.3',
body: [],
actions: [
{
type: 'Action.OpenUrl',
title: 'Go To Test Tab',
url: ‘https://teams.microsoft.com/l/entity/23232322-7676-4848-5555-44444444444/testtab’
}
]
}
This works very nicely and when I press the “go to Test Tab” it opens up the test tab as desired.
My problem is with deploying.
If I submit my new manifest to the App Store, without updating my production server, those testing the new version will continue to get the message “In the next version we will have a test tab” and be missing the link to the new tab.
If I update my production server now, before the update in the App Store, my current users will get the adaptive card with the button that will fail if they press it.
Clearly, neither of these options are good.
Ideally, my response should be something like:
If tabExists() {
Return {… the adaptive card }
Else {
return await step.prompt('textPrompt', { prompt: 'In the next version we will have a ‘test tab })
}
However, I don't know how to write "tabExists()" - I was thinking maybe there was some way to access the version number from the bot manifest, or the list of static tabs, and use that information, but I am happy for alternative suggestions.
We can get the manifest version using below Graph API or using SDK method:
https://learn.microsoft.com/en-us/graph/api/appcatalogs-list-teamsapps?view=graph-rest-1.0&tabs=http#example-4-list-applications-with-a-given-id-and-return-the-submission-review-state
So, before sending the Adaptive Card or message, you can put a custom condition to check the manifest version and send the message accordingly.
You can check the manifest version as explained by Chetan, i tried the same and figured its actually not the best idea.
It always should be best practice to have a "production" and "test" server or something like that.
Having different manifest versions point to the same server and running checks which version you're on will more than likely lead to issues sooner or later.
I sometimes even have 3 different instances running (prod, staging, test) to try various builds and things.
You can check that in your code but imo its not advisable to do so.

Hashicorp Packer: vsphere-iso builder deploy multiple disks?

I'm trying to get Hashicorp's Packer (1.5.5) to deploy multiple disks for a specialized (USGCB compliant) template and I need it to have four separate disks. I'm using the vsphere-iso builder. The "disk_size" parameter deploys the root drive fine. I found the 'storage' parameter which I think is used to deploy the other disks...
storage ([]DiskConfig) - A collection of one or more disks to be provisioned along with the VM
But I can't seem to figure out the format that the data needs to be in - in the json file. I tried...
"storage": [
{
"storage[1]": "20673",
"storage[2]": "16384",
"storage[3]": "4096"
}
]
and
"storage": [
{
"20673",
"16384",
"4096"
}
]
but none of those worked.
the storage section contains just the additional disks
you need the following
"disk_controller_type": "pvscsi",
"disk_size": "20673",
"disk_thin_provisioned": true,
"storage": [
{
"disk_size": "16384",
"disk_thin_provisioned": true
},
{
"disk_size": "4096",
"disk_thin_provisioned": true
}
],

multiple dist directories occur in requests when aurelia bundle is deployed

I was trying to deploy my aurelia application using gulp. Once deployed however I see all the css and js files being requested with multiple dist directories in the request path. I don't quite know why this is occurring.
This is one of the warning message in the chrome console
Resource interpreted as Stylesheet but transferred with MIME type text/html:
"
http://integration.mcc.gto.intranet.db.com/mcc-gui/mu/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/dist/styles/bootstrap-theme-3.3.2.min.css"
This is my bundles section in the gulp build tasks:
{
"bundles": {
"dist/app-build": {
"includes": [
"[**/*.js]",
"**/*.html!text",
"**/*.css!text"
],
"options": {
"inject": true,
"minify": true,
"depCache": true,
"rev": false
}
},
"dist/aurelia": {
"includes": [
"aurelia-framework",
"aurelia-bootstrapper",
"aurelia-event-aggregator",
"aurelia-fetch-client",
"aurelia-router",
"aurelia-animator-css",
"aurelia-templating-binding",
"aurelia-polyfills",
"aurelia-templating-resources",
"aurelia-templating-router",
"aurelia-loader-default",
"aurelia-history-browser",
"aurelia-logging-console",
"aurelia-pal-browser",
"aurelia-templating-binding",
"bootstrap",
"bootstrap/css/bootstrap.css!text",
"bootstrap-tour",
"d3",
"fetch",
"font-awesome",
"jquery",
"lodash",
"moment"
],
"options": {
"inject": true,
"minify": true,
"depCache": false,
"rev": false
}
}
}
}

Use Maps with typerscirpt and requirejs

I starting using requirejs with typescript and the amd module of typescript.
Right now I am using HereMaps with typescript, the functions are only referenced with a d.ts file.
How could I reference/import Here Maps, google maps or openstreetmaps to typescript 2, that it will be loaded by requirejs?
I think it is not a perfect combination and it will be better to use webpack or something simular
I solved it by switch the typescript module to AMD in tsconfig.json
{
"compilerOptions": {
"module": "AMD",
"target": "es5",
"sourceMap": true,
"declaration": false
},
"exclude": [
"node_modules"
]
}
then you have to use require to import reference
import H = require('heremaps-core');
after you define external references
requirejs.config({
shim: {
'heremaps-core': {
exports: 'H'
},
'heremaps-ui': ['heremaps-core'],
'heremaps-service': ['heremaps-core'],
'heremaps-events': ['heremaps-core'],
'hogan': {
exports: 'Hogan'
}
},
paths: {
'jquery': [
'https://code.jquery.com/jquery-3.1.1.min',
'https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min',
'lib/jquery-3.1.1.min'
],
'hogan': [
'https://twitter.github.io/hogan.js/builds/3.0.1/hogan-3.0.1.js',
'lib/hogan.min'
],
'google.maps': [
'https://maps.googleapis.com/maps/api/js?v=3.21 &key=AIzaSyBtw3pgNVNPacgQGwLQt1nUbBrqGW-De90'
],
'heremaps-core': [
'https://js.api.here.com/v3/3.0/mapsjs-core'
],
'heremaps-ui': [
'https://js.api.here.com/v3/3.0/mapsjs-ui'
],
'heremaps-service': [
'https://js.api.here.com/v3/3.0/mapsjs-service'
],
'heremaps-events': [
'https://js.api.here.com/v3/3.0/mapsjs-mapevents'
]
}
});
I am not sure if it is all. I did not work at this project since a year.

How to configure LumberJack(LogStash-forwarder) on windows

I've installed ELK on my ubuntu server using this manual,
Now i want to index some log files from a windows server so I installed a logstash forwarder (LumberJack), but I can't get it to run.
this is the logstash-forwarder.conf file :
{
"network": {
"servers": [ "http://XX.XX.XX.XX:5000" ],
"ssl key": "D:/lumberjack/pki/tls/certs/logstash-forwarder.crt",
"ssl ca": "D:/lumberjack/pki/tls/certs/logstash-forwarder.crt",
"timeout": 15,
},
"files": [
{
"paths": [
#single paths are fine
"D:/bea12/Oracle/Middleware/domains/Google/servers/RT1/logs/AppLogs/RT1_APP_9_0.log",
#globs are fine too, they will be periodically evaluated
#to see if any new files match the wildcard.
"/var/logauth.log"
],
]
}
}
and this is the Error I get when i'm trying to run the "lumberjack.exe" ,
That I created with go-build:
2015/04/30 18:17:39.052033 Failed unmarshalling json: invalid character '}' looking for beginning of object key string
2015/04/30 18:17:39.052033 Could not load config file d:\lumberjack\logstash-forwarder.conf: invalid character '}' looking for beginning of object key string
Can anyone please tell me what am I doing wrong?
By the way this is the command I'm using to run the forwarder:
lumberjack.exe -config="d:\lumberjack\logstash-forwarder.conf"
Ok.
So the problem was in the configuration file, There were 2 unnecesary commas and no need for the http:\ at the start:
{
"network": {
"servers": [ "XX.XX.XX.XX:5000" ],
"ssl key": "D:/lumberjack/pki/tls/certs/logstash-forwarder.key",
"ssl ca": "D:/lumberjack/pki/tls/certs/logstash-forwarder.crt",
"timeout": 15
},
"files": [
{
"paths": [
#single paths are fine
"D:/bea12/Oracle/Middleware/domains/google/servers/RT1/logs/AppLogs/RT1_APP_9_0.log",
#globs are fine too, they will be periodically evaluated
#to see if any new files match the wildcard.
"/var/logauth.log"
]
}
]
}
This is my suggested configuration file for LumberJack on windows.