Monday, 26 September 2016

Keyword arguments (kwargs) in Custom Views


Custom views are a great way to create widgets in TACTIC.   They combine HTML, CSS, server side Python and client Javascript all in a single self contained widget.  All views in TACTIC have a predefined variable named “kwargs” which contain parameters that are passed to the widget from some external source.  The kwargs variable is a simple dictionary of name / value pairs and represent keyword arguments for that widget.  These kwargs can be used to write highly functional general purpose widgets that can be reused.


In a TACTIC using the Custom Layout Editor, it can be assumed that there is always a kwargs variable which can be simply accessed in the Python section of the custom view.


color = kwargs.get(“color”) or “”
search_type = kwargs.get(“search_type”) or “”


These variables can be accessed in the HTML component using the following syntax:


<div class=”top_element” style=”color: ${color}”>
 <element view=”view1” search_type=”${search_type}”/>
</div>


Thus a variable take from the kwargs are passed from python to an HTML, first to set the color style and second, to pass the search_type to another view which will receive as a kwarg as well.


The variables defined in Python are also accessible in the styles section:


.top_element {
   color: ${color};
}


The kwargs variable is also passed along to the behavior section:


<behavior class=”top_element” event=”click”>
   alert( bvr.kwargs.search_key );
</behavior>


This makes the input variables through kwargs available to all parts of a TACTIC widget.  One often used technique is to go fill in the kwargs variable with custom key / value pairs to simplify the communication of data between Python and Javascript


server = TacticServerStub.get()
count = server.eval(“@COUNT(workflow/asset)”)
kwargs.count = count


And in Javascript


<behavior class=”top_element” event=”click”>
   alert(bvr.kwargs.count)
</behavior>


The kwargs value can be a complex data structure as well:


codes = server.eval(“@GET(workflow/asset.code”)
kwargs.codes = codes


And in Javascript


var codes = bvr.kwargs.codes;
for (var i = 0; i < codes.length; i++ ) {
   alert(codes[i]);
}


Put together, this provides a complete communication for transferring data for server side data to the client side, all encapsulated in a single widget.

21 comments:

  1. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading about keyword arguments. I am impressed with your work and skill. Thank you so much. oracle fusion scm

    ReplyDelete
  2. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform!
    고스톱

    ReplyDelete
  3. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.
    스포츠토토

    ReplyDelete
  4. I got too much interesting stuff on your blog. I guess I am not the only one having all the enjoyment here! Keep up the good work.
    일본야동

    ReplyDelete
  5. Really impressed! Everything is very open and very clear clarification of issues. It contains truly facts. Your website is very valuable. Thanks for sharing.
    토토사이트

    ReplyDelete
  6. This one is very nice! I love it! I hope New Knowledge Hub will help people! But any way if you need some help with essay or homework you can use this beautiful service for essay writing and homework! Just text to them https://topswriting.com/review/essaywriter and be free! Good luck, have fun!

    ReplyDelete
  7. I am hoping the same best effort from you in the future as well and in fact your creative writing skills has inspired me.
    Data Science Course near me

    ReplyDelete
  8. Very great post which I really enjoy reading this and it is not everyday that I have the possibility to see something like this. Thank You.
    Best Online Data Science Courses

    ReplyDelete
  9. I want to thank you for your time in this wonderful read which is really appreciable and put you in your favorites to see new things on your blog, a must-have blog!
    Business Analytics Course in Noida

    ReplyDelete
  10. Nice Post i have read this article and if I can I would like to suggest some cool tips or advice and perhaps you could write future articles that reference this article. I want to know more!
    Data Analytics Course in Gurgaon

    ReplyDelete
  11. Nice post. This is a great article and am pretty much pleased with your good work. Very helpful information. Thank you.
    Best Data Science Courses

    ReplyDelete
  12. Very nice job... Thanks for sharing this amazing and educative blog post!
    Data Science Training in Chandigarh

    ReplyDelete
  13. It’s nearly impossible to find well-informed people for this topic, but you seem like you know what you’re talking about! 바카라사이트인포

    ReplyDelete
  14. This website certainly has all of the information 카지노사이트

    ReplyDelete
  15. Very interesting information and i really glad to getting this information. 토토

    ReplyDelete
  16. Great blog article. Really looking forward to read more.
    바카라사이트

    ReplyDelete
  17. Thank you , this is really useful information towards my assessment. 경마

    ReplyDelete
  18. This is really nice which is really cool blog and you have really helped a lot of people who visit the blog and give them useful information.
    Data Science Training in Noida

    ReplyDelete
  19. Well done for this excellent article. and really enjoyed reading this article today it might be one of the best articles I have read so far and please keep this work of the same quality.
    Data Analytics Course in Noida

    ReplyDelete