Hi everyone,
I am having a problem with creating a parent Infolog and child Infologs.
- I have attached an email to a group to create with Infolog but there is a problem that it does not work with the group email.
- When I create the parent Infolog, it has a UID but creating subs by UID is completely impossible to attach.
def create_task_on_egroupware(request, title, egroupware_group_id, description, parent_uid=None):
API_URL = settings.EGROUPWARE_API_URL
username = request.user.username
password = settings.EGROUPWARE_CREDENTIALS.get('password')
api_url = f"{API_URL}/{username}/infolog/"
headers = {
"Content-Type": "application/json",
"Prefer": "return=representation",
"Accept": "application/pretty+json"
}
# š¹ Lįŗ„y thį»i gian hiį»n tįŗ”i theo chuįŗ©n UTC, Äį»nh dįŗ”ng ISO 8601
start_time = datetime.now(timezone.utc).isoformat()
# š¹ Lįŗ„y thĆ“ng tin nhĆ³m tį»« ExtendedGroup dį»±a vĆ o egroupware_group_id
try:
group = ExtendedGroup.objects.get(egroupware_group_id=egroupware_group_id)
group_name = group.group.name # Lįŗ„y tĆŖn group
group_email = group.email_manager # Lįŗ„y email manager
group_principal_url = f"principals/groups/{group_name.lower()}/" # DĆ¹ng principal-URL
except ExtendedGroup.DoesNotExist:
print(f"ā Group not found for egroupware_group_id = {egroupware_group_id}")
return None
# š¹ Äį»nh nghÄ©a payload
payload = {
"title": title,
"start": start_time, # Thį»i gian tįŗ”o task
"timeZone": "Europe/Warsaw", # MĆŗi giį»
"description": description, # MĆ“ tįŗ£ task
"priority": 5, # Äį» Ę°u tiĆŖn mįŗ·c Äį»nh
"participants": [
{
"@type": "Participant",
"name": group_name,
"uri": group_principal_url, # š¢ DĆ¹ng principal-URL thay vƬ email
"email": group_email,
"kind": "group",
"roles": {"attendee": True}
}
],
"status": "confirmed",
"progress": "needs-action",
}
# Nįŗæu cĆ³ nhiį»m vį»„ cha, thĆŖm `relatedTo` ÄĆŗng Äį»nh dįŗ”ng
if parent_uid:
payload["relatedTo"] = {
parent_uid: {
"@type": "Relation",
"relation": "parent"
}
}
print(f"š¹ Sending request to EGroupware: {json.dumps(payload, indent=2)}")
# š¹ Gį»i request lĆŖn EGroupware
response = requests.post(api_url, auth=(username, password), headers=headers, json=payload)
print(f"š¹ Response status: {response.status_code}")
print(f"š¹ Response text: {response.text}")
# š¹ Xį» lĆ½ lį»i JSONDecodeError nįŗæu phįŗ£n hį»i rį»ng
if response.status_code == 201:
try:
result = response.json()
return result.get("uid", None) # Trįŗ£ vį» UID cį»§a task vį»«a tįŗ”o
except json.JSONDecodeError:
print(f"ā ļø JSONDecodeError but task created successfully.")
return "Task Created (No JSON Response)" # Giįŗ£ lįŗp UID
else:
print(f"ā ļø Error creating task: {response.text}")
return None
def wait_for_task_creation(api_url, auth, task_uid, headers, max_retries=10, wait_time=5):
for i in range(max_retries):
print(f"ā³ Check if parent task exists... Attempt {i+1}/{max_retries}")
response = requests.get(api_url, auth=auth, headers=headers)
if response.status_code == 200:
try:
tasks = response.json().get("responses", {})
# Kiį»m tra nįŗæu task cha ÄĆ£ xuįŗ„t hiį»n
for task_url, task in tasks.items():
if task.get("uid") == task_uid:
print(f"ā
Task parent {task_uid} exists in EGroupware!")
return True
# š¹ Nįŗæu chĘ°a tƬm thįŗ„y, thį» tƬm theo title
print("ā ļø Task parent {task_uid} not found, searching by title...")
title_search_url = f"{api_url}?filter[title]=Room 101"
search_response = requests.get(title_search_url, auth=auth, headers=headers)
if search_response.status_code == 200:
task_data = search_response.json().get("responses", {})
for task_url, task in task_data.items():
if task.get("title") == f"Room {room_number}":
found_uid = task.get("uid")
print(f"ā
Task parent {found_uid} exists in EGroupware!")
return found_uid # Trįŗ£ vį» UID mį»i
except json.JSONDecodeError:
print("ā ļø JSONDecodeError - Response is not valid JSON. Try again...")
time.sleep(wait_time)
print(f"ā Task parent {task_uid} does not exist after {max_retries} retries!")
return False
def create_checkout_room_task(request, room_number):
extended_group = get_object_or_404(ExtendedGroup, group__name="housekeeping")
egroupware_group_id = extended_group.egroupware_group_id
# Tįŗ”o Task cha
parent_uid = create_task_on_egroupware(
request,
title=f"Room {room_number}",
egroupware_group_id=egroupware_group_id,
description=f"Room {room_number}"
)
if not parent_uid:
return "ā Error creating Task Room on EGroupware!"
# Chį» task cha xuįŗ„t hiį»n trĘ°į»c khi tįŗ”o sub-task
API_URL = settings.EGROUPWARE_API_URL
username = request.user.username
password = settings.EGROUPWARE_CREDENTIALS.get('password')
headers = {"Accept": "application/pretty+json"}
if not wait_for_task_creation(f"{API_URL}/{username}/infolog/", auth=(username, password), task_uid=parent_uid, headers=headers):
print(f"ā ļø The parent task {parent_uid} does not exist. Try retrieving the task list from the EGroupware API...")
response = requests.get(f"{API_URL}/{username}/infolog/?filter[title]=Room {room_number}", auth=(username, password), headers=headers)
if response.status_code == 200:
try:
task_data = response.json().get("responses", {})
for task_url, task in task_data.items():
if task.get("title") == f"Room {room_number}":
parent_uid = task.get("uid")
print(f"ā
Found parent task again: {parent_uid}")
break
except json.JSONDecodeError:
print(f"ā JSONDecodeError - Response is not valid JSON. Try again...")
if not parent_uid:
return f"ā The parent task {parent_uid} has not yet been recorded in the system.!"
# Lįŗ„y danh sĆ”ch sub-task tį»« TaskTemplate
sub_tasks = TaskTemplate.objects.filter(task_type="Cleaning vacant rooms")
for task in sub_tasks:
subtask_description = f"""
Task Parent: Room {room_number}
Area: {task.area}
Task: {task.name}
"""
create_task_on_egroupware(
request,
title=f"Room {room_number}: {task.name}",
egroupware_group_id=egroupware_group_id,
description=subtask_description.strip(),
parent_uid=parent_uid
)
return f"ā
Task Room {room_number} and sub-tasks have been created on EGroupware!"
Sending request to EGroupware: {
ātitleā: āRoom 101ā,
āstartā: ā2025-03-05T12:05:22.232169+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āRoom 101ā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā
}
Response status: 201
Response text: {
"@type": āTaskā,
āprodIdā: āEGroupware InfoLog 23.1.011ā,
āuidā: āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā,
ācreatedā: ā2025-03-05T12:05:22Zā,
ātitleā: āRoom 101ā,
āstartā: ā2025-03-05T13:05:22ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āRoom 101ā,
āparticipantsā: {
ā1067ā: {
"@type": āParticipantā,
ānameā: āTuan Nguyen Leā,
āemailā: "ngletuan94@gmail.com",
ākindā: āindividualā,
ārolesā: { āownerā: true }
},
āhousekeeping -1008@lists.egroupware.orgā: {
"@type": āParticipantā,
ānameā: āhousekeepingā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āindividualā,
ārolesā: { āinformationalā: true }
}
},
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
āpriorityā: 9,
āprivacyā: āpublicā,
āegroupware.org:typeā: ātaskā
}
Check if parent task existsā¦ Attempt 1/10
Task parent urn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5 exists in EGroupware!
Sending request to EGroupware: {
ātitleā: āRoom 101: Change bed linens and sheetsā,
āstartā: ā2025-03-05T12:05:22.470393+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āTask Parent: Room 101\n Area: Hotel\n Task: Change bed linens and sheetsā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
ārelatedToā: {
āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā: {
"@type": āRelationā,
ārelationā: āparentā
}
}
}
Response status: 422
Response text: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
ļø Error creating task: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
Sending request to EGroupware: {
ātitleā: āRoom 101: Vacuum the entire room and bathroomā,
āstartā: ā2025-03-05T12:05:22.541383+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āTask Parent: Room 101\n Area: Hotel\n Task: Vacuum the entire room and bathroomā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
ārelatedToā: {
āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā: {
"@type": āRelationā,
ārelationā: āparentā
}
}
}
Response status: 422
Response text: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
ļø Error creating task: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
Sending request to EGroupware: {
ātitleā: āRoom 101: Dust the desk, wardrobe, doors, windowsills, lampsā,
āstartā: ā2025-03-05T12:05:22.610553+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āTask Parent: Room 101\n Area: Hotel\n Task: Dust the desk, wardrobe, doors, windowsills, lampsā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
ārelatedToā: {
āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā: {
"@type": āRelationā,
ārelationā: āparentā
}
}
}
Response status: 422
Response text: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
ļø Error creating task: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
Sending request to EGroupware: {
ātitleā: āRoom 101: Clean the kettle and cupsā,
āstartā: ā2025-03-05T12:05:22.682884+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āTask Parent: Room 101\n Area: Hotel\n Task: Clean the kettle and cupsā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
ārelatedToā: {
āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā: {
"@type": āRelationā,
ārelationā: āparentā
}
}
}
Response status: 422
Response text: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
ļø Error creating task: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
Sending request to EGroupware: {
ātitleā: āRoom 101: Refill the coffee and tea set, leave a bottle of waterā,
āstartā: ā2025-03-05T12:05:22.759663+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āTask Parent: Room 101\n Area: Hotel\n Task: Refill the coffee and tea set, leave a bottle of waterā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
ārelatedToā: {
āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā: {
"@type": āRelationā,
ārelationā: āparentā
}
}
}
Response status: 422
Response text: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
ļø Error creating task: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
Sending request to EGroupware: {
ātitleā: āRoom 101: Check the hotel service brochure set, restock if necessaryā,
āstartā: ā2025-03-05T12:05:22.828724+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āTask Parent: Room 101\n Area: Hotel\n Task: Check the hotel service brochure set, restock if necessaryā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
ārelatedToā: {
āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā: {
"@type": āRelationā,
ārelationā: āparentā
}
}
}
Response status: 422
Response text: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
ļø Error creating task: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
Sending request to EGroupware: {
ātitleā: āRoom 101: Clean the ceiling and remove cobwebsā,
āstartā: ā2025-03-05T12:05:22.893179+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āTask Parent: Room 101\n Area: Hotel\n Task: Clean the ceiling and remove cobwebsā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
ārelatedToā: {
āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā: {
"@type": āRelationā,
ārelationā: āparentā
}
}
}
Response status: 422
Response text: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
ļø Error creating task: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
Sending request to EGroupware: {
ātitleā: āRoom 101: Clean the fridge, discard any leftover productsā,
āstartā: ā2025-03-05T12:05:22.969534+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āTask Parent: Room 101\n Area: Hotel\n Task: Clean the fridge, discard any leftover productsā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
ārelatedToā: {
āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā: {
"@type": āRelationā,
ārelationā: āparentā
}
}
}
Response status: 422
Response text: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
ļø Error creating task: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
Sending request to EGroupware: {
ātitleā: āRoom 101: Clean windows, frames, and windowsills (both sides)ā,
āstartā: ā2025-03-05T12:05:23.035995+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āTask Parent: Room 101\n Area: Hotel\n Task: Clean windows, frames, and windowsills (both sides)ā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
ārelatedToā: {
āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā: {
"@type": āRelationā,
ārelationā: āparentā
}
}
}
Response status: 422
Response text: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
ļø Error creating task: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
Sending request to EGroupware: {
ātitleā: āRoom 101: Wipe the entrance door to the room and bathroomā,
āstartā: ā2025-03-05T12:05:23.114756+00:00ā,
ātimeZoneā: āEurope/Warsawā,
ādescriptionā: āTask Parent: Room 101\n Area: Hotel\n Task: Wipe the entrance door to the room and bathroomā,
āpriorityā: 5,
āparticipantsā: [
{
"@type": āParticipantā,
ānameā: āhousekeepingā,
āuriā: āprincipals/groups/housekeeping/ā,
āemailā: "-1008@lists.egroupware.org",
ākindā: āgroupā,
ārolesā: {
āattendeeā: true
}
}
],
āstatusā: āconfirmedā,
āprogressā: āneeds-actionā,
ārelatedToā: {
āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā: {
"@type": āRelationā,
ārelationā: āparentā
}
}
}
Response status: 422
Response text: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
ļø Error creating task: {
āerrorā: 422,
āmessageā: āError parsing JsTask attribute ārelatedToā: UID āurn:uuid:f8e4616e-22b3-43f2-8d82-30c69ff10ca5ā NOT found!ā
}
- I have tried all ways to fix the error but still not working.
created
last reply
- 7
replies
- 126
views
- 3
users
- 7
links