# HG changeset patch # User Paul Boddie # Date 1507331481 -7200 # Node ID e981fec918769ccbb00d271ad0c02dee2af2f22d # Parent 2ab74bb5e2d99dda7e96bf2dc2b9a1b8b40d240b Extended the new_object function to initialise essential properties. Updated the invite tool to use the enhanced new_object function. diff -r 2ab74bb5e2d9 -r e981fec91876 imiptools/data.py --- a/imiptools/data.py Sat Oct 07 00:39:09 2017 +0200 +++ b/imiptools/data.py Sat Oct 07 01:11:21 2017 +0200 @@ -166,6 +166,9 @@ def get_value(self, name): return get_value(self.details, name) + def set_value(self, name, value, attr=None): + self.details[name] = [(value, attr or {})] + def get_utc_datetime(self, name, date_tzid=None): return get_utc_datetime(self.details, name, date_tzid) @@ -764,11 +767,22 @@ finally: out.close() -def new_object(object_type): +def new_object(object_type, organiser=None, organiser_attr=None): + + """ + Make a new object of the given 'object_type' and optional 'organiser', + with optional 'organiser_attr' describing any organiser identity in more + detail. + """ - "Make a new object of the given 'object_type'." + details = {} - return Object({object_type : ({}, {})}) + if organiser: + details["UID"] = [(make_uid(organiser), {})] + details["ORGANIZER"] = [(organiser, organiser_attr or {})] + details["DTSTAMP"] = [(get_timestamp(), {})] + + return Object({object_type : (details, {})}) def make_uid(user): diff -r 2ab74bb5e2d9 -r e981fec91876 tools/invite.py --- a/tools/invite.py Sat Oct 07 00:39:09 2017 +0200 +++ b/tools/invite.py Sat Oct 07 01:11:21 2017 +0200 @@ -3,7 +3,7 @@ """ Prepare an invitation message. -Copyright (C) 2016 Paul Boddie +Copyright (C) 2016, 2017 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -22,7 +22,7 @@ from datetime import datetime from imiptools.data import get_address, make_uid, new_object from imiptools.dates import get_datetime, get_datetime_item, \ - get_default_timezone \ + get_default_timezone from imiptools.period import Period from imiptools.mail import Messenger from os.path import split @@ -48,9 +48,7 @@ # Create an event for the calendar with the organiser and attendee details. - e = new_object("VEVENT") - e["UID"] = [(make_uid(organiser), {})] - e["ORGANIZER"] = [(organiser, {})] + e = new_object("VEVENT", organiser) attendees = []