I have a python function that is converted to KFP component using #component decorator, like this:
#component(
base_image="image_name:image_tag",
)
def func(arg1):
# I want to get the image used here, e.g. I want to get image = "image_name:image_tag" because I want to use it in the logic inside the function
if image == "image_name:image_tag":
do_something
else:
do_something_else
Is it possible? Thanks
The approach that I would take here is to create an optional parameter that has a default value of the name of your typical base image. Then you can perform your logic based on the parameter value. As far as I know, the documentation does not show the ability to read the base image name defined in the component decorator.
Related
I have a lot of repeating texts inside of my SAPUI5-App. Hence I have the same value with different keys in i18n.
I don't want to merge them into one key because of readability.
one example:
PROFILE_CHAPTER_A=Details
GREET_MESSAGE=Greetings
[...]
WIZARDSTEP_A=Something
WIZARDSTEP_B=Different
WIZARDSTEP_C=In
WIZARDSTEP_D=These
WIZARDSTEP_E=Ones
WIZARDSTEP_F=Details
[...]
#I wish for something like this
GREETING_FORUM={GREET_MESSAGE} {0}, Hello in our Forum!
GREETING_ WEBSOP={GREET_MESSAGE} {0}, Welcome to our Webshop!
You see that PROFILE_CHAPTER_A and WIZARDSTEP_F have the sam value.
In this case I don't want to reference to only one of them because if I'm inside of the view I want a clear naming of the i18n. But if I mean the exact same thing I want to change it only once and not in 5 different keys.
An example of what I imagine should be possible. Maybe I just want to change the "Greetings" to "What's up" or something else and then I just want to reference the first word and have it used by everything else.
Is this i18n-nesting possible in (SAP)UI5? And if not, can it be added?
We use the namespace concept for i18n files:
# Global used
core.detail = Detail
core.button.ok = Ok
# Assuming there is a view with namespace: my.great.app.detail
detail.title = title
# Assuming there are dialog in my.great.app.detail
detail.dialog.confirm.title = Done, saving?
detail.dialog.delete.message = Really?
# another (sub) view: my.great.app.detail.specialParts
detail.specialParts.title = very special
Works also flawless for multi component apps, if you prefix component name.
I am trying to build the name of a var dynamically by concatenating the value of a variable and adding some string afterwards, as I add these variable in runtime. Something like the following should work but it does not.
th:text="${__#{myClass.getA().getB()}+'-result'__}"
Is this even possible to do? I dont know the name of the variable, I can only construct it like this unfortunately.
Yes, that is possible, Thymeleaf supports expression preprocessing:
Let's start with some examples:
The message(i18n) expressions should be referenced using the # character. So let's suppose you have the message.key in your translation file. To reference it in Thymeleaf you will have to use
th:text="#{message.key}"
In your scenario your key name is generated dynamically based on a variable so for preprocessing it in thymeleaf you need to use two underscores __
Let's suppose in your context you have a model variable called myModelVariable with a method messagePrefix(). Our example becomes:
th:text="#{__${myModelVariable.messagePrefix()}__}"
This means the myModelVariable.messagePrefix() will be processed first and the result will be used as the key name which will be then resolved to a nice user friendly message.
And if you also want to add a static part at the end of it will look like this:
th:text="#{__${myModelVariable.messagePrefix()}__}+'*'"
Even the key can contain a static part so this is also accepted:
th:text="#{__${myModelVariable.messagePrefix()}__.staticsuffix}+'*'"
More info you can find in the section 2.7 here:
https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html
I'm wondering if there is a clean way to retrieve an object from its URL with django rest framework. Surely there should be, as it seems to be what's happening when using HyperlinkedRelatedField.
For instance, I have this URL /api/comment/26 as a string. From my view, how can I get the comment instance with pk=26?
Of course I could redo the work and work on the string but it must be a better way?
Thanks a lot.
EDIT:
This is how I solved it at the end:
resolve('/api/comment/26/').func.cls.model will return my model Comment.
resolve('/api/category/1/').kwargs['pk'] will return the pk.
Which gives you:
from django.core.urlresolvers import resolve
resolved_func, unused_args, resolved_kwargs = resolve('/api/category/1/')
resolved_func.cls.model.objects.get(pk=resolved_kwargs['pk'])
I suspect your best bet would be to manually keep a map of models to url patterns — not too dissimilar from a URLConf.
If that doesn't rock your boat you could pass the path into resolve.
This will give you a ResolverMatch upon which you'll find the func that was returned by the as_view call when you set up your URLs.
The __name__ attribute of your view function will be that of your original view class. Do something like globals()[class_name] to get the class itself.
From there access the model attribute.
I hope that helps. As I say, you might just want to map models to URLs yourself.
With class-based views, something like the following seems needed:
resolve(url).func.cls.serializer_class.Meta.model.objects.get(
**resolve(url).kwargs)
Solution above did not work for me, the following did work though:
from django.core.urlresolvers import resolve
resolved_func, unused_args, resolved_kwargs = resolve('/api/category/1/')
resolved_func.cls().get_queryset().get(id=resolved_kwargs['pk'])
additionally this solution uses the built in queryset of your view, which might have annotations or important filters.
Using HyperlinkedModelSerializer I actually needed to do this with a full url. For this to work, you need to extract the path first, resulting in:
import urllib.parse
from django.core.urlresolvers import resolve
def obj_from_url(url):
path = urllib.parse.urlparse(url).path
resolved_func, unused_args, resolved_kwargs = resolve(path)
return resolved_func.cls().get_queryset().get(id=resolved_kwargs['pk'])
I'm looking for a function that would tell me the current object and method by way of the URI. Normally, I would use $this->uri->uri_string(), however, I do not want to pass any "dynamic" segments. For example, a URI of 'products/shoes/123', would be 'products/view_product'.
I want to be able to do this so I can create a config file containing page titles... since I use a model to output my page header. It is called from MY_Controller.php in the construct. For example: $this->template->overall_header($title = "View Product")...
but in the construct, it would be:
$this->template->overall_header($title = $this->config->item($object_method_string));
Anybody have any solutions? Thanks for your time.
for current method
$method= $this->router->fetch_method();
I hope you are talking about this
To expand on Nishant's answer you can access the attributes from the router class.
So for current object;
$this->router->class
And for current method;
$this->router->method
Improving on this question:
Is it good practice to add own file in lib/Varien/Data/Form/Element folder
The accepted answer shows how to extend a Varien form element, but this will not work if you want to package it into a custom module.
What would be the proper method of extending the Varien form element in a module? A simple XML setting I'm hoping?
Update:
Thanks Vinai for the response. Although that does work, I was hoping to extend the form element somehow. My extension is using the base File form element to allow administrators to upload files to categories. So, I'm not directly adding the form elements to the fieldset myself.
I suppose it's possible to to check for the file input on my category block on the backend: Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes , and then change the form element if it is 'file' to 'mycompany_file' -- but this seems like a workaround.
Is there an easier way? Thanks again Vinai.
On the Varien_Data_Form instance you can specify custom element types like this:
$fieldset->addType('custom', 'Your_Module_Model_Form_Element_Custom');
Then, add your element with
$fieldset->addField('the_name', 'custom', $optionsArray);
If you are using a form without fieldsets you can do the same on the Varien_Data_Forminstance, too.
EDIT: Expand answer because of new additional details in the question.
In the class Mage_Adminhtml_Block_Widget_Form::_setFieldset() there is the following code:
$rendererClass = $attribute->getFrontend()->getInputRendererClass();
if (!empty($rendererClass)) {
$fieldType = $inputType . '_' . $attribute->getAttributeCode();
$fieldset->addType($fieldType, $rendererClass);
}
Because of this the attribute frontend_input_renderer on the attributes can be used to specify custom element classes.
This property can be found in the table catalog_eav_attribute, and luckily enough it isn't set for any of the category image attributes.
Given this, there are several ways to apply customizaton.
One option is to simply set the element class in the table using an upgrade script.
Another would be using an observer for the eav_entity_attribute_load_after event and setting the input renderer on the fly if the entity_type_id and the input type matches.
So it is a little more involved then just regular class rewrites in Magento, but it is quite possible.
You don't necessarily need to have a file in the lib/Varien/ directory in order to extend it. If you needed to add an element to that collection, you should be able to extend one of the Elements in your app/code/local module. The answer to the question you referenced seems to also indicate this is the case. I would create your custom field, extending its highest-level function set (i.e., lib/Varien/Data/Form/Element/File.php).
If you want to override the Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes block, then you should extend that block in your module and then reference the new one. You may wish to extend the block using an event observer rather than an XML rewrite, for compatibility purposes.