Commit acd4b90d authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor code to fix issue when the user changes the event type in the edition...

refactor code to fix issue when the user changes the event type in the edition dialog of UNG Calendar

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@45304 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 39016ab1
...@@ -60,6 +60,8 @@ from DateTime import DateTime\n ...@@ -60,6 +60,8 @@ from DateTime import DateTime\n
import random\n import random\n
\n \n
def convertToERP5DateTime(date):\n def convertToERP5DateTime(date):\n
if not date:\n
return None\n
date, hour = date.split()\n date, hour = date.split()\n
month, day, year = date.split("/")\n month, day, year = date.split("/")\n
return DateTime("%s/%s/%s %s" % (month, day, year, hour))\n return DateTime("%s/%s/%s %s" % (month, day, year, hour))\n
...@@ -116,7 +118,8 @@ if request_type == "list":\n ...@@ -116,7 +118,8 @@ if request_type == "list":\n
\n \n
elif request_type == "remove":\n elif request_type == "remove":\n
title = form.get("title")\n title = form.get("title")\n
catalog_object = portal.portal_catalog.getResultValue(portal_type=portal_type_list, title=title)\n catalog_object = portal.portal_catalog.getResultValue(portal_type=portal_type_list,\n
title=title)\n
event = context.restrictedTraverse(catalog_object.getPath())\n event = context.restrictedTraverse(catalog_object.getPath())\n
portal.event_module.deleteContent(event.getId())\n portal.event_module.deleteContent(event.getId())\n
return dumps({"IsSuccess": True})\n return dumps({"IsSuccess": True})\n
...@@ -132,12 +135,25 @@ elif request_type == "update":\n ...@@ -132,12 +135,25 @@ elif request_type == "update":\n
catalog_object = portal.portal_catalog.getResultValue(portal_type=portal_type_list,\n catalog_object = portal.portal_catalog.getResultValue(portal_type=portal_type_list,\n
id=event_id)\n id=event_id)\n
event = context.restrictedTraverse(catalog_object.getPath())\n event = context.restrictedTraverse(catalog_object.getPath())\n
event_portal_type = form.get(\'event_portal_type\')\n
if event.getPortalType() != event_portal_type and event_portal_type in portal_type_list:\n
new_event = portal.event_module.newContent(portal_type=event_portal_type)\n
new_event.edit(start_date=start_date,\n
end_date=end_date,\n
title=title,\n
description=text_content)\n
portal.event_module.deleteContent(event.getId())\n
else:\n
kw = {}\n
if title and event.getTitle() != title:\n if title and event.getTitle() != title:\n
event.setTitle(title)\n kw["title"] = title\n
if text_content and event.getDescription() != text_content:\n if text_content and event.getDescription() != text_content:\n
event.setDescription(text_content)\n kw["description"] = text_content\n
event.setStartDate(start_date)\n if start_date is not None:\n
event.setStopDate(end_date)\n kw["start_date"] = start_date\n
if end_date is not None:\n
kw["stop_date"] = end_date\n
event.edit(**kw)\n
return dumps({"IsSuccess": True})\n return dumps({"IsSuccess": True})\n
\n \n
elif request_type == "add":\n elif request_type == "add":\n
......
...@@ -67,7 +67,7 @@ function Edit(data){\n ...@@ -67,7 +67,7 @@ function Edit(data){\n
title: "Update Event",\n title: "Update Event",\n
buttons: {\n buttons: {\n
"Save": function(){\n "Save": function(){\n
data = $("form#create_new_event").serializeArray();\n var data = $("form#create_new_event").serializeArray();\n
var dataHash = {};\n var dataHash = {};\n
for (var i=0; i<data.length; i++)\n for (var i=0; i<data.length; i++)\n
dataHash[data[i].name] = data[i].value;\n dataHash[data[i].name] = data[i].value;\n
...@@ -84,6 +84,7 @@ function Edit(data){\n ...@@ -84,6 +84,7 @@ function Edit(data){\n
dataHash.stop_date_minute;\n dataHash.stop_date_minute;\n
\n \n
var paramList = [{name : \'CalendarEndTime\', \'value\': stop_date},\n var paramList = [{name : \'CalendarEndTime\', \'value\': stop_date},\n
{name : \'event_portal_type\', \'value\': dataHash.portal_type},\n
{name : \'CalendarStartTime\', \'value\': start_date},\n {name : \'CalendarStartTime\', \'value\': start_date},\n
{name : \'title\', \'value\': dataHash.title},\n {name : \'title\', \'value\': dataHash.title},\n
{name : \'request_type\', \'value\': \'update\'},\n {name : \'request_type\', \'value\': \'update\'},\n
......
...@@ -41,12 +41,12 @@ class TestUNG(ERP5TypeTestCase): ...@@ -41,12 +41,12 @@ class TestUNG(ERP5TypeTestCase):
return "UNG Tests" return "UNG Tests"
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
return ('erp5_base', return ('erp5_ingestion_mysql_innodb_catalog',
'erp5_base',
'erp5_jquery',
'erp5_web', 'erp5_web',
'erp5_ingestion_mysql_innodb_catalog',
'erp5_core_proxy_field_legacy', 'erp5_core_proxy_field_legacy',
'erp5_ingestion', 'erp5_ingestion',
'erp5_jquery',
'erp5_jquery_ui', 'erp5_jquery_ui',
'erp5_dms', 'erp5_dms',
'erp5_crm', 'erp5_crm',
...@@ -268,14 +268,56 @@ class TestUNG(ERP5TypeTestCase): ...@@ -268,14 +268,56 @@ class TestUNG(ERP5TypeTestCase):
self.portal.Base_updateCalendarEventList("update") self.portal.Base_updateCalendarEventList("update")
self.stepTic() self.stepTic()
self.assertEquals(web_message.getTitle(), "Buy Coffee") self.assertEquals(web_message.getTitle(), "Buy Coffee")
self.portal.REQUEST.form.clear() form_dict["event_portal_type"] = "Note"
form_dict = dict(title=web_message.getTitle(),
id=web_message.getId())
self.portal.REQUEST.form.update(form_dict) self.portal.REQUEST.form.update(form_dict)
self.portal.Base_updateCalendarEventList("remove") self.portal.Base_updateCalendarEventList("update")
self.stepTic() self.stepTic()
web_message = self.portal.portal_catalog.getResultValue(portal_type="Web Message") web_message = self.portal.portal_catalog.getResultValue(portal_type="Web Message")
self.assertEquals(web_message, None) self.assertEquals(web_message, None)
note = self.portal.portal_catalog.getResultValue(portal_type="Note")
self.assertEquals(note.getTitle(), "Buy Coffee")
self.portal.REQUEST.form.clear()
form_dict = dict(title=note.getTitle(),
id=note.getId())
self.portal.REQUEST.form.update(form_dict)
self.portal.Base_updateCalendarEventList("remove")
self.stepTic()
note = self.portal.portal_catalog.getResultValue(portal_type="Note",
title="Buy Coffee")
self.assertEquals(note, None)
self.portal.REQUEST.form.clear()
start_date = DateTime()
end_date = DateTime() + 1
form_dict = dict(CalendarStartTime=start_date.strftime("%m/%d/%Y %H:%M"),
CalendarEndTime=end_date.strftime("%m/%d/%Y %H:%M"),
CalendarTitle="Another Sample",
portal_type="Letter")
self.portal.REQUEST.form.update(form_dict)
self.portal.Base_updateCalendarEventList("add")
self.stepTic()
letter = self.portal.portal_catalog.getResultValue(portal_type="Letter",
title="Another Sample")
self.assertEquals(letter.getPortalType(), "Letter")
self.assertEquals(letter.getTitle(), "Another Sample")
self.assertEquals(letter.getStartDate().hour(), start_date.hour())
self.assertEquals(letter.getStartDate().day(), start_date.day())
self.assertEquals(letter.getStopDate().hour(), end_date.hour())
self.assertEquals(letter.getStopDate().day(), end_date.day())
self.portal.REQUEST.form.clear()
form_dict = dict(title="Change only the Title of Sample",
event_id=letter.getId())
self.portal.REQUEST.form.update(form_dict)
self.portal.Base_updateCalendarEventList("update")
self.stepTic()
letter = self.portal.portal_catalog.getResultValue(portal_type="Letter",
title="Another Sample")
self.assertEquals(letter, None)
letter = self.portal.portal_catalog.getResultValue(portal_type="Letter",
title="Change only the Title of Sample")
self.assertEquals(letter.getStartDate().hour(), start_date.hour())
self.assertEquals(letter.getStartDate().day(), start_date.day())
self.assertEquals(letter.getStopDate().hour(), end_date.hour())
self.assertEquals(letter.getStopDate().day(), end_date.day())
def testERPSite_createUNGUser(self): def testERPSite_createUNGUser(self):
"""Test if script creates an user correctly""" """Test if script creates an user correctly"""
......
349 350
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment