Re: Crazy Idea: OOP for "Hyperlink"

2018-05-04 Thread guettli
In my use case there is no model involved.

I have a django url-mapping (regex to view) not model.

Regards,
  Thomas Güttler

Am Montag, 30. April 2018 15:55:44 UTC+2 schrieb TonyF-UK:
>
> What is wrong with a special type of Field - which is a URL, but also 
> have augmented data items which are stored on the model? 
>
> As far as I know - there is no rule that states that each 'Field' on a 
> model has to have one and only one field in the database. Even if you 
> have one and only one field in the database, you could capture augmented 
> information about the URL, and store that as a blob field on the model. 
>
> The Custom field would also implement the right methods to turn the 
> field into html, or even a form. 
>
> All possible - the question is how much effort is needed to implement 
> and test this custom Field. 
>
> -- 
> -- 
> Anthony Flury 
> email : *anthon...@btinternet.com * 
> Twitter : *@TonyFlury * 
>
> On 30/04/18 08:24, guettli wrote: 
> > 
> > 
> > Am Donnerstag, 26. April 2018 15:54:31 UTC+2 schrieb Matthew Pava: 
> > 
> > I’ve been thinking about your idea, and I wonder if there could 
> > instead be some kind of widget for URL objects (or views). 
> > 
> > 
> > A widget ... Let me think about it. A widget is a libray, is source 
> code. 
> > The code needs some data to operate on. 
> > Where should the data come from? Where should I store the data? 
> > What kind of data/input does the widget need? 
> > 
> > I have no clue 
> > -- 
> > 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...@googlegroups.com  
> > . 
> > To post to this group, send email to django...@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/fd48e249-9d57-43f5-87e4-09bed383af62%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/fd48e249-9d57-43f5-87e4-09bed383af62%40googlegroups.com?utm_medium=email_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/415bfc09-172e-4346-a42e-664a1d691e17%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Crazy Idea: OOP for "Hyperlink"

2018-04-30 Thread 'Anthony Flury' via Django users
What is wrong with a special type of Field - which is a URL, but also 
have augmented data items which are stored on the model?


As far as I know - there is no rule that states that each 'Field' on a 
model has to have one and only one field in the database. Even if you 
have one and only one field in the database, you could capture augmented 
information about the URL, and store that as a blob field on the model.


The Custom field would also implement the right methods to turn the 
field into html, or even a form.


All possible - the question is how much effort is needed to implement 
and test this custom Field.


--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury *

On 30/04/18 08:24, guettli wrote:



Am Donnerstag, 26. April 2018 15:54:31 UTC+2 schrieb Matthew Pava:

I’ve been thinking about your idea, and I wonder if there could
instead be some kind of widget for URL objects (or views).


A widget ... Let me think about it. A widget is a libray, is source code.
The code needs some data to operate on.
Where should the data come from? Where should I store the data?
What kind of data/input does the widget need?

I have no clue
--
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/fd48e249-9d57-43f5-87e4-09bed383af62%40googlegroups.com 
.

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/ba738bb9-dfd7-b865-f486-a308f7b30bc6%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.


RE: Crazy Idea: OOP for "Hyperlink"

2018-04-30 Thread Matthew Pava
Here’s Django’s documentation on widgets:
https://docs.djangoproject.com/en/2.0/ref/forms/widgets/
>From the docs:
A widget is Django’s representation of an HTML input element.

This whole idea would take some time to implement and consider ramifications.  
After all, a hyperlink isn’t really an HTML input element.

You have urlpatterns being a list of url objects.  If you could somehow take 
the attributes of the url object and copy them to a widget (through an __init__ 
method, for instance), and allow the user to customize those attributes in the 
URLWidget class.  The really tricky thing about it, though, would be handling 
permissions.

I think it is a DRY way of handling the situation.

So the data comes from your urls file, where it is also stored.  The input of 
the widget would be the url objects from the urls file.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of guettli
Sent: Monday, April 30, 2018 2:25 AM
To: Django users
Subject: Re: Crazy Idea: OOP for "Hyperlink"



Am Donnerstag, 26. April 2018 15:54:31 UTC+2 schrieb Matthew Pava:
I’ve been thinking about your idea, and I wonder if there could instead be some 
kind of widget for URL objects (or views).


