Draft: Functionality to add shopping items to basket from IDA.
3 unresolved threads
3 unresolved threads
Compare changes
+ 59
− 3
@@ -36,9 +36,13 @@ class shopping_client:
@@ -87,6 +91,56 @@ class shopping_client:
Basically, I think it should be possible to just add to the list of shopping items using patch, but in fact one has to replace the original with a complete updated version. This is probably expected behaviour, but I wasn't expecting it. Maybe because the list of shopping items is a single field in the user profile model.
@@ -102,12 +156,14 @@ class shopping_client:
I'm wondering about the semantics of this.
As I read the code (I confess, I've not tested it directly), the user will normally get a
list
(or aDataFrame
) by callingget_basket()
. Isn't the natural thing for them to do to simply manipulate thatlist
— adding, removing, altering items — and have those changes synced back to ESAP (either automatically, or on demand)?Maybe easier to put that in pseudocode. The current workflow would look something like this:
I guess what seems weird in the above API is that I'm manipulating the contents of the shopping basket by calling methods on some other objects.
I'm imagining an API that looks more like:
This is possible but it would require some refactoring. Basically the basket would have to be implemented as its own class that provides an append method. Not sure how to expose the underlying data container DF/list either. Some of the plugins may rely on certain behaviour. Tricky.
Is the basket not a
list
? (Leaving asideDataFrame
s for the moment for simplicity). Maybe not; I should look in my Copious Free Time.If the user doesn't set the
convert_to_pandas
argumentTrue
inget_basket()
then the internal representation is just a list, yes. Otherwise, it's a pandas data frame. Notwithstanding, I think what you're talking about would involve making aBasket
class with a list-like interface, or which at least implementsappend()
. Plus I'm assuming you'd either want append to immediately update the basket entry in the database or to have asave()
orcommit()
method too (and something like ato_pandas()
method for users who do want a pandas data frame to work with). It's not difficult to do that, but it is a major API change and I'm not sure if any of the plugins developed so far rely on theconvert_to_pandas
functionality. It might also be worth asking the various archive plugins to provide amake_basket_entry()
method to avoid the hacking that Nico mentions in esap-general#68 (comment 23686)Hi Hugh — sorry for leaving this idle for so long.
Basically, yes, I think your summary of my requests is about right. I'm worried that the API currently in this MR is confusing to the naive user as to what's going on. The fact that I can do
without actually adding anything to the shopping basket seems weird; worse is that if I then try to add something using the “correct” method it explodes:
My fairly off-the-cuff suggestion is that
ShoppingClient
should be aMutableSequence
which stores the “raw” basket as alist
of JSON strings internally. Aget_as_pandas
method could return a copy of the data as a dataframe. I can think more about this and write down a concrete proposal if that would be helpful (but not today...).I think it's better to break the API now, before we have any widespread deployments; changes will only get more painful with time.
Thoughts welcome! Please push back if you think I'm crazy... :-)
Hi John,
I don't think it will be difficult to implement what you want but a concrete proposal would indeed be useful. No need to have it immediately though :-)
Cheers,
Hugh