These are chat archives for fossasia/open-event-server

2nd
Jun 2017
Afroz Ahamad
@enigmaeth
Jun 02 2017 06:30
@shubham-padia @SaptakS Please review #3704 .
Aseem Shrey
@LuD1161
Jun 02 2017 16:11

I am implementing before_create_object to change the data but I am doing something wrong.
It is being implemented in class EventList(ResourceList)

    def before_create_object(self, data, view_kwargs):
        starts_at = data['starts_at']
        ends_at = data['ends_at']
        zone = data['timezone']
        local = timezone(zone)
        start_time = local.localize(starts_at).strftime('%Y-%m-%d %H:%M:%S%z')
        end_time = local.localize(ends_at).strftime('%Y-%m-%d %H:%M:%S%z')
        data['starts_at'] = start_time
        data['ends_at'] = end_time

however as it should be modifying data before passing into the database.
The data['starts_at'] and data['ends_at'] are being modified but the data is not being saved in the database.
can anyone help me with this ?

@SaptakS @shubham-padia @enigmaeth ?
Shubham Padia
@shubham-padia
Jun 02 2017 16:15
Have you specified the before_create_object method when declaring the datalayer, I missed that a few times
Aseem Shrey
@LuD1161
Jun 02 2017 16:18
This is the full code :
class EventList(ResourceList):
    def before_create_object(self, data, view_kwargs):
        starts_at = data['starts_at']
        ends_at = data['ends_at']
        zone = data['timezone']
        local = timezone(zone)
        start_time = local.localize(starts_at).strftime('%Y-%m-%d %H:%M:%S%z')
        end_time = local.localize(ends_at).strftime('%Y-%m-%d %H:%M:%S%z')
        data['starts_at'] = start_time
        data['ends_at'] = end_time
        print ("starts_at :"+str(starts_at)+
               "ends_at :"+str(ends_at)+
               "start_time :" + str(data['starts_at'])+
               "end_time :" + str(data['ends_at']))

    decorators = (jwt_required,)
    schema = EventSchema
    data_layer = {'session': db.session,
                  'model': Event,
                  'methods': {'before_create_object': before_create_object}
                  }
yes I have specified it @shubham-padia
Shubham Padia
@shubham-padia
Jun 02 2017 16:20
Not sure then
Aseem Shrey
@LuD1161
Jun 02 2017 16:20
I have tried printing for debugging and it's working fine , like this :
starts_at :2017-07-06 11:22:33ends_at :2017-07-16 11:22:33start_time :2017-07-06 11:22:33+0530end_time :2017-07-16 11:22:33+0530
so it is working fine , isn't it ?
Piyush Agrawal
@poush
Jun 02 2017 16:24
Hey try one thing! Try to alter the create_object of the alchemy.py file of jsonapi library and try to add checks on different steps
and see if you get something
Shubham Padia
@shubham-padia
Jun 02 2017 16:28
And use a good debugger instead, Pycharm's default one works like a charm
Aseem Shrey
@LuD1161
Jun 02 2017 16:28
ok
Afroz Ahamad
@enigmaeth
Jun 02 2017 17:41
@poush I have made the changes for #3704 . Can you please check it now?
Piyush Agrawal
@poush
Jun 02 2017 18:04
@enigmaeth added comment.