Customise title in the WK Status Bar - watchkit

I'm trying to customise title in the WK Status Bar of my first Controller.
The correct way should be this:
public func setTitle(title: String?) // title of controller. displayed when controller active
so
WKInterfaceController.setTitle("my Title")
but using this code, xCode says Cannot convert value of type 'String' to expected argument type 'WKInterfaceController'. What's wrong?

setTitle is an instance method, not a class method.
You need to refer to a specific instance controller to change that controller's title. Since you would generally be setting your first controller's title within its own code, you can omit self, and simply call
setTitle("my Title")

Related

Alfresco - add recipient's name to workflow notification email template

I'm using Alfresco 5.2 Community. I'm trying to edit the template wf-email.html.ftl file found in Repository> Data Dictionary> Email Templates> Workflow Notification> wf-email.html.ftl.
In the line
<p>Hi,</p>
I want to add the recipient's name in the message, something like
<p>Hi John,</p>
Is this possible? If yes, how is it achieved?
Unfortunately, the assignee is not passed as an argument to the template, so it is not available to the template. You can see this by looking at the source of the class that actually sends the notification:
https://github.com/Alfresco/alfresco-repository/blob/master/src/main/java/org/alfresco/repo/workflow/WorkflowNotificationUtils.java
Looking at that class you can see where things like the workflow ID, title, and description are added as arguments that get passed to the template renderer:
templateArgs.put(ARG_WF_ID, taskId);
templateArgs.put(ARG_WF_TITLE, taskTitle);
templateArgs.put(ARG_WF_DESCRIPTION, description);
But the assignee is not passed.
You could lookup the workflow and then get the current task and then get the assignee to that task, but that's probably not the best way to go about it.
If you really need this, I would extend the existing WorkflowNotificationUtils.java with my own, and add in the assignee as an argument to the template. Or I'd turn off the default notifications and just use my own notification classes that my custom workflows call.

How can I define http.route(‘URL’) which will generic for all pages or dynamic url with dynamic page rendering in odoo 11 web controller?

I want to use below method which is call while rendering any page. If I pass ‘/’ in http.route it will call only for homepage not for others like ‘/shop’, ‘/blog’ etc. Also wanted to pass dynamic template rendering in return on the basis of http.route(‘URL’).
#http.route(['/'], type='http', auth="public", website=True)
def cusotm_controller_func(self, **kwargs):
values= { # values which is passing in template }
return request.render('website.homepage', values)
Can anyone help me out?
Thanks.
Maybe you need to call your function in another moment, like after the models registry(pool) is loaded. You could do this by implementing the method _register_hook in your model. Odoo will always call that method in your model to allow you to initialize whatever you want, but you just have the self and cr arguments.
Maybe helps
Thanks to from odoo forum.
Solution :
Controllers are registering itself in the openerp.http.controllers_per_module dict (see code)... so you can get controller instance using module name and controller name under it:
from odoo.http import controllers_per_module
controller_instance = None
for name,instance in controllers_per_module.get('my_module'):
if name.endswith('my_module.controller.name'):
controller_instance = instance
break
if controller_instance != None:
controller_instance.a_function(*args)

adding a button in tryton view form

hi i have been searching and i cant find any tutorial about how to add a button in my view_form part of a custom module.
i wanted to add a button and make it call a method i made every time it is clicked.
in xml view form :
<label name="fieldstring"/>
<field name="fieldstring"/>
<button name="dosomething"/>
code:
def dosomething(cls,records):
#treatement
is there any example module that is using a button associated to a treatment??
In order to add a button to a view you have to make 3 steps:
Add the button to the _buttons dictionary of ModelView class. Normally this is done in the setup method of your class. Here you can define the icon and the states (when the button is invisible for example). If nothing needed you can define it with an empty dictionary.
For example:
#classmethod
def __setup__(cls):
super(Class, cls).__setup__()
cls._buttons.update({
'mybutton': {},
})
More complex examples can be found on tryton modules, for example:
http://hg.tryton.org/modules/account_invoice/file/84a41902ff5d/invoice.py#l224
Declare your method and decorate it with ModelView.button (in order to check access right to this button). For example:
#classmethod
#ModelView.button
def mybutton(cls, records)
#DO whatever you want with records
NOTE that the name method must be the one that you use as key of the _buttons dictionary in step1.
And finally add it to the view. You can find all the attributes that can be used on:
http://doc.tryton.org/3.2/trytond/doc/topics/views/index.html?highlight=button#button
Note that the string and name attributes are mandatory.
Also the name must be the name of the method to call, defined in step 2.
You can find some examples in:
http://hg.tryton.org/modules/account_invoice/file/84a41902ff5d/view/invoice_form.xml#l51

ErrorBinding Spring portlet MVC

Disclaimer: I wished I had a through understanding before starting working with the framework.
But as it is of now, I'm lacking on that front, and hence the question.
I am working with Spring-Portlet MVC.
I have a flow, where in I take an input on a screen, validate the input, depending upon its result it either render same screen or next screen.
Implementation detail:
I have an action method which takes form backed command object. It checks whether entered input is valid or not. If it is not valid, it populate error message in BindingResult instance it takes as another argument.
We have different render method, to render different screen.
I'm taking command object as an argument in these render method. This command object I'm receiving is same as one passed to action.
Problem:
While rerendering a screen spring-mvc should bind the error message populated in action method. Currently when I take command object as argument in render method spring-mvc is somehow unable to bind that error message. But interesting enough it is able to bind the error message if I don't take command object as argument in render method and rather create a new command object altogether there.
can,some one having better understanding of spring-portlet mvc please explain this behaviour, or tell where I am lacking in understanding.
Regards,
Mawia
EDIT: Just to enrich the below answer: Though I didn't exactly isolated the issue which was causing the said behaviour, but the way I met my requirement was using modelattribute. ModelAttribute can be used either on method or a parameter to a method. It ensures that model will made available to all the call till the view is render(that is my understanding!). So we don't need to take command object as parameter in Render method, just annotate the commandObject parameter in action method with ModelAttribute and then you can get the same object returned from model as suggested in the answer below.
I don't think the command/model object should be an argument/parameter in the render method. I have had the same issue trying to get the validation error messages when command/model is defined as argument in render method signature. I typically have the command/object creation/populate in a separate method, like this:
#ModelAttribute(value="address")
public Address getAddress(#RequestParam Integer id){
Address address = null;
if(id != null){
address = myService.getAddress(id);
}else{
address = new Address();
}
return address;
}
If I still need to access the ModelAttribute/command object from the render method, I typically get it by:
#RenderMapping
public String showAddressPage(ModelMap modelMap){
Address address = modelMap.get("address");
//make any additional changes to address
}
I used this example as reference article

Link between CCK field and view

I want to use a view to select nodes in a content type field. This view must receive an argument that is another field of the content type.
Can someone explain me how to pass the argument from the field to the view?
Excuse my poor english
You might be able to use the Views Arguments Extras module. It will allow the argument of the view to come from a cck field. Some more details about this module (from its project page):
This module contains a group of view handlers and plugins that add the following options:
Argument Default Current Node CCK
allows for cck field values of the current node to be loaded as default arguments
Argument Default Request Params
allows for get and post params as default values
Argument Order Sort
a sort handler, that allows for the order of items to be based on their order in a multi-value argument
I believe you can use the argument validation to validate the argument, and at that point you are free to change the $handler->argument value before it is passed in to Views.
If you just want to change what the view displays based on the value of a CCK field, the easiest way I have found is to embed a view into the template using views_embed_view(). Something like this in your template file would work I think:
//Use the dsm function to print out your $node object
//to get the name of the field you want to pass as an arg
//like this: dsm($node);
//Assuming that the value of that field is in $node->cck_field['0']:
print views_embed_view('name_of_view', 'name_of_display', $node->cck_field['0'];
views_embed_view() only needs the first argument, the name of the view, to work. It will return the HTML for the default display of the named view. We pass it a specific display as a second argument. Anything after the second argument gets passed into the view as an argument, so we pass in the value of the field as an argument to the view. See this link for some documentation on how the function works.

Resources