django 1.7 template deleted, but still loads as if it exists - django

Question:
What do I need to do to have Django load a template from the filesystem, instead of loading from memory/cache?
Use case:
I am using render_to_string() to generate a template's HTML for use as an attachment to a EmailMultiAlternatives.
Problem:
I have made changes to the template, sent a subsequent email, yet the changes to the template are not reflected in the email. I have printed the render_to_string() prior to sending the email and it too is not updated, so the problem exists prior to the email part.
Details:
I am using the default settings.TEMPLATE_LOADERS (filesystem/app_directories) for Django 1.7, have tried clearing the cache and have restarted the default development server.
If I change the filename of the template, render_to_string() renders the "changes."
What is even stranger is I have completely removed the template file from the filesystem, yet render_to_string() still renders the original template.
This is a "new problem," as I have modified templates countless times and their changes have been reflected immediately.

Maybe you have that file somewhere else on your file system? Try checking your template file locations in settings.py and review your template files in your file system.

Related

How override woocommerce view-order template?

This page: /my-account/view-order/132616/
... is associated with the view-order.php template file under the my account section. I am able to edit this by going directly into the woocommerce plugin dir, but copying the file into /my-child-theme/woocommerce/myaccount/view-order.php does not have any effect. I am able to edit the orders.php template in this manner, but not this one. I haven't been able to find any answers online to this one: why some of these template files can be copied / overwritten and some cannot be? Also, there appears to be limited scope on applying a hook to manipulate the content on this page. What I want to do, is turn the product names listed here into links back to the products in the store. Thanks for any help!
turns out this doesn't satisfy my need since the content I'm trying to manipulate is in the woocommerce_view_order do_action. Now I'm on the hunt for a filter hook.

How to setup email translation with Django Allauth

I am trying to setup translations for emails with django-allauth.
I have rewritten my templates, translated my .po files and complied them.
The html translations work fine but for some reason just the emails don't get translated.
I have properly configured translations following the django tutorial
https://docs.djangoproject.com/en/1.10/topics/i18n/translation/#how-django-discovers-language-preference
The related question doesn't help:
How does email translation work with django allauth?
Package versions:
Django==1.10
django-allauth==0.27.0
I had the same problem with django-allauth==0.32.0 and Django==1.11.1. Translations that are shipped with allauth are simply outdated or incomplete. In my project, for example, an email with a link to reset the password was always in English (in default language LANGUAGE_CODE = 'en') although the user set the language to Czech.
In .po file for Czech translations: https://github.com/pennersr/django-allauth/blob/master/allauth/locale/cs/LC_MESSAGES/django.po#L408 is this e-mail translation marked as fuzzy – so translations are not used. The same applies to other languages I've checked (de, es...).
The reason is explained in this comment from the author of allauth:
The allauth templates are merely meant as a starting point, something
to get you going quickly. Hence, I do not treat issues in the
translations as blocking for release, which can result in translations
getting left behind. Feel free to submit pull requests to fill in the
gaps.
Source: https://github.com/pennersr/django-allauth/issues/1113#issuecomment-141189606
I think there are two ways to solve this issue:
Fix/update translations on https://www.transifex.com/django-allauth/django-allauth/, submit pull request on Github and wait for a new release.
My recommendation: copy all templates from allauth to your project, make your own *.po files and ignore all default translations/templates. Do not forget that e-mail templates are in *.txt so you must call makemessages this way: python manage.py makemessages ... --extension html,txt,py.

Recover hybrid page Alfresco Share

I've created a new page Aikau, but I changed the XML file and the rendered page content between the standard Share header and footer disappeared.
In this page, I want the arguments of the query string, so I write this code:
page.get.desc.xml:
<webscript>
<shortname>My New Page</shortname>
<url>/hdp/ws/my-new-page</url>
<authentication>user</authentication>
</webscript>
page.get.js:
function main ()
{
// Get the args
var fileProp = args["test"];
model.temp = fileProp;
}
main();
page.get.html.ftl:
Test arg: ${temp}
I have to put /hdp/ws/my-new-page in the XML file to write the content of FTL file in this page... But why did the header and footer of the Alfresco template disappeared ? hdp serves for this purpose. And if I don't put the URL like that on the XML, the page appears with the template.
What is wrong in my code? Or how can I recover the template? Or add header and footer?
EDIT: I already try to put only /my-new-page without /hdp/ws/ but the args are null when I put /hdp/ws/. Give me a hint.
EDIT2: I already try to import alfresco-template.ftl but I can't. Any idea?
You don't actually need to include the the "hdp/ws" part in your WebScript descriptor. Only the "/my-new-page" is required. Aikau attempts to simplify the Surf page creation by providing a number of pages out-of-the-box (and the "hdp" page is just one of them).
Aikau uses URI-template mapping to match a single WebScript to a page, so for example in the URL:
/share/page/hdp/ws/my-new-page
share = application context
page = Spring MVC request dispatcher
hdp/ws/my-new-page is then mapped to the URI template:
<uri-template id="share-page">/{pageid}/ws/{webscript}</uri-template>
Where "hdp" is the id of the page to render and "my-new-page" is the WebScript URL. The HDP page uses the "webscript" token from the template to automatically create a new Surf Component and bind it to the WebScript.
But in short - don't include "hdp/ws" in your WebScript URLs for Aikau pages.
You need to make the things that you have on javascript server in this javascript mandatorily? If not, you can create a javascript client that receive the same arguments (location.search give to you the query string, so, you can make parse of that query string and get only the value of the "test" that you want) and call them on FTL file (the client-side javascript). So, when the page loading, it does not lose the arguments. It isn't the best solution but you can try this...