A widget ... Let me think about it. A widget is a libray, is source code.
The code needs some data to operate on.
Where should the data come from? Where should I store the data?
What kind of data/input does the widget need?

I have no clue
--
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/fd48e249-9d57-43f5-87e4-09bed383af62%40googlegroups.com<https://groups.google.com/d/msgid/django-users/fd48e249-9d57-43f5-87e4-09bed383af62%40googlegroups.com?utm_medium=email_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/aa28590ca7a24873857bf88947c33023%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Crazy Idea: OOP for "Hyperlink"

2018-04-30 Thread guettli


Am Donnerstag, 26. April 2018 15:54:31 UTC+2 schrieb Matthew Pava:
>
> I’ve been thinking about your idea, and I wonder if there could instead be 
> some kind of widget for URL objects (or views).
>
>  
>

A widget ... Let me think about it. A widget is a libray, is source code.
The code needs some data to operate on.
Where should the data come from? Where should I store the data?
What kind of data/input does the widget need?

I have no clue

-- 
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/fd48e249-9d57-43f5-87e4-09bed383af62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Crazy Idea: OOP for "Hyperlink"

2018-04-26 Thread Matthew Pava
I’ve been thinking about your idea, and I wonder if there could instead be some 
kind of widget for URL objects (or views).

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of guettli
Sent: Thursday, April 26, 2018 8:34 AM
To: Django users
Subject: Re: Crazy Idea: OOP for "Hyperlink"



Am Mittwoch, 25. April 2018 17:29:36 UTC+2 schrieb Jani Tiainen:
Hi.

Most probably you get there by creating custom template tag and bunch of other 
code.

It would be easier to grasp your idea if you have some kind of an 
implementation to reference.

Or is there something that stops you from proceeding?


Yes, there is something that stops me: work, family, friends, tennis, sleeping. 
With other words "time".

Nevertheless, even if I had time, I would do asking, talking and thinking for 
some days before taking the keyboard :-)

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/b5c3f2db-f664-4855-a63c-349fb04d398f%40googlegroups.com<https://groups.google.com/d/msgid/django-users/b5c3f2db-f664-4855-a63c-349fb04d398f%40googlegroups.com?utm_medium=email_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/612379414d7f4cf7a2c8aa1185decab9%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Crazy Idea: OOP for "Hyperlink"

2018-04-26 Thread guettli


Am Mittwoch, 25. April 2018 17:29:36 UTC+2 schrieb Jani Tiainen:
>
> Hi.
>
> Most probably you get there by creating custom template tag and bunch of 
> other code.
>
> It would be easier to grasp your idea if you have some kind of an 
> implementation to reference.
>
> Or is there something that stops you from proceeding?
>
>
Yes, there is something that stops me: work, family, friends, tennis, 
sleeping. With other words "time".

Nevertheless, even if I had time, I would do asking, talking and thinking 
for some days before taking the keyboard :-)

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.
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/b5c3f2db-f664-4855-a63c-349fb04d398f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Crazy Idea: OOP for "Hyperlink"

2018-04-26 Thread guettli
I would like to keep both things separated:

- Attributes for URLs
- Access without login

What do you think?

Regards,
  Thomas


Am Mittwoch, 25. April 2018 14:04:22 UTC+2 schrieb TonyF-UK:
>
> Interestingly, I am thinking on something similar too - having a 
> report/notifications/actions view that have an auto generated URL. The 
> idea (on my concept) is that by getting this unique URL via email, a 
> user can access the report/action without needing to actually login - 
> the fact that a user accesses the url is authenticaton - it could 
> optionally require a password, since the userid is effectively part of 
> the URL 
>
> My thoughts : 
>
> Either a specific 
>
> A Notification/Report Model where one of the fields will be the 
> unique URL id 
>  An incoming URL with the right path would search for the 
> notification model with the extracted URL id 
>  My views would search my models for the incoming Id, and 
> confirm expected users, permissions etc. 
>  I would only have one view that needs this so my specific 
> solution would be highly specific 
>
>
> Or a  generic solution 
>
> A model for URLs and that model can have a one to one or one to one 
> to many relationship with other models; clearly this relationship is 
> dynamic so - I see this : 
>
> In the Model : 
>
> from hrefgeneric.models import HRefModel 
>
> class Notification(models.Model) 
>  href = models.OneToOne(HRefModel, ...) 
>  ... 
>
> In the views 
>
> from hrefgeneric.views import HRefRequiredMixin 
>
> class NotificationView(HRefRequiredMixin, View): 
>  class HREFRequired: 
>  login_url = '/login/' 
>  redirect_field_name='redirect_to' 
>  user_name_field = 'username' 
>
>   def get(self, HRef): 
>  # HRef is now the HRef instance relevant to the 
> incoming request (not just any text extracted from the URL 
>pass 
> def post(self, HRef): 
>  # HRef is now the HRef instance relevant to the 
> incoming request (not just any text extracted from the URL 
>pass 
>
>
> If login_url is set to anything truthy, then the mixin will enforce 
> some form of authentication form, with 'user_name_field' set to the 
> expected user name of the HRef (assuming the expected user on the 
> HRef is not None). 
>
> For the generic solution it would be great if there a decorator for 
> non class based views which does something similar. 
>
>  The HRef instance needs the following fields 
>
>  field_name =  # The name of any URL field that 
> this HREF should be matched on 
>  field_value =  # The value that the above field 
> should have for this HREF 
>  user =  # The user that is allowed to 
> access this HREF - can be None 
>  group =  # The permission Group that the 
> user - can be None 
>  permission =  # One or more permissions that 
> the user - can be None 
>
>  On creation, field_name & field_value must be set 
>
>  Example: 
>a pattern like this : 
> path('/notification/', my_view) 
>
>and a href instance : 
>  HRef(field_name='id', field_value='aabbccddeeff') 
>
>   would match against an incoming path of 
>  http://host/notification/aabbccddeeff 
>
>  It might be that we need to match multiple fields on a url - not 
> sure how we do this. 
>
> I would happily contribute to an Django appropriate plugin etc - it 
> seems like there is a lot of commonality between the use cases. 
>
> -- 
> Anthony Flury 
> email : *anthon...@btinternet.com * 
> Twitter : *@TonyFlury * 
>
>
> On 25/04/18 09:30, guettli wrote: 
> > Thank Adrien for sharing your knowledge. 
> > 
> > Our use cases have some parts that are common and some 
> > parts that are distinct. 
> > 
> > You want actions, I want static attributes. 
> > 
> > You define them on the model. 
> > 
> > I use URLs. In my case sometimes there is a 1:1 relationship between 
> > URL and model, 
> > but sometimes not. 
> > 
> > In my use case I have reports. I want a report to have a preview html 
> > snippet. 
> > 
> > There are N reports (N URLs) for one model. 
> > 
> > But I think there are more common things than distinct things. 
> > 
> > One URL can have N attributes. 
> > 
> > Some are actions, some static ones. 
> > 
> > Where these attributes come from is a different topic. 
> > 
> > If the URL  represents a model, the attributes (in your case 
> > "actions") of the model 
> > can be propagated up to the URL. 
> > 
> > I  hope you undestand what I wrote. If not, then tell me. 
> > 
> > Up to now these are just basic thoughts. I won't do 

Re: Crazy Idea: OOP for "Hyperlink"

2018-04-25 Thread Jani Tiainen
Hi.

Most probably you get there by creating custom template tag and bunch of
other code.

It would be easier to grasp your idea if you have some kind of an
implementation to reference.

Or is there something that stops you from proceeding?


ma 23. huhtikuuta 2018 klo 12.00 guettli  kirjoitti:

> 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)
>
> 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.
> 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/c1df4a33-d077-42c4-8fd0-94902b4fad69%40googlegroups.com
> 
> .
> 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/CAHn91ocEskC_8iZBcO9ZJ4xURd-f%3DH%3DppLZbqkpPQZR%2B7SMyWQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Crazy Idea: OOP for "Hyperlink"

2018-04-25 Thread 'Anthony Flury' via Django users
Interestingly, I am thinking on something similar too - having a 
report/notifications/actions view that have an auto generated URL. The 
idea (on my concept) is that by getting this unique URL via email, a 
user can access the report/action without needing to actually login - 
the fact that a user accesses the url is authenticaton - it could 
optionally require a password, since the userid is effectively part of 
the URL


My thoughts :

Either a specific

   A Notification/Report Model where one of the fields will be the
   unique URL id
    An incoming URL with the right path would search for the
   notification model with the extracted URL id
    My views would search my models for the incoming Id, and
   confirm expected users, permissions etc.
    I would only have one view that needs this so my specific
   solution would be highly specific


Or a  generic solution

   A model for URLs and that model can have a one to one or one to one
   to many relationship with other models; clearly this relationship is
   dynamic so - I see this :

   In the Model :

   from hrefgeneric.models import HRefModel

   class Notification(models.Model)
    href = models.OneToOne(HRefModel, ...)
    ...

   In the views

   from hrefgeneric.views import HRefRequiredMixin

   class NotificationView(HRefRequiredMixin, View):
    class HREFRequired:
        login_url = '/login/'
        redirect_field_name='redirect_to'
        user_name_field = 'username'

     def get(self, HRef):
                # HRef is now the HRef instance relevant to the
   incoming request (not just any text extracted from the URL
                      pass
       def post(self, HRef):
                # HRef is now the HRef instance relevant to the
   incoming request (not just any text extracted from the URL
                      pass


   If login_url is set to anything truthy, then the mixin will enforce
   some form of authentication form, with 'user_name_field' set to the
   expected user name of the HRef (assuming the expected user on the
   HRef is not None).

   For the generic solution it would be great if there a decorator for
   non class based views which does something similar.

    The HRef instance needs the following fields

        field_name =  # The name of any URL field that 
this HREF should be matched on
        field_value =  # The value that the above field 
should have for this HREF
            user =  # The user that is allowed to 
access this HREF - can be None
            group =  # The permission Group that the 
user - can be None
            permission =  # One or more permissions that 
the user - can be None


    On creation, field_name & field_value must be set

    Example:
          a pattern like this :
           path('/notification/', my_view)

      and a href instance :
                HRef(field_name='id', field_value='aabbccddeeff')

     would match against an incoming path of
                http://host/notification/aabbccddeeff

    It might be that we need to match multiple fields on a url - not 
sure how we do this.


I would happily contribute to an Django appropriate plugin etc - it 
seems like there is a lot of commonality between the use cases.


--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury *


On 25/04/18 09:30, guettli wrote:

Thank Adrien for sharing your knowledge.

Our use cases have some parts that are common and some
parts that are distinct.

You want actions, I want static attributes.

You define them on the model.

I use URLs. In my case sometimes there is a 1:1 relationship between 
URL and model,

but sometimes not.

In my use case I have reports. I want a report to have a preview html 
snippet.


There are N reports (N URLs) for one model.

But I think there are more common things than distinct things.

One URL can have N attributes.

Some are actions, some static ones.

Where these attributes come from is a different topic.

If the URL  represents a model, the attributes (in your case 
"actions") of the model

can be propagated up to the URL.

I  hope you undestand what I wrote. If not, then tell me.

Up to now these are just basic thoughts. I won't do any coding
during the next days. If someone likes this idea and implements it,
please let me know. I am always curious.

Regards,
  Thomas



Am Montag, 23. April 2018 12:22:32 UTC+2 schrieb Adrien Cossa:

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 

Re: Crazy Idea: OOP for "Hyperlink"

2018-04-25 Thread guettli
Thank Adrien for sharing your knowledge.

Our use cases have some parts that are common and some
parts that are distinct.

You want actions, I want static attributes.

You define them on the model.

I use URLs. In my case sometimes there is a 1:1 relationship between URL 
and model,
but sometimes not.

In my use case I have reports. I want a report to have a preview html 
snippet.

There are N reports (N URLs) for one model.

But I think there are more common things than distinct things.

One URL can have N attributes.

Some are actions, some static ones.

Where these attributes come from is a different topic.

If the URL  represents a model, the attributes (in your case "actions") of 
the model
can be propagated up to the URL.

I  hope you undestand what I wrote. If not, then tell me.

Up to now these are just basic thoughts. I won't do any coding
during the next days. If someone likes this idea and implements it,
please let me know. I am always curious.

Regards,
  Thomas



Am Montag, 23. April 2018 12:22:32 UTC+2 schrieb Adrien Cossa:
>
> 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...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> 

Re: Crazy Idea: OOP for "Hyperlink"

2018-04-23 Thread Adrien Cossa

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 
.
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/c1df4a33-d077-42c4-8fd0-94902b4fad69%40googlegroups.com 
.

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.


Crazy Idea: OOP for "Hyperlink"

2018-04-23 Thread guettli
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)

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.
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/c1df4a33-d077-42c4-8fd0-94902b4fad69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.