Hi,
On 04/23/2018 10:59 AM, guettli wrote:
I have a vague idea to use OOP for a hyperlink.
A hyperlink has these attributes for me:
- href
- verbose name
- Permission: Is the current user allowed to follow the link?
- Preview (on-mouse-over tooltip)
We have developed something similar in the company I work for. The use
case is not exactly the same as yours, but we end up with some "Action"
object that are similar to your "Hyperlink".
We have a mechanism based on mixins to define actions on our models, for
example let's say "create child node". Now each action has some
attributes telling what to display (e.g. "Create new child node") and
what should happen when we click on it (e.g. POST to an URL). Now the
interesting part is that we can also define some restrictions for every
action (e.g. "forbid if user is not part of the manager group, or if a
child already exist for the current object, or ... etc") and we have a
serializer mixin that would automatically embed our actions information
when serializing the model object.
It is then the frontend's job to display whatever you like (description
or restriction) when the mouse is over, and to make the link clickable
or not. If the user tries to trick us with a manual request, we will not
allow the action because the view / model method execution is protected
with the same restriction set.
That is to say, after having defined a list of actions in a model field,
and a list of restriction for each action, we have a fully working
action description and restriction mechanism to manipulate our objects.
It looks a bit like this:
class X(ModelWithActionsMixin, Model):
actions = [ Action(id="create_child", ...,
restrictions=[Restriction(...), ...], ]
@protect(action_id="create")
def add_child(self):
...
or if you want to check the restrictions directly in your view instead
of protecting the method:
class NodeCreateView(...):
def post(self, ...):
obj = self.get_object()
try:
protect_action(obj, "add_child")
except ProtectedActionError as e:
raise Error400(...)
else:
obj.add_child()
Maybe you can use some similar mechanism for your implementation?
PS: we are willing to make a proper package for our stuff and the idea
behind would be to release it as free module, but I can't tell if that
will really happen or when... but to see that you need something similar
will probably push us :-)
I like Django because it handles the "href" part very smart (via
reverse()).
My current use case is the preview tooltip.
The app I develop has roughly ten different report types.
I can't remember the name, but I can remember how the report looked like.
I recall the shape and colors of the report.
That's why I would like to have a on-mouse-over tooltip for the hyperlink.
For example look at these chart types:
https://developers.google.com/chart/interactive/docs/gallery
The tooltip should show a small version of the report/chart if I move
the mouse over the hyperlink.
I don't want to automate the creation of the preview images. It is
enough if I am able to attach a small HTML snippet to
each Django-URL. This HTML snippet should be used for the preview tooltip.
What do you think?
Regards,
Thomas
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/c1df4a33-d077-42c4-8fd0-94902b4fad69%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/c1df4a33-d077-42c4-8fd0-94902b4fad69%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/e8166c20-ba7a-6748-7c1f-4dfd3737e2e3%40init.at.
For more options, visit https://groups.google.com/d/optout.