Subject: Trying to work on a feature.

From: Rahul Soshte <[email-masked]>
Date: Mon, 26 Mar 2018 23:59:27 +0530

I am new to the codebase of pgAdmin4 and I am trying to work on this
Feature.

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

which appends .sql to files when using the feature "Save" or "Save As"

Which files or folders I should be mostly grasping or looking at ?

---

From: Joao De Almeida Pereira <[email-masked]>
Date: Mon, 26 Mar 2018 19:01:37 +0000

Hello Rahul,

This issues looks like it is located in the file
pgadmin/tools/sqleditor/__init__.py in the function save_file
Maybe around the code:

# generate full path of file
file_path = unquote(file_data['file_name'])
if hasattr(str, 'decode'):
    file_path = unquote(
        file_data['file_name']
    ).encode('utf-8').decode('utf-8')

Sorry if this seams obvious, but we would advise you to:
1 - Extract the function content of save_file to it's own file, something
like pgadmin/tools/sqleditor/utils/save_query_to_file.py
2 - Leave in the__init__.py file a shell function like

@blueprint.route('/save_file/', methods=["PUT", "POST"], endpoint='save_file')
@login_required
def save_file():
    """
    This function retrieves file_name and data from request.
    and then save the data to the file
    """
    if request.data:
        file_data = json.loads(request.data, encoding='utf-8')

    save_query_to_file = SaveQueryToFile()
    save_query_to_file.execute(file_data)

    return make_json_response(
       data={
             'status': True,
            }
    )

3 - Create some tests around the current behavior of the function, similar
to the ones you can find in pgadmin/tools/sqleditor/utils/tests/*
4 - Create some tests to ensure if no extension is provided that it would
add a default one and implement this new behavior

And you should be set to go

Thanks
Victoria & Joao