Thread: [pgAdmin4][Patch][Feature #1998] Appends .sql if extension not givenwhen using 'save' or 'save as' feature

Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)

Attachment
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.

Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)



On Thu, Mar 29, 2018 at 11:45 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.
​Yes, I also think it should append .sql only if the sql extension is selected and user has not provided extension.​
 
​Let say If I want to save the file with .txt extension then I can use All Files. ​


Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)


Hi,
I tried writing tests in the web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils
for the file web/pgadmin/tools/sqleditor/utils/tests/save_query_to_file_utils.py

But I am getting a error,

ERROR: runTest (pgadmin.tools.sqleditor.utils.tests.test_save_query_to_file_utils.TestSaveQueryToFile)
When user has entered the extension .sql to the file while saving
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils.py", line 42, in runTest
    file_path_result = save_query_to_file(self.file_data)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/save_query_to_file_utils.py", line 15, in save_query_to_file
    storage_manager_path = get_storage_directory()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask_login.py", line 788, in decorated_view
    if current_app.login_manager._login_disabled:
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
    return self.__local()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask/globals.py", line 51, in _find_app
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

How do I test the extracted code inside context? How do I resolve this error.
I have attached test_save_query_to_file_utils.py
and save_query_to_file_utils.py

Murtuza, Actually I didnt find any toggable button in the File Dialog Box So I made it general purpose ( I guess I will have to make one then and then if I select SQL all .sql files should be listed, and if I select All files then every type of file is shown in the File Dialog Box,this will be a new feature, wouldnt it ?  )


On Fri, Mar 30, 2018 at 4:10 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:


On Thu, Mar 29, 2018 at 11:45 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.
​Yes, I also think it should append .sql only if the sql extension is selected and user has not provided extension.​
 
​Let say If I want to save the file with .txt extension then I can use All Files. ​


Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)



Attachment
Hi Rahul,

When I said .sql extension, I meant selected sql option in 'Format' combobox (check the screenshot I've attached)

For the error you've mentioned you can create Fake application context.
Ref: ../web/pgadmin/dashboard/tests/test_dashboard_templates.py +274

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Fri, Mar 30, 2018 at 6:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I tried writing tests in the web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils
for the file web/pgadmin/tools/sqleditor/utils/tests/save_query_to_file_utils.py

But I am getting a error,

ERROR: runTest (pgadmin.tools.sqleditor.utils.tests.test_save_query_to_file_utils.TestSaveQueryToFile)
When user has entered the extension .sql to the file while saving
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils.py", line 42, in runTest
    file_path_result = save_query_to_file(self.file_data)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/save_query_to_file_utils.py", line 15, in save_query_to_file
    storage_manager_path = get_storage_directory()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask_login.py", line 788, in decorated_view
    if current_app.login_manager._login_disabled:
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
    return self.__local()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask/globals.py", line 51, in _find_app
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

How do I test the extracted code inside context? How do I resolve this error.
I have attached test_save_query_to_file_utils.py
and save_query_to_file_utils.py

Murtuza, Actually I didnt find any toggable button in the File Dialog Box So I made it general purpose ( I guess I will have to make one then and then if I select SQL all .sql files should be listed, and if I select All files then every type of file is shown in the File Dialog Box,this will be a new feature, wouldnt it ?  )


On Fri, Mar 30, 2018 at 4:10 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:


On Thu, Mar 29, 2018 at 11:45 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.
​Yes, I also think it should append .sql only if the sql extension is selected and user has not provided extension.​
 
​Let say If I want to save the file with .txt extension then I can use All Files. ​


Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)




++ Attaching screenshot

On Fri, Mar 30, 2018 at 7:06 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Rahul,

When I said .sql extension, I meant selected sql option in 'Format' combobox (check the screenshot I've attached)

For the error you've mentioned you can create Fake application context.
Ref: ../web/pgadmin/dashboard/tests/test_dashboard_templates.py +274

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Fri, Mar 30, 2018 at 6:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I tried writing tests in the web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils
for the file web/pgadmin/tools/sqleditor/utils/tests/save_query_to_file_utils.py

But I am getting a error,

ERROR: runTest (pgadmin.tools.sqleditor.utils.tests.test_save_query_to_file_utils.TestSaveQueryToFile)
When user has entered the extension .sql to the file while saving
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils.py", line 42, in runTest
    file_path_result = save_query_to_file(self.file_data)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/save_query_to_file_utils.py", line 15, in save_query_to_file
    storage_manager_path = get_storage_directory()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask_login.py", line 788, in decorated_view
    if current_app.login_manager._login_disabled:
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
    return self.__local()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask/globals.py", line 51, in _find_app
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

How do I test the extracted code inside context? How do I resolve this error.
I have attached test_save_query_to_file_utils.py
and save_query_to_file_utils.py

Murtuza, Actually I didnt find any toggable button in the File Dialog Box So I made it general purpose ( I guess I will have to make one then and then if I select SQL all .sql files should be listed, and if I select All files then every type of file is shown in the File Dialog Box,this will be a new feature, wouldnt it ?  )


On Fri, Mar 30, 2018 at 4:10 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:


On Thu, Mar 29, 2018 at 11:45 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.
​Yes, I also think it should append .sql only if the sql extension is selected and user has not provided extension.​
 
​Let say If I want to save the file with .txt extension then I can use All Files. ​


Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)





Attachment
Hi,
I don't know why that combobox is not seen in my environment.I am using Ubuntu 17.10.I have attached the screenshot.
Is this a bug?



On Fri, Mar 30, 2018 at 7:07 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
++ Attaching screenshot

On Fri, Mar 30, 2018 at 7:06 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Rahul,

When I said .sql extension, I meant selected sql option in 'Format' combobox (check the screenshot I've attached)

For the error you've mentioned you can create Fake application context.
Ref: ../web/pgadmin/dashboard/tests/test_dashboard_templates.py +274

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Fri, Mar 30, 2018 at 6:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I tried writing tests in the web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils
for the file web/pgadmin/tools/sqleditor/utils/tests/save_query_to_file_utils.py

But I am getting a error,

ERROR: runTest (pgadmin.tools.sqleditor.utils.tests.test_save_query_to_file_utils.TestSaveQueryToFile)
When user has entered the extension .sql to the file while saving
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils.py", line 42, in runTest
    file_path_result = save_query_to_file(self.file_data)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/save_query_to_file_utils.py", line 15, in save_query_to_file
    storage_manager_path = get_storage_directory()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask_login.py", line 788, in decorated_view
    if current_app.login_manager._login_disabled:
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
    return self.__local()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask/globals.py", line 51, in _find_app
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

How do I test the extracted code inside context? How do I resolve this error.
I have attached test_save_query_to_file_utils.py
and save_query_to_file_utils.py

Murtuza, Actually I didnt find any toggable button in the File Dialog Box So I made it general purpose ( I guess I will have to make one then and then if I select SQL all .sql files should be listed, and if I select All files then every type of file is shown in the File Dialog Box,this will be a new feature, wouldnt it ?  )


On Fri, Mar 30, 2018 at 4:10 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:


On Thu, Mar 29, 2018 at 11:45 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.
​Yes, I also think it should append .sql only if the sql extension is selected and user has not provided extension.​
 
​Let say If I want to save the file with .txt extension then I can use All Files. ​


Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)






Attachment
​I don't think so, Could you inspect html/css code on 'Save as' dialog within your browser window and see if it's present or not?​


On Fri, Mar 30, 2018 at 8:30 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I don't know why that combobox is not seen in my environment.I am using Ubuntu 17.10.I have attached the screenshot.
Is this a bug?



On Fri, Mar 30, 2018 at 7:07 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
++ Attaching screenshot

On Fri, Mar 30, 2018 at 7:06 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Rahul,

When I said .sql extension, I meant selected sql option in 'Format' combobox (check the screenshot I've attached)

For the error you've mentioned you can create Fake application context.
Ref: ../web/pgadmin/dashboard/tests/test_dashboard_templates.py +274

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Fri, Mar 30, 2018 at 6:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I tried writing tests in the web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils
for the file web/pgadmin/tools/sqleditor/utils/tests/save_query_to_file_utils.py

But I am getting a error,

ERROR: runTest (pgadmin.tools.sqleditor.utils.tests.test_save_query_to_file_utils.TestSaveQueryToFile)
When user has entered the extension .sql to the file while saving
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils.py", line 42, in runTest
    file_path_result = save_query_to_file(self.file_data)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/save_query_to_file_utils.py", line 15, in save_query_to_file
    storage_manager_path = get_storage_directory()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask_login.py", line 788, in decorated_view
    if current_app.login_manager._login_disabled:
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
    return self.__local()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask/globals.py", line 51, in _find_app
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

How do I test the extracted code inside context? How do I resolve this error.
I have attached test_save_query_to_file_utils.py
and save_query_to_file_utils.py

Murtuza, Actually I didnt find any toggable button in the File Dialog Box So I made it general purpose ( I guess I will have to make one then and then if I select SQL all .sql files should be listed, and if I select All files then every type of file is shown in the File Dialog Box,this will be a new feature, wouldnt it ?  )


On Fri, Mar 30, 2018 at 4:10 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:


On Thu, Mar 29, 2018 at 11:45 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.
​Yes, I also think it should append .sql only if the sql extension is selected and user has not provided extension.​
 
​Let say If I want to save the file with .txt extension then I can use All Files. ​


Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)







Yeah the code is present.I have attached the screenshot.
Also  I have noticed that the format combobox appears clearly in my Vivaldi Browser but it is not seen in my Firefox Browser.

On Fri, Mar 30, 2018 at 9:59 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
​I don't think so, Could you inspect html/css code on 'Save as' dialog within your browser window and see if it's present or not?​


On Fri, Mar 30, 2018 at 8:30 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I don't know why that combobox is not seen in my environment.I am using Ubuntu 17.10.I have attached the screenshot.
Is this a bug?



On Fri, Mar 30, 2018 at 7:07 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
++ Attaching screenshot

On Fri, Mar 30, 2018 at 7:06 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Rahul,

When I said .sql extension, I meant selected sql option in 'Format' combobox (check the screenshot I've attached)

For the error you've mentioned you can create Fake application context.
Ref: ../web/pgadmin/dashboard/tests/test_dashboard_templates.py +274

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Fri, Mar 30, 2018 at 6:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I tried writing tests in the web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils
for the file web/pgadmin/tools/sqleditor/utils/tests/save_query_to_file_utils.py

But I am getting a error,

ERROR: runTest (pgadmin.tools.sqleditor.utils.tests.test_save_query_to_file_utils.TestSaveQueryToFile)
When user has entered the extension .sql to the file while saving
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils.py", line 42, in runTest
    file_path_result = save_query_to_file(self.file_data)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/save_query_to_file_utils.py", line 15, in save_query_to_file
    storage_manager_path = get_storage_directory()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask_login.py", line 788, in decorated_view
    if current_app.login_manager._login_disabled:
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
    return self.__local()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask/globals.py", line 51, in _find_app
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

How do I test the extracted code inside context? How do I resolve this error.
I have attached test_save_query_to_file_utils.py
and save_query_to_file_utils.py

Murtuza, Actually I didnt find any toggable button in the File Dialog Box So I made it general purpose ( I guess I will have to make one then and then if I select SQL all .sql files should be listed, and if I select All files then every type of file is shown in the File Dialog Box,this will be a new feature, wouldnt it ?  )


On Fri, Mar 30, 2018 at 4:10 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:


On Thu, Mar 29, 2018 at 11:45 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.
​Yes, I also think it should append .sql only if the sql extension is selected and user has not provided extension.​
 
​Let say If I want to save the file with .txt extension then I can use All Files. ​


Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)








Attachment

Then that's browser specific issue, please create one redmine ticket for the issue.​


On Fri, Mar 30, 2018 at 11:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Yeah the code is present.I have attached the screenshot.
Also  I have noticed that the format combobox appears clearly in my Vivaldi Browser but it is not seen in my Firefox Browser.

On Fri, Mar 30, 2018 at 9:59 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
​I don't think so, Could you inspect html/css code on 'Save as' dialog within your browser window and see if it's present or not?​


On Fri, Mar 30, 2018 at 8:30 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I don't know why that combobox is not seen in my environment.I am using Ubuntu 17.10.I have attached the screenshot.
Is this a bug?



On Fri, Mar 30, 2018 at 7:07 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
++ Attaching screenshot

On Fri, Mar 30, 2018 at 7:06 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Rahul,

When I said .sql extension, I meant selected sql option in 'Format' combobox (check the screenshot I've attached)

For the error you've mentioned you can create Fake application context.
Ref: ../web/pgadmin/dashboard/tests/test_dashboard_templates.py +274

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Fri, Mar 30, 2018 at 6:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I tried writing tests in the web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils
for the file web/pgadmin/tools/sqleditor/utils/tests/save_query_to_file_utils.py

But I am getting a error,

ERROR: runTest (pgadmin.tools.sqleditor.utils.tests.test_save_query_to_file_utils.TestSaveQueryToFile)
When user has entered the extension .sql to the file while saving
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils.py", line 42, in runTest
    file_path_result = save_query_to_file(self.file_data)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/save_query_to_file_utils.py", line 15, in save_query_to_file
    storage_manager_path = get_storage_directory()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask_login.py", line 788, in decorated_view
    if current_app.login_manager._login_disabled:
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
    return self.__local()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask/globals.py", line 51, in _find_app
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

How do I test the extracted code inside context? How do I resolve this error.
I have attached test_save_query_to_file_utils.py
and save_query_to_file_utils.py

Murtuza, Actually I didnt find any toggable button in the File Dialog Box So I made it general purpose ( I guess I will have to make one then and then if I select SQL all .sql files should be listed, and if I select All files then every type of file is shown in the File Dialog Box,this will be a new feature, wouldnt it ?  )


On Fri, Mar 30, 2018 at 4:10 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:


On Thu, Mar 29, 2018 at 11:45 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.
​Yes, I also think it should append .sql only if the sql extension is selected and user has not provided extension.​
 
​Let say If I want to save the file with .txt extension then I can use All Files. ​


Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)









I am trying to access the value in the format combobox for selected file type to put it here..

This snippet happens to be in web/pgadmin/tools/sqleditor/static/js/sqleditor.js



How do I get access to that format combobox value to determine whether it is 'sql' or 'All Files' ?
Also What is e here ?

This passed as to sqleditor's save_file method as seen from the code here.

This snippet happens to be in web/pgadmin/tools/sqleditor/__init__.py






On Sat, Mar 31, 2018 at 12:05 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:

Then that's browser specific issue, please create one redmine ticket for the issue.​


On Fri, Mar 30, 2018 at 11:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Yeah the code is present.I have attached the screenshot.
Also  I have noticed that the format combobox appears clearly in my Vivaldi Browser but it is not seen in my Firefox Browser.

On Fri, Mar 30, 2018 at 9:59 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
​I don't think so, Could you inspect html/css code on 'Save as' dialog within your browser window and see if it's present or not?​


On Fri, Mar 30, 2018 at 8:30 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I don't know why that combobox is not seen in my environment.I am using Ubuntu 17.10.I have attached the screenshot.
Is this a bug?



On Fri, Mar 30, 2018 at 7:07 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
++ Attaching screenshot

On Fri, Mar 30, 2018 at 7:06 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Rahul,

When I said .sql extension, I meant selected sql option in 'Format' combobox (check the screenshot I've attached)

For the error you've mentioned you can create Fake application context.
Ref: ../web/pgadmin/dashboard/tests/test_dashboard_templates.py +274

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Fri, Mar 30, 2018 at 6:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I tried writing tests in the web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils
for the file web/pgadmin/tools/sqleditor/utils/tests/save_query_to_file_utils.py

But I am getting a error,

ERROR: runTest (pgadmin.tools.sqleditor.utils.tests.test_save_query_to_file_utils.TestSaveQueryToFile)
When user has entered the extension .sql to the file while saving
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils.py", line 42, in runTest
    file_path_result = save_query_to_file(self.file_data)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/save_query_to_file_utils.py", line 15, in save_query_to_file
    storage_manager_path = get_storage_directory()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask_login.py", line 788, in decorated_view
    if current_app.login_manager._login_disabled:
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
    return self.__local()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask/globals.py", line 51, in _find_app
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

How do I test the extracted code inside context? How do I resolve this error.
I have attached test_save_query_to_file_utils.py
and save_query_to_file_utils.py

Murtuza, Actually I didnt find any toggable button in the File Dialog Box So I made it general purpose ( I guess I will have to make one then and then if I select SQL all .sql files should be listed, and if I select All files then every type of file is shown in the File Dialog Box,this will be a new feature, wouldnt it ?  )


On Fri, Mar 30, 2018 at 4:10 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:


On Thu, Mar 29, 2018 at 11:45 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.
​Yes, I also think it should append .sql only if the sql extension is selected and user has not provided extension.​
 
​Let say If I want to save the file with .txt extension then I can use All Files. ​


Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)










Attachment
Hi,

We are passing the file name when we trigger an event from File manager whenever user selects any file
../pgadmin/misc/file_manager/static/js/file_manager.js   Line:302
OR creates any new file
../pgadmin/misc/file_manager/static/js/file_manager.js   Line:583, Line:678 

You can use jQuery selector $('.change_file_types select').val() to fetch the selected file type and write your logic accordingly.

On Wed, Apr 11, 2018 at 4:19 AM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
I am trying to access the value in the format combobox for selected file type to put it here..

This snippet happens to be in web/pgadmin/tools/sqleditor/static/js/sqleditor.js



How do I get access to that format combobox value to determine whether it is 'sql' or 'All Files' ?
Also What is e here ?

This passed as to sqleditor's save_file method as seen from the code here.

This snippet happens to be in web/pgadmin/tools/sqleditor/__init__.py






On Sat, Mar 31, 2018 at 12:05 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:

Then that's browser specific issue, please create one redmine ticket for the issue.​


On Fri, Mar 30, 2018 at 11:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Yeah the code is present.I have attached the screenshot.
Also  I have noticed that the format combobox appears clearly in my Vivaldi Browser but it is not seen in my Firefox Browser.

On Fri, Mar 30, 2018 at 9:59 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
​I don't think so, Could you inspect html/css code on 'Save as' dialog within your browser window and see if it's present or not?​


On Fri, Mar 30, 2018 at 8:30 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I don't know why that combobox is not seen in my environment.I am using Ubuntu 17.10.I have attached the screenshot.
Is this a bug?



On Fri, Mar 30, 2018 at 7:07 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
++ Attaching screenshot

On Fri, Mar 30, 2018 at 7:06 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Rahul,

When I said .sql extension, I meant selected sql option in 'Format' combobox (check the screenshot I've attached)

For the error you've mentioned you can create Fake application context.
Ref: ../web/pgadmin/dashboard/tests/test_dashboard_templates.py +274

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Fri, Mar 30, 2018 at 6:36 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
I tried writing tests in the web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils
for the file web/pgadmin/tools/sqleditor/utils/tests/save_query_to_file_utils.py

But I am getting a error,

ERROR: runTest (pgadmin.tools.sqleditor.utils.tests.test_save_query_to_file_utils.TestSaveQueryToFile)
When user has entered the extension .sql to the file while saving
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/tests/test_save_query_to_file_utils.py", line 42, in runTest
    file_path_result = save_query_to_file(self.file_data)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/utils/save_query_to_file_utils.py", line 15, in save_query_to_file
    storage_manager_path = get_storage_directory()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask_login.py", line 788, in decorated_view
    if current_app.login_manager._login_disabled:
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
    return self.__local()
  File "/var/www/flask/pgadmin4/local/lib/python2.7/site-packages/flask/globals.py", line 51, in _find_app
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

How do I test the extracted code inside context? How do I resolve this error.
I have attached test_save_query_to_file_utils.py
and save_query_to_file_utils.py

Murtuza, Actually I didnt find any toggable button in the File Dialog Box So I made it general purpose ( I guess I will have to make one then and then if I select SQL all .sql files should be listed, and if I select All files then every type of file is shown in the File Dialog Box,this will be a new feature, wouldnt it ?  )


On Fri, Mar 30, 2018 at 4:10 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:


On Thu, Mar 29, 2018 at 11:45 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hi Rahul,
I see you extracted some code, that is a pretty good move :D

We run the patch through the testing pipeline and everything is green GJ :D
Also tested the functionality by hand and looks like it is working except for "add the .sql extension when format is set to SQL." if you set it to All Files  the extension is also added. Not sure if this is a big deal or not. Lets see what other people think.
​Yes, I also think it should append .sql only if the sql extension is selected and user has not provided extension.​
 
​Let say If I want to save the file with .txt extension then I can use All Files. ​


Codewise here are some of my comments:
. You added the yarn-error.log file and a migration to the patch doesn't look intentional. Can you please remove them?
. Also in the patch there are 2 file (moc_LogWindow.cpp and ui_LogWindow.h) that look like they do not belong to the patch (Did you rebase your branch before trying to create the patch?

The test file: test_save_query_to_file.py is empty, it is missing some tests there.

As a convention we user lower case names for functions and UpperCase for class

Please, regenerate the patch following my previous comments.

Thanks
Joao

On Thu, Mar 29, 2018 at 12:54 PM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,
When using save or save as feature if .sql is not provided this Patch appends it.
as clearly mentioned in this link.

https://redmine.postgresql.org/issues/1998

I have ran pep8,regression and Jasmine tests too.

I have primarily changed these files
     web/pgadmin/tools/sqleditor/__init__.py
     web/pgadmin/tools/sqleditor/static/js/sqleditor.js
     web/pgadmin/tools/sqleditor/utils/save_query_to_file.py


Regards,
Rahul Soshte (Hunter)











Attachment
Hi,

I have been partially able to solve the problem as you can see in the image. When I select sql in format combobox then only the .sql extension is added.




 But another issue has arisen. Once the file is saved and now When I change the text in the CodeMirror , the save button is enabled and then when I click on it , a error message pops.The problem is whenever I try to save a file for the first time the code works ,but the 2nd time
I try to save it,the code faulters.

Error message is as follows:

Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispach_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask_login.py", line 792, in decorated_view
    return func(*args, **kwargs)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/__init__.py", line 1314, in save_file
    'file_path': file_path
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 61, in make_json_response
    separators=(',', ':')),
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/__init__.py", line 399, in dumps
    **kw).encode(obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 291, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 373, in iterencode
    return _iterencode(o, 0)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 30, in default
    return json.JSONEncoder.default(self, obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 268, in default
    o.__class__.__name__)
TypeError: Object of type Response is not JSON serializable

I pass an array which contains the file_name and file_type in /pgadmin/misc/file_manager/static/js/file_manager.js
 


Also I have done similar changes around line 678.

Also in web/pgadmin/tools/sqleditor/__init__.py I have made the folllowing changes



Also I have attached my web/pgadmin/tools/sqleditor/utils/save_file_query_to_file_utils.py
Attachment
Also attaching my web/pgadmin/tools/sqleditor/static/sqleditor.js
my  _save_file_handler code





On Sat, Apr 14, 2018 at 4:46 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,

I have been partially able to solve the problem as you can see in the image. When I select sql in format combobox then only the .sql extension is added.




 But another issue has arisen. Once the file is saved and now When I change the text in the CodeMirror , the save button is enabled and then when I click on it , a error message pops.The problem is whenever I try to save a file for the first time the code works ,but the 2nd time
I try to save it,the code faulters.

Error message is as follows:

Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispach_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask_login.py", line 792, in decorated_view
    return func(*args, **kwargs)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/__init__.py", line 1314, in save_file
    'file_path': file_path
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 61, in make_json_response
    separators=(',', ':')),
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/__init__.py", line 399, in dumps
    **kw).encode(obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 291, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 373, in iterencode
    return _iterencode(o, 0)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 30, in default
    return json.JSONEncoder.default(self, obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 268, in default
    o.__class__.__name__)
TypeError: Object of type Response is not JSON serializable

I pass an array which contains the file_name and file_type in /pgadmin/misc/file_manager/static/js/file_manager.js
 


Also I have done similar changes around line 678.

Also in web/pgadmin/tools/sqleditor/__init__.py I have made the folllowing changes



Also I have attached my web/pgadmin/tools/sqleditor/utils/save_file_query_to_file_utils.py

Attachment



On Sat, Apr 14, 2018 at 4:49 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Also attaching my web/pgadmin/tools/sqleditor/static/sqleditor.js
my  _save_file_handler code





On Sat, Apr 14, 2018 at 4:46 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,

I have been partially able to solve the problem as you can see in the image. When I select sql in format combobox then only the .sql extension is added.




 But another issue has arisen. Once the file is saved and now When I change the text in the CodeMirror , the save button is enabled and then when I click on it , a error message pops.The problem is whenever I try to save a file for the first time the code works ,but the 2nd time
I try to save it,the code faulters.

Error message is as follows:

Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispach_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask_login.py", line 792, in decorated_view
    return func(*args, **kwargs)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/__init__.py", line 1314, in save_file
    'file_path': file_path
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 61, in make_json_response
    separators=(',', ':')),
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/__init__.py", line 399, in dumps
    **kw).encode(obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 291, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 373, in iterencode
    return _iterencode(o, 0)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 30, in default
    return json.JSONEncoder.default(self, obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 268, in default
    o.__class__.__name__)
TypeError: Object of type Response is not JSON serializable

I pass an array which contains the file_name and file_type in /pgadmin/misc/file_manager/static/js/file_manager.js
 


Also I have done similar changes around line 678.

Also in web/pgadmin/tools/sqleditor/__init__.py I have made the folllowing changes



Also I have attached my web/pgadmin/tools/sqleditor/utils/save_file_query_to_file_utils.py


Attachment
// read data from codemirror and write to file
      _save_file_handler: function(e) {
        var self = this,
          _e = e,
          data = {
            'file_name': decodeURI(e[0]),
            'file_content': self.gridView.query_tool_obj.getValue(),
            'file_type': e[1],
          };
        self.trigger(
          'pgadmin-sqleditor:loading-icon:show',
          gettext('Saving the queries in the file...')
        );

        // Make ajax call to save the data to file
        $.ajax({
          url: url_for('sqleditor.save_file'),
          method: 'POST',
          contentType: 'application/json',
          data: JSON.stringify(data),
          success: function(res) {
            if (res.data.status) {
              alertify.success(res.data.result);
              alertify.success(gettext('File saved successfully.'));
              self.gridView.current_file = res.data.result;
              self.gridView.current_file_type = e[1];
              self.setTitle(self.gridView.current_file.replace(/^.*[\\\/]/g, ''), true);
              // disable save button on file save
              $('#btn-save').prop('disabled', true);

On Sat, Apr 14, 2018 at 4:50 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:



On Sat, Apr 14, 2018 at 4:49 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Also attaching my web/pgadmin/tools/sqleditor/static/sqleditor.js
my  _save_file_handler code





On Sat, Apr 14, 2018 at 4:46 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,

I have been partially able to solve the problem as you can see in the image. When I select sql in format combobox then only the .sql extension is added.




 But another issue has arisen. Once the file is saved and now When I change the text in the CodeMirror , the save button is enabled and then when I click on it , a error message pops.The problem is whenever I try to save a file for the first time the code works ,but the 2nd time
I try to save it,the code faulters.

Error message is as follows:

Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispach_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask_login.py", line 792, in decorated_view
    return func(*args, **kwargs)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/__init__.py", line 1314, in save_file
    'file_path': file_path
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 61, in make_json_response
    separators=(',', ':')),
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/__init__.py", line 399, in dumps
    **kw).encode(obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 291, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 373, in iterencode
    return _iterencode(o, 0)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 30, in default
    return json.JSONEncoder.default(self, obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 268, in default
    o.__class__.__name__)
TypeError: Object of type Response is not JSON serializable

I pass an array which contains the file_name and file_type in /pgadmin/misc/file_manager/static/js/file_manager.js
 


Also I have done similar changes around line 678.

Also in web/pgadmin/tools/sqleditor/__init__.py I have made the folllowing changes



Also I have attached my web/pgadmin/tools/sqleditor/utils/save_file_query_to_file_utils.py



Attachment
Hi Rahul,

Instead of partial code, please send WIP patch, so I can look into this and help you.

Thanks,
Khushboo

On Sat, Apr 14, 2018 at 4:51 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
// read data from codemirror and write to file
      _save_file_handler: function(e) {
        var self = this,
          _e = e,
          data = {
            'file_name': decodeURI(e[0]),
            'file_content': self.gridView.query_tool_obj.getValue(),
            'file_type': e[1],
          };
        self.trigger(
          'pgadmin-sqleditor:loading-icon:show',
          gettext('Saving the queries in the file...')
        );

        // Make ajax call to save the data to file
        $.ajax({
          url: url_for('sqleditor.save_file'),
          method: 'POST',
          contentType: 'application/json',
          data: JSON.stringify(data),
          success: function(res) {
            if (res.data.status) {
              alertify.success(res.data.result);
              alertify.success(gettext('File saved successfully.'));
              self.gridView.current_file = res.data.result;
              self.gridView.current_file_type = e[1];
              self.setTitle(self.gridView.current_file.replace(/^.*[\\\/]/g, ''), true);
              // disable save button on file save
              $('#btn-save').prop('disabled', true);

On Sat, Apr 14, 2018 at 4:50 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:



On Sat, Apr 14, 2018 at 4:49 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Also attaching my web/pgadmin/tools/sqleditor/static/sqleditor.js
my  _save_file_handler code





On Sat, Apr 14, 2018 at 4:46 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,

I have been partially able to solve the problem as you can see in the image. When I select sql in format combobox then only the .sql extension is added.




 But another issue has arisen. Once the file is saved and now When I change the text in the CodeMirror , the save button is enabled and then when I click on it , a error message pops.The problem is whenever I try to save a file for the first time the code works ,but the 2nd time
I try to save it,the code faulters.

Error message is as follows:

Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispach_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask_login.py", line 792, in decorated_view
    return func(*args, **kwargs)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/__init__.py", line 1314, in save_file
    'file_path': file_path
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 61, in make_json_response
    separators=(',', ':')),
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/__init__.py", line 399, in dumps
    **kw).encode(obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 291, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 373, in iterencode
    return _iterencode(o, 0)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 30, in default
    return json.JSONEncoder.default(self, obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 268, in default
    o.__class__.__name__)
TypeError: Object of type Response is not JSON serializable

I pass an array which contains the file_name and file_type in /pgadmin/misc/file_manager/static/js/file_manager.js
 


Also I have done similar changes around line 678.

Also in web/pgadmin/tools/sqleditor/__init__.py I have made the folllowing changes



Also I have attached my web/pgadmin/tools/sqleditor/utils/save_file_query_to_file_utils.py




Attachment
Hi,

I have attached the WIP Patch.

Regards,
Rahul Soshte

On Mon, Apr 16, 2018 at 4:13 PM, Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
Hi Rahul,

Instead of partial code, please send WIP patch, so I can look into this and help you.

Thanks,
Khushboo


On Sat, Apr 14, 2018 at 4:51 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
// read data from codemirror and write to file
      _save_file_handler: function(e) {
        var self = this,
          _e = e,
          data = {
            'file_name': decodeURI(e[0]),
            'file_content': self.gridView.query_tool_obj.getValue(),
            'file_type': e[1],
          };
        self.trigger(
          'pgadmin-sqleditor:loading-icon:show',
          gettext('Saving the queries in the file...')
        );

        // Make ajax call to save the data to file
        $.ajax({
          url: url_for('sqleditor.save_file'),
          method: 'POST',
          contentType: 'application/json',
          data: JSON.stringify(data),
          success: function(res) {
            if (res.data.status) {
              alertify.success(res.data.result);
              alertify.success(gettext('File saved successfully.'));
              self.gridView.current_file = res.data.result;
              self.gridView.current_file_type = e[1];
              self.setTitle(self.gridView.current_file.replace(/^.*[\\\/]/g, ''), true);
              // disable save button on file save
              $('#btn-save').prop('disabled', true);

On Sat, Apr 14, 2018 at 4:50 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:



On Sat, Apr 14, 2018 at 4:49 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Also attaching my web/pgadmin/tools/sqleditor/static/sqleditor.js
my  _save_file_handler code





On Sat, Apr 14, 2018 at 4:46 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,

I have been partially able to solve the problem as you can see in the image. When I select sql in format combobox then only the .sql extension is added.




 But another issue has arisen. Once the file is saved and now When I change the text in the CodeMirror , the save button is enabled and then when I click on it , a error message pops.The problem is whenever I try to save a file for the first time the code works ,but the 2nd time
I try to save it,the code faulters.

Error message is as follows:

Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispach_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask_login.py", line 792, in decorated_view
    return func(*args, **kwargs)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/__init__.py", line 1314, in save_file
    'file_path': file_path
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 61, in make_json_response
    separators=(',', ':')),
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/__init__.py", line 399, in dumps
    **kw).encode(obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 291, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 373, in iterencode
    return _iterencode(o, 0)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 30, in default
    return json.JSONEncoder.default(self, obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 268, in default
    o.__class__.__name__)
TypeError: Object of type Response is not JSON serializable

I pass an array which contains the file_name and file_type in /pgadmin/misc/file_manager/static/js/file_manager.js
 


Also I have done similar changes around line 678.

Also in web/pgadmin/tools/sqleditor/__init__.py I have made the folllowing changes



Also I have attached my web/pgadmin/tools/sqleditor/utils/save_file_query_to_file_utils.py





Attachment
Hello Rahul,
I didn't try to execute the code that you sent on the WIP.

Nevertheless you are returning internal_server_error in some cases from the function save_query_to_file. You need to do one of 2 things

1) Let the exception flow to the controller and catch it there
2) In the controller check if the return is a response

Personally I would go with 1. Eventually I would catch the exception in the function and throw a SaveFileException (new class). Going with 1 you can test all the functionality without having to standup a Flask application and doing an HTTP request.

Thanks
Joao

On Mon, Apr 16, 2018 at 8:20 AM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,

I have attached the WIP Patch.

Regards,
Rahul Soshte

On Mon, Apr 16, 2018 at 4:13 PM, Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
Hi Rahul,

Instead of partial code, please send WIP patch, so I can look into this and help you.

Thanks,
Khushboo


On Sat, Apr 14, 2018 at 4:51 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
// read data from codemirror and write to file
      _save_file_handler: function(e) {
        var self = this,
          _e = e,
          data = {
            'file_name': decodeURI(e[0]),
            'file_content': self.gridView.query_tool_obj.getValue(),
            'file_type': e[1],
          };
        self.trigger(
          'pgadmin-sqleditor:loading-icon:show',
          gettext('Saving the queries in the file...')
        );

        // Make ajax call to save the data to file
        $.ajax({
          url: url_for('sqleditor.save_file'),
          method: 'POST',
          contentType: 'application/json',
          data: JSON.stringify(data),
          success: function(res) {
            if (res.data.status) {
              alertify.success(res.data.result);
              alertify.success(gettext('File saved successfully.'));
              self.gridView.current_file = res.data.result;
              self.gridView.current_file_type = e[1];
              self.setTitle(self.gridView.current_file.replace(/^.*[\\\/]/g, ''), true);
              // disable save button on file save
              $('#btn-save').prop('disabled', true);

On Sat, Apr 14, 2018 at 4:50 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:



On Sat, Apr 14, 2018 at 4:49 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Also attaching my web/pgadmin/tools/sqleditor/static/sqleditor.js
my  _save_file_handler code





On Sat, Apr 14, 2018 at 4:46 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,

I have been partially able to solve the problem as you can see in the image. When I select sql in format combobox then only the .sql extension is added.




 But another issue has arisen. Once the file is saved and now When I change the text in the CodeMirror , the save button is enabled and then when I click on it , a error message pops.The problem is whenever I try to save a file for the first time the code works ,but the 2nd time
I try to save it,the code faulters.

Error message is as follows:

Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispach_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask_login.py", line 792, in decorated_view
    return func(*args, **kwargs)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/__init__.py", line 1314, in save_file
    'file_path': file_path
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 61, in make_json_response
    separators=(',', ':')),
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/__init__.py", line 399, in dumps
    **kw).encode(obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 291, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 373, in iterencode
    return _iterencode(o, 0)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 30, in default
    return json.JSONEncoder.default(self, obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 268, in default
    o.__class__.__name__)
TypeError: Object of type Response is not JSON serializable

I pass an array which contains the file_name and file_type in /pgadmin/misc/file_manager/static/js/file_manager.js
 


Also I have done similar changes around line 678.

Also in web/pgadmin/tools/sqleditor/__init__.py I have made the folllowing changes



Also I have attached my web/pgadmin/tools/sqleditor/utils/save_file_query_to_file_utils.py





Attachment
Hi Rahul,

I have tried to execute your code on PY2, no error but the .sql extension has not appended.
On PY3, the code is not working, giving an error.

One another thing I have noticed that you are using the make_json_response function in a wrong way, please check the definition to get the better idea.

Thanks,
Khushboo

On Mon, Apr 16, 2018 at 7:33 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Rahul,
I didn't try to execute the code that you sent on the WIP.

Nevertheless you are returning internal_server_error in some cases from the function save_query_to_file. You need to do one of 2 things

1) Let the exception flow to the controller and catch it there
2) In the controller check if the return is a response

Personally I would go with 1. Eventually I would catch the exception in the function and throw a SaveFileException (new class). Going with 1 you can test all the functionality without having to standup a Flask application and doing an HTTP request.

Thanks
Joao

On Mon, Apr 16, 2018 at 8:20 AM Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,

I have attached the WIP Patch.

Regards,
Rahul Soshte

On Mon, Apr 16, 2018 at 4:13 PM, Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
Hi Rahul,

Instead of partial code, please send WIP patch, so I can look into this and help you.

Thanks,
Khushboo


On Sat, Apr 14, 2018 at 4:51 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
// read data from codemirror and write to file
      _save_file_handler: function(e) {
        var self = this,
          _e = e,
          data = {
            'file_name': decodeURI(e[0]),
            'file_content': self.gridView.query_tool_obj.getValue(),
            'file_type': e[1],
          };
        self.trigger(
          'pgadmin-sqleditor:loading-icon:show',
          gettext('Saving the queries in the file...')
        );

        // Make ajax call to save the data to file
        $.ajax({
          url: url_for('sqleditor.save_file'),
          method: 'POST',
          contentType: 'application/json',
          data: JSON.stringify(data),
          success: function(res) {
            if (res.data.status) {
              alertify.success(res.data.result);
              alertify.success(gettext('File saved successfully.'));
              self.gridView.current_file = res.data.result;
              self.gridView.current_file_type = e[1];
              self.setTitle(self.gridView.current_file.replace(/^.*[\\\/]/g, ''), true);
              // disable save button on file save
              $('#btn-save').prop('disabled', true);

On Sat, Apr 14, 2018 at 4:50 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:



On Sat, Apr 14, 2018 at 4:49 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Also attaching my web/pgadmin/tools/sqleditor/static/sqleditor.js
my  _save_file_handler code





On Sat, Apr 14, 2018 at 4:46 PM, Rahul Soshte <rahulsoshte360@gmail.com> wrote:
Hi,

I have been partially able to solve the problem as you can see in the image. When I select sql in format combobox then only the .sql extension is added.




 But another issue has arisen. Once the file is saved and now When I change the text in the CodeMirror , the save button is enabled and then when I click on it , a error message pops.The problem is whenever I try to save a file for the first time the code works ,but the 2nd time
I try to save it,the code faulters.

Error message is as follows:

Traceback (most recent call last):
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispach_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/flask_login.py", line 792, in decorated_view
    return func(*args, **kwargs)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/tools/sqleditor/__init__.py", line 1314, in save_file
    'file_path': file_path
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 61, in make_json_response
    separators=(',', ':')),
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/__init__.py", line 399, in dumps
    **kw).encode(obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 291, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 373, in iterencode
    return _iterencode(o, 0)
  File "/var/www/flask/pgadmin4/pgadmin4/web/pgadmin/utils/ajax.py", line 30, in default
    return json.JSONEncoder.default(self, obj)
  File "/var/www/flask/pgadmin4/lib/python2.7/site-packages/simplejson/encoder.py", line 268, in default
    o.__class__.__name__)
TypeError: Object of type Response is not JSON serializable

I pass an array which contains the file_name and file_type in /pgadmin/misc/file_manager/static/js/file_manager.js
 


Also I have done similar changes around line 678.

Also in web/pgadmin/tools/sqleditor/__init__.py I have made the folllowing changes



Also I have attached my web/pgadmin/tools/sqleditor/utils/save_file_query_to_file_utils.py






Attachment