Which folder to put email templates in, when sending from admin?

I've inherited some code that doesn't work, where a button (with a custom function) exists in the admin page for particular dataobject, and triggers an email to be sent. The code is currently trying to populate the body of the email by using a template file, which is currently in the theme folder for the site.
However, the email body is blank, as the template is not being found. My understanding is that the admin section of the site doesn't look in the theme folder for templates. Where can I put the template (and the other templates it includes) where they can be found from code in the admin part of the site?
$email = new Email($sender_email, $recipient_email, "Your order has been shipped!");
$email->setTemplate("OrderShipped");
$email->populateTemplate(array("Order" => $order));
$email->send();
The error being output to the error log is this:
[17-Nov-2014 14:34:01] Warning at framework/view/SSViewer.php line 780: None
of these templates can be found in theme 'mytheme': OrderShipped.ss
(http://mytestsite.co.nz/admin/orders/MyOrder/EditForm/field/MyOrder)
As the theme is not set when in the backend of the CMS, templates should not be in the themes folder. You can try to move the file into mysite/templates/Email for the main email template. Any includes can be stored in mysite/templates/Includes.
as jfbarrois wrote, the theme is not set in CMS. So I used this small hack and it started to work:
Config::inst()->update('SSViewer', 'theme_enabled', true);
Config::inst()->update('SSViewer', 'theme', 'mysite');
// change 'mysite' with the name of your theme
and you can keep the template in "mysite/templates/Email".
Maybe there's also some other option how to do that, but I haven't found it yet.

Getting file uploads to work with Django & Cloudinary

I am trying to use Cloudinary as a CDN and am having some trouble getting file uploads to work properly. I have followed their blog posts and website, but am running into a consistent and very annoying error.
I have a model associated with both an image (a cover photo) and a media object (a PDF or ebook, like a .mobi or .epub). I have a model form set up to create an object:
class NewMediaObjectForm(forms.ModelForm):
class Meta:
model = MediaObject
fields = ('cover_photo', ...)
cover_photo = CloudinaryJsFileField(options={'tags': 'cover_photo'})
Now, I've read this tutorial from Cloudinary and I know that their form looks like this:
class NewMediaObjectForm(forms.ModelForm):
class Meta:
model = MediaObject
fields = ('cover_photo', ...)
cover_photo = CloudinaryJsFileField(options={'tags': 'cover_photo'})
Here's my problem: if I match their level of indention, the generated HTML shows that the input field is getting all of the right Cloudinary stuff attached to it - but the upload itself doesn't work. The page simply refreshes with an error message stating that no image was selected. Importantly, I can see from the generated HTML that the tags I've specified are coming through.
If I use method #1, with my indention, the file uploads to Cloudinary but none of my tags are applied. It also treats everything as an image, giving me a "invalid image file" error when trying to upload anything other than images (such as the ebook files I mentioned earlier).
I want both - how can I get this upload field to work AND get it to respect the options I'm trying to define?
(I do have cloudinary.config called in the appropriate views; I do have cloudinary_includes and cloudinary_js_config in the appropriate templates; I've imported everything and am calling cl_init_js_callbacks on the form in the view.)
One more addition - I am running this on a local machine using manage.py's runserver rather than deploying, if that has any impact on the configuration.
UPDATE:
I found something I was doing wrong. I've fixed it and made things worse.
The necessary jQuery was not being loaded. Now I am loading it, but the upload button simply doesn't function. I press the button, I select the file, the select dialog disappears, and it shows that no file has been selected. However, I can see that the tags are being passed to the generated HTML, so it's a step in the right direction. Any ideas?
Please forgive me. This was a PEBCAK issue; I will leave this visible for anyone else who may make the same mistakes I've made in the future.
Make sure the proper jQuery scripts are being loaded - open the Chrome developer console, Firebug, whatever and double check. Then, make sure they're being loaded after the DOM so that there are elements for the script to attach to.
Cloudinary will expect html/cloudinary_cors.htmlto be accessible in your static directory.
Either I have broken something, or the default behavior for this particular type of ModelField is to simply IMMEDIATELY upload the selected file and continue displaying "No File Chosen." I thought that nothing was happening and was very surprised when I saw 50+ images successfully uploaded.