Repository: fossasia/open-event-server

Issue:
Editing CFS in Event Wizard doesn't save information
If we edit the information for CFS in event wizard once it has been saved, it is not updating.



Discussion:

Resolving patch:
diff --git a/open_event/helpers/data.py b/open_event/helpers/data.py
--- a/open_event/helpers/data.py
+++ b/open_event/helpers/data.py
@@ -849,7 +849,7 @@ def create_event(form, img_files):
             track_color = form.getlist('tracks[color]')
 
             room_name = form.getlist('rooms[name]')
-            room_color = form.getlist('rooms[color]')
+            room_floor = form.getlist('rooms[floor]')
 
             sponsor_name = form.getlist('sponsors[name]')
             sponsor_url = form.getlist('sponsors[url]')
@@ -899,7 +899,7 @@ def create_event(form, img_files):
 
             for index, name in enumerate(room_name):
                 if not string_empty(name):
-                    room = Microlocation(name=name, event_id=event.id)
+                    room = Microlocation(name=name, floor=room_floor[index], event_id=event.id)
                     db.session.add(room)
 
             for index, name in enumerate(sponsor_name):
@@ -1031,16 +1031,20 @@ def edit_event(request, event_id, event, session_types, tracks, social_links, mi
             event.state = state
 
         session_type_names = form.getlist('session_type[name]')
+        session_type_id = form.getlist('session_type[id]')
         session_type_length = form.getlist('session_type[length]')
 
         social_link_name = form.getlist('social[name]')
         social_link_link = form.getlist('social[link]')
+        social_link_id = form.getlist('social[id]')
 
         track_name = form.getlist('tracks[name]')
         track_color = form.getlist('tracks[color]')
+        track_id = form.getlist('tracks[id]')
 
         room_name = form.getlist('rooms[name]')
-        room_color = form.getlist('rooms[color]')
+        room_floor = form.getlist('rooms[floor]')
+        room_id = form.getlist('rooms[id]')
 
         sponsor_name = form.getlist('sponsors[name]')
         sponsor_logo_url = []
@@ -1053,33 +1057,66 @@ def edit_event(request, event_id, event, session_types, tracks, social_links, mi
         custom_forms_value = form.getlist('custom_form[value]')
 
         # save the edited info to database
+
         for index, name in enumerate(session_type_names):
             if not string_empty(name):
-                session_type, c = get_or_create(SessionType,
-                                                name=name,
-                                                length=session_type_length[index],
-                                                event_id=event.id)
+                print session_type_id[index]
+                if session_type_id[index] != '':
+                    session_type, c = get_or_create(SessionType,
+                                                    id=session_type_id[index],
+                                                    event_id=event.id)
+                    session_type.name = name
+                    session_type.length = session_type_length[index]
+                else:
+                    session_type, c = get_or_create(SessionType,
+                                                    name=name,
+                                                    length=session_type_length[index],
+                                                    event_id=event.id)
                 db.session.add(session_type)
 
         for index, name in enumerate(social_link_name):
             if not string_empty(social_link_link[index]):
-                social_link, c = get_or_create(SocialLink,
-                                               name=name,
-                                               link=social_link_link[index],
-                                               event_id=event.id)
+                if social_link_id[index] != '':
+                    social_link, c = get_or_create(SocialLink,
+                                                   id=social_link_id[index],
+                                                   event_id=event.id)
+                    social_link.name = name
+                    social_link.link = social_link_link[index]
+                else:
+                    social_link, c = get_or_create(SocialLink,
+                                                   name=name,
+                                                   link=social_link_link[index],
+                                                   event_id=event.id)
                 db.session.add(social_link)
 
         for index, name in enumerate(track_name):
             if not string_empty(name):
-                track, c = get_or_create(Track,
-                                         name=name,
-                                         color=track_color[index].upper(),
-                                         event_id=event.id)
+                if track_id[index] != '':
+                    track, c = get_or_create(Track,
+                                             id=track_id[index],
+                                             event_id=event.id)
+                    track.name = name
+                    track.color = track_color[index].upper()
+                else:
+                    track, c = get_or_create(Track,
+                                             name=name,
+                                             color=track_color[index].upper(),
+                                             event_id=event.id)
                 db.session.add(track)
 
         for index, name in enumerate(room_name):
             if not string_empty(name):
-                room, c = get_or_create(Microlocation, name=name, event_id=event.id)
+                if room_id[index] != '':
+                    room, c = get_or_create(Microlocation,
+                                            id=room_id[index],
+                                            event_id=event.id)
+                    room.name = name
+                    room.floor = room_floor[index]
+                else:
+                    room, c = get_or_create(Microlocation,
+                                            name=name,
+                                            floor=room_floor[index],
+                                            event_id=event.id)
                 db.session.add(room)
 
         for sponsor in sponsors:
@@ -1113,7 +1150,6 @@ def edit_event(request, event_id, event, session_types, tracks, social_links, mi
         session_form = ""
         speaker_form = ""
         for index, name in enumerate(custom_forms_name):
-            print name
             if name == "session_form":
                 session_form = custom_forms_value[index]
             elif name == "speaker_form":
@@ -1122,6 +1158,9 @@ def edit_event(request, event_id, event, session_types, tracks, social_links, mi
         update_or_create(
             CustomForms, event_id=event.id,
             session_form=session_form, speaker_form=speaker_form)
+
+        delete_from_db(call_for_papers, "CallForPaper Deleted")
+
         if form.get('call_for_speakers_state', u'off') == u'on':
             if call_for_papers:
                 call_for_papers.announcement = form['announcement']
diff --git a/open_event/models/call_for_papers.py b/open_event/models/call_for_papers.py
--- a/open_event/models/call_for_papers.py
+++ b/open_event/models/call_for_papers.py
@@ -27,7 +27,7 @@ def __str__(self):
         return unicode(self).encode('utf-8')
 
     def __unicode__(self):
-        return self.name
+        return self.announcement
 
     @property
     def serialize(self):


Test patch: