Comments (2)
Ufff yeah, this will be quiet a lot of work 😄 That is mainly the reason why I left out the implementation of many
cardinality for now. But it would be very appreciated contribution!
Originally, I had in my mind read-only approach as the main use case for the many
cardinality. To enable easy access to filtered out entries. For example, have something like:
project = api.Project.get(id=123)
project.time_entries # return all linked Time Entries to the Project
But with the use-case of Tags, there will be the need also for being able to add/remove tags. Tags will be an especially special case because they are serialized as normal array/list for the time entries.
As I am thinking about how to approach this, I believe that the main work will go into implementing a special container that will encapsulate the mapped entries. There should be a general implementation that could be used for the read-only/filter out use-case and then for specific use-cases there would be extended containers that would allow mutability.
You could then specify for the mapping field with many
cardinality, what Container should be used for the field. Something like:
class FilterContainer(AbstractContainer)
...
class Project(api.TogglEntity):
time_entries = field.MappingField(TimeEntry, cardinality=field.MappingField.MANY, container=FilterContainer)
Mapped Container
It is a question on its own, what capabilities of this container should be. I think that it could be quiet similar (at least from an interface point of view) to the SetContainer
. I would start with implementing a general immutable container, for the read-only use-case and then extend on that for the Tag's case.
Few things about the container:
- It should receive the
mapped_cls
and the Entity's instance. - The
mapped_field
could be used as "reverse field" - When the entity is serialized to be saved the serialization should be delegated to the Container from the MappingField, but it should be also allowed to skip the serialization as some of these fields can be "virtual" and should not be sent to Toggl.
The general filter should then have all the information to retrieve the filtered information, it could look something like:
class FilterContainer:
def __init__(self, mapped_cls, reverse_field, instance):
self.entities = mapped_cls.objects.filter(**{reverse_field: instance.id})
MappingField
Mapping field then should mainly do work around constructing the Container, returning it to the user, handling serialization, parsing etc.
Sorry for such a long reply, but hopefully this give you some direction on how to approach this. Let me know if you have any questions, suggestions anything 😄
from toggl-cli.
Thanks for the reply! Initially I thought I was really going to need this many-many relationship for doing what I want with tags. But realizing how Tags are dealt with by Toggl itself, and that they are literally no more than an ID-Name pair means that that part can be pretty low on the list of priorities.
At least getting the read-only version working for e.g. the Project-TimeEntries relationship would still be very nice though. Is probably a better starting point for me to start looking into anyway 😄
from toggl-cli.
Related Issues (20)
- Project Add command incorrectly claims created projects are public by default
- CLI should not show entry is running when time entry has stop == start HOT 3
- sum command doesn't respect configured timezone HOT 1
- Option to set task? HOT 4
- Rework CLI completion with new Click 8.0 release HOT 1
- Unable to find user for TimeEntry HOT 1
- Add `--colors=always` option for passing to `click` HOT 2
- Authentication fail on "ls" command -- but works for other commands
- How do I find entries without project? HOT 1
- Install completion to $ZDOTDIR/.zshrc HOT 4
- toggl projects add -n "asd asd" --color 123 HOT 3
- Flag to quickly do `toggl stop -p $TIME; toggl start -s $TIME ...` HOT 3
- API v8 is being deprecated and shut down by toggle HOT 12
- [Feature request] rewrite in javascript HOT 1
- Add `num-entries` option to `ls` HOT 3
- Print entry description on `toggl start`
- Feature Request: Summed Worklogs Grouped by Description HOT 5
- Python 3.12 Support HOT 3
- Add `TogglServerValidationException` for 400 code errors
- Toggl sessions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from toggl-cli.