Code-completion support for Django template language in Pycharm - django

In the template files code-completion works well for html tags and for adding matching {%,
What I want is for eg: if I type blog. and Ctrl + Space, it should show me the options like blog_title,blog_author etc, that are associated with blog.
Is this possible at all?

I do not think it is possible as PyCharm has no knowledge of the type of objects you pass as context to the template. It could infer it from the view where the template is used but we are not there yet.

It is possible if you register your own template tags with explicit name in your code.
Example: register.tag ("page_attribute", PageAttribute)
See also: https://github.com/divio/django-cms/issues/3878 where the same thing came up.
PyCharm will recognize that and do as you asked.

Related

HelloSign: how to duplicate a template though API?

The following screenshot is the manual approach to duplicate a template.
Is there an API to do it?
# API like this
HelloSignClient.duplicate_template(template_id)
This is Hazem from HelloSign API Support team.
Take a look at the /template endpoints - to replicate the "Duplicate" feature on hellosign.com for templates, you'd use GET /template/files (if you need the original files), and then POST /template/update_files. That creates a new template using the original template's overlay, and the "new" or the same documents that you pass in (which in this case would be files from your GET /template/files call).
For more details about this endpoint, please check the links below:
*Update Template Files
https://app.hellosign.com/api/reference#update_template_files
*Get Template Files
https://app.hellosign.com/api/reference#get_template_files

invalid type literal import - How to import and use my custom service

So I created a simple service with a single class, without constructor : services.RecursiveQuery and added it as a plugin to my Eclipse instance as described in this question.
According to the documentation the next step would be to import it in my template file file so I tried this:
{m:import:services.RecursiveQuery}
However I get this error in the validation file:
Expression "import:services.RecursiveQuery:services" is invalid: invalid type literal import:
What am I doing wrong ? It feels like I'm missing something. Also I was wondering how to use the getAllChildren() method of this service. I would have tried
{m:for child | services.RecursiveQuery.getAllChildren(self)} but that doesnt feel right.
The M2Doc documentation may be unclear on this point: {m:import...} is not a valid statement in a M2Doc template file. It should be used in MS Word document properties, not in the docx template file.
You should use the template properties wizard to change imports along with the solution you mentionned here.
For a better understanding of how to use custom services you can check examples in M2Doc sources.

In dustjs, can I put a template inside a template, where the inner template is defined in partial tag with a string literal?

So I have an object like this {"templateName":"myTemplate","data":{"one":1}}
Here is my template:
{templateName}
{>"{templateName}":data/}
This does not render though (with no error message)...however, it works when I change it to this:
{templateName}
{>"myTemplate":data/}
It renders like this in the view:
myTemplate
[then here it shows myTemplate, rendered with data passed to it]
It renders perfectly and even shows the correct template name on top. I thought that putting the key in the quotes would work, but I guess I am misreading the dustjs guide. How can I accomplish this?
After doing a little digging, I believe I have found the problem. By using the syntax {>"{templateName}":data/}, you are changing the context from root to data. When this happens, templateName is no longer accessible when Dust tries to resolve the template name. So, Dust ends up searching for a template called "". I have filed an issue for this bug.
Having said that, if I were to write a book called "Dust: The Good Parts", I would leave contexts out of it (e.g. {#myData:myContext}). I have found that they cause more problems than they solve.
As a workaround, you can use this syntax:
{templateName}
{>"{templateName}"/}
And then your "myTemplate" would need to do something like:
{data.one}
Here is an example of this working.

Confusion about "data-template-name" and "id" in "<script>" tag

After <script type="text/x-handlebars"
a. I'm wondering in what cases do I put data-template-name and what cases do I put id.
In the guide tutorial video source they use ids exclusively.
In the todomvc source and pretty much everywhere else I've seen, data-template-name is used.
b. And what exactly is put after data-template-name and id (i.e. what comes after their =)?
a) AFAIK id is the newer version of data-template-name, and they seem to work the same.
b) The id allows you to identify a template it in your routing, rendering or 'views'.
For Routing:
You can use this name to help the router identify which template to render, e.g. use this.render('displayStuff) during the renderTemplate in a route, to "override" the default template that belongs to the route.
See also: http://emberjs.com/guides/routing/rendering-a-template/
For Rendering:
Templates allow specific ways to change rendering. Ember-Handlebars provides {{render}} and {{partial}} to change the default template associated to the view.
See also: http://emberjs.com/guides/templates/rendering-with-helpers/
For Views:
By default, a view will find its corresponding template based on convention. So the somethingView has an associated somethingController and a something template (so template with id='something'). A view will also allow to forgo this convention by setting its templateName parameter.
See also: http://emberjs.com/guides/views/inserting-views-in-templates/
hope it helps!
Both work and are correct but data-template-name has a higher precedence and gives you more freedom re: element id's (they wont conflict with template ids)
via http://discuss.emberjs.com/t/ember-components-id-or-data-template-name-in-handlebars-script-tag/3847
also when you move your handlebars templates to stand alone files (production situation lets say) you won't need to worry about id vs data-template-name (let your build tools do this for you based on the template file name)

Multiple Grails scaffolding templates in one application

I'm creating a DB web application with grails for my company and found myself in the need to change the default scaffolding templates.
So far so good, everything gets generated with the modified templates (controllers, views, ..).
Now, however, I get a request to create some "composite screens" with functionalities and a layout that differ from the overwritten templates.
So now my question is: is it possible in grails to create one or more templates (next the the default one) and pass this template name as an argument to the generate-* commands?
Thanks in advance!
EDIT: Adding the template name to the generate commands was just an idea, if it's possible to do this a different way, I'll be happy too.
Grails commands are scripts in grails/scripts. If you follow its logic you will see two things.
1) There is only one parameter passed to the script → domain.
2) Class for generating views is DefaultGrailsTemplateGenerator. You can analyse sourcecode and check what this class offers.
Update
Link to DefaultGrailsTemplateGenerator in GitHub.
I am not sure about the generate command parameters, but if you add another .gsp page into scaffolding directory, I believe it will try to run it through generation process.
So for example I used to have a show.gsp page as well as showBasic.gsp page, which showed fewer properties.