I’m trying to load the parameterization. I’m using API().get_current_user().full_name and it works in the Controller class. But it doesn’t work in the parameterization class because I get the error 'User' object has no attribute '_generate_entity_type'.
Is it possible to get the user details in parameterization? Or should I load it into one of the Views and do my processing there?
It’s okay I just figured it out. I just have to declare an empty property in Parameterization and then update it after it’s been initialised in the Controller class.
class Parametrization(ViktorParametrization):
self.user = None
...
class Controller(ViktorController):
user = API().get_current_user().full_name
parametrization = Parametrization
parametrization.user = Text("Welcome " + user)
Welcome to the community! And great to see how you are experimenting.
I believe that, although you got it working, that this won’t give the expected results in production. It seems that you want to have a means to present a dynamic text in the Parametrization.
There is an approach for this, by making use of the OutputField. This, however, renders the result as a greyed-out field. I believe what you ideally want is an OutputField type of feature that renders your text as normal text. There is already an existing feature request for this. If this is what you want, I would recommend upvoting this feature request, and maybe add some context to that thread:
I believe that, although you got it working, that this won’t give the expected results in production.
To add a bit more on how this works (and that it might not behave like you expected)
the code directly underneath the Controller and Parametrization classes is only executed when the app is started.
in development this happens every time you explicitly call viktor-cli start / viktor-cli clean-start or when the code autoreloads
in production the app is not often restarted and it can run for a long time without reloading. this would mean that it does not change every time some-one enters the app
@PanjiBrotoisworo: im also curious how you got it to work in the first place. could you share a fully working code snippet?
Hi @matthijs, I’m currently using the SDK API externally in order to obtain more detailed reports than allowed by the audit.
It would be very helpful to access the full name of a user who created an entity.
I believe some of the content in this thread could serve as a workaround, but I wanted to check if you knew of a ‘proper’ way to retrieve the full name of a user who created an entity (assuming you already have the entity object) ?
Hi @kassi, in order to get these full names i think you should resort to the REST API (the SDK API functions don’t have a python equivalent to get this information i think)
A nice resource to learn about the difference between the two:/