CardDAV implementation in Tryton

Hello,

I read this section of the doc and it mentions that Tryton can act as a CardDAV server. I really like the idea of being able to integrate Tryton contacts in e-mail clients like Thunderbird or Outlook, even if it’s a one-way synchronization.

Then when I searched the forum, I read this post about *DAV removal…

What is the current status of the CardDAV implementation?

I’d be interested as well.
I’m using owncloud as a CardDAV and CalDAV server with various clients, which works very well. Double data storage is not what we want, so my wish is tryton to act as a CardDAV client, so it can achieve party (address) data. Acting as a CardDAV server would work as well.

But maybe I didnt at all understand the concept of handling and providing party (address) data in tryton at all, and someone could give me a hint.

For now, nothing happened on this topic (except the removal of unmaintained code).
I think the direction to go would be to server through HTTP a readonly vCalendar and vCard file which will allow CalDav and CardDAV server to synchronize with and share.

1 Like

Yes, I fully agree. Shall I file a RFE?

Only if you are going to work on it: Tryton - How to Develop

In case you’re talking about coding - sorry, I’m just a dumb user.

We created a small carddav solution (tryton v6.0). It adds some fields to the party module and uploads the vcards to a carddav adressbook on our nextcloud by cron-job. It’s just one way. By this we got the contacts available in thunderbird, local phones and smartphones. If anybody is interested, we’ll create a clean module and upload it to pypi.

Which fields are added? Why are they needed?

Indeed generating the file as URL on tryton will be easier as you will not require the nextcloud server. This implementation will be generic enought to be included as tryton official module.

Do you think that will work for your use case? If nextcloud supports syncing from external cardav it will just require to read the tryton url and it will work.

Mainly just a vcard-table is added and related to the party.
If you like to have a look at th emodule, it’s on the way to you on the private channel.
Here two screenshots:
Party-Config-panel:


Party:

But to get the information we need, we added a module to get First Name, Last Name, Nickname, pre/subfix, Birthday …
Please have a look at it. … It’s on its way to you :wink:

One more note: Even it be a nice feature, if Tryton could/would deliver the vcards without another service to other clients, I do not really see the need for this, because we have to run and administrate those carddav/caldav services anyway.

When the carddav / caldav modules were removed there were some alternatives listed. One was Radicale (GitHub - Kozea/Radicale: A simple CalDAV (calendar) and CardDAV (contact) server.) which is a simple carddav / caldav server. It uses now a filestorage as backend, but it should be possible to make a Tryton backend for it, so the data is directly taken from Tryton.

What you need to administrate? As far as the user has access to it on Tryton it should be able to see such data on other services. So Tryton is where the access rights should be defined.

For me it’s easier than syncing to an external service.
Indeed we implemented the Caldav sincronization using this pattern on a custom module and it works like a charm.

Hi Sergi, might we have a look at your caldav tool? It should be quite a small afford to integrate the vcard/carddav to it … ?
But to get you right, your Tryton-ical-solution acts as a caldav-server? That sounds great.

We have some more adressbooks/contacts and calenders/events (which aren’t and do not necessarily need to be managed by Tryton) that we need to handle by our groupware (before we used SOGo, now nextcloud, radicale should be fine, too) and manage/grant privileges (read, write, private, public, limited visible, …) just the standard caldav/carddav properties.

So, if we have the chance to integrate it, great. But we didn’t make it further than our carddav-interface.

Here is the relevant code:

from ics import Calendar, Event
from werkzeug.wrappers import Response

from trytond.model import ModelSQL, ModelView
from trytond.protocols.wrappers import with_pool, with_transaction
from trytond.wsgi import app

# In your model definition


class Appointment(ModelSQL, ModelView):

    def to_ics_event(self):
        event = Event()
        event.begin = self.date
        end = self.end_date
        if self.end_date and self.end_date < self.date:
            end = None
        event.end = end
        event.name = '%s - %s' % (self.pet.rec_name, self.owner.rec_name)
        description_lines = [self.type_.rec_name, self.veterinarian.rec_name]
        event.description = '\n'.join(description_lines)
        event.state = self.state_string
        event.uuid = self.id
        event.created = self.create_date
        event.last_modified = self.write_date
        return event

# In routes.py


def create_calendar(Model):
    calendar = Calendar()
    for record in Model.search([]):
        event = record.to_ics_event()
        if not event:
            continue
        calendar.events.add(event)
    return calendar


@app.route('/<database_name>/appointments.ics', methods=['GET'])
@app.auth_required
@with_pool
@with_transaction(user='request', context=dict(_check_access=True))
def appointments(request, pool):
    return Response(
        str(create_calendar(pool.get('vet.appointment'))),
        content_type='text/calendar')

We are using the ics library to abstract the generation of the Calendar format. Although I did not found any library for generating vCard I think we can just return the text representation of it directly.

Then you just need to combine the data from Tryton with the other in your groupware server. For me this is out of the scope of Tryton and should be something that your groupware server is responsible for.

2 Likes

Hi.
I am actually very interested in this - specifically a CardDav server so we can access the contacts from clients like thunderbird,…
since the last post here is nearly a year old I’d like to ask first if anyone made any progress there, or if there is a consensus which is the best way to go about it (meaning do we want to implement it directly in tryton with an HTTP server or do we rather want to automtically sync it - to nextcloud for example,…) – or write a tryton storage bakcend for some groupware/carddav server’s contacts sync.

If there is nothing currently working/available I will probably start writing up some basic vcard generation first and then see about how to publish it one way or another.

In any case… any updates by people who already have stuff like this running would be greatly appreciated (combining efforts to make an official module would be even better of course :wink: )

For me this is the simpler way to implement what you are requesting.

you mean serve the CardDav trhough HTTP from tryton directly I assume?

Yes, I already posted an example about how to implement for sharing events in caldav.

So you just need to create a route that exposes the party data as cardDav and then just read such URL.

1 Like