Skip to content

Commit

Permalink
support of post apis for all apps
Browse files Browse the repository at this point in the history
  • Loading branch information
impratikjaiswal committed May 5, 2024
1 parent 2207b23 commit e2153f2
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 15 deletions.
43 changes: 28 additions & 15 deletions amenity_pj/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask_sitemapper import Sitemapper
from werkzeug.exceptions import abort

from amenity_pj.apps import app_qr_play, app_tlv_play, app_asn1_play, app_cert_play
from amenity_pj.apps import app_qr_play, app_tlv_play, app_asn1_play, app_cert_play, app_excel_play
from amenity_pj.helper.constants import Const
from amenity_pj.helper.util import Util

Expand Down Expand Up @@ -97,15 +97,20 @@ def index():
return render_template(Const.TEMPLATE_AMENITY_PJ, **default_data)


@app.route(Const.URL_ASN1_PLAY_ASN1_OBJECTS)
def asn1_play_asn1_objects():
return app_asn1_play.handle_asn1_objects()


@sitemapper.include(lastmod=Const.DEPLOYMENT_DATE)
@app.route(Const.URL_ASN1_PLAY, methods=('GET', 'POST'))
def asn1_play():
return app_asn1_play.handle_requests()
return app_asn1_play.handle_requests(api=False)


@app.route(Const.URL_ASN1_PLAY_ASN1_OBJECTS)
def asn1_play_asn1_objects():
return app_asn1_play.handle_asn1_objects()
@app.route(Const.URL_API_ASN1_PLAY, methods=('GET', 'POST'))
def asn1_play_api():
return app_asn1_play.handle_requests(api=True)


@sitemapper.include(lastmod=Const.DEPLOYMENT_DATE_CERT_PLAY)
Expand All @@ -122,26 +127,34 @@ def cert_play_api():
@sitemapper.include(lastmod=Const.DEPLOYMENT_DATE)
@app.route(Const.URL_TLV_PLAY, methods=('GET', 'POST'))
def tlv_play():
return app_tlv_play.handle_requests()
return app_tlv_play.handle_requests(api=False)


@app.route(Const.URL_API_TLV_PLAY, methods=('GET', 'POST'))
def tlv_play_api():
return app_tlv_play.handle_requests(api=True)


@sitemapper.include(lastmod=Const.DEPLOYMENT_DATE)
@app.route(Const.URL_QR_PLAY, methods=('GET', 'POST'))
def qr_play():
return app_qr_play.handle_requests()
return app_qr_play.handle_requests(api=False)


@app.route(Const.URL_API_QR_PLAY, methods=('GET', 'POST'))
def qr_play_api():
return app_qr_play.handle_requests(api=True)


@sitemapper.include(lastmod=Const.DEPLOYMENT_DATE)
@app.route(Const.URL_EXCEL_PLAY, methods=('GET', 'POST'))
def excel_play():
default_data = {
'app_title': Const.TITLE_EXCEL_PLAY,
'app_description': Const.DESCRIPTION_EXCEL_PLAY,
'app_version': Const.VERSION_EXCEL_PLAY,
'app_github_url': Util.get_github_url(github_repo=Const.GITHUB_REPO_EXCEL_PLAY, github_pages=False),
'app_github_pages_url': Util.get_github_url(github_repo=Const.GITHUB_REPO_EXCEL_PLAY, github_pages=True),
}
return render_template(Const.TEMPLATE_EXCEL_PLAY, **default_data)
return app_excel_play.handle_requests(api=False)


@app.route(Const.URL_API_EXCEL_PLAY, methods=('GET', 'POST'))
def excel_play_api():
return app_excel_play.handle_requests(api=True)


@sitemapper.include(lastmod=Const.DEPLOYMENT_DATE)
Expand Down
100 changes: 100 additions & 0 deletions amenity_pj/apps/app_excel_play.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# from excel_play.main.data_type.data_type_master import DataTypeMaster
# from python_helpers.ph_modes_error_handling import PhErrorHandlingModes
# from excel_play.main.helper.defaults import Defaults
from excel_play.main.helper.constants_config import GIT_SUMMARY
from flask import render_template, request, jsonify
from python_helpers.ph_constants import PhConstants
from python_helpers.ph_keys import PhKeys
from python_helpers.ph_util import PhUtil

from amenity_pj.helper.constants import Const
from amenity_pj.helper.util import Util


def get_sample_data(key):
sample_data = {
PhKeys.SAMPLE_1: {
},
}
return sample_data.get(key, None)


def handle_requests(api=False):
"""
:return:
"""

default_data = {
'app_title': Const.TITLE_EXCEL_PLAY,
'app_description': Const.DESCRIPTION_EXCEL_PLAY,
'app_version': Const.VERSION_EXCEL_PLAY,
'app_github_url': Util.get_github_url(github_repo=Const.GITHUB_REPO_EXCEL_PLAY, github_pages=False),
'app_github_pages_url': Util.get_github_url(github_repo=Const.GITHUB_REPO_EXCEL_PLAY, github_pages=True),
'app_git_summary': GIT_SUMMARY,
PhKeys.SAMPLE_PROCESSING: PhKeys.SAMPLE_LOAD_ONLY,
PhKeys.OUTPUT_DATA: PhConstants.STR_EMPTY,
}
log_req = f'{Const.TEMPLATE_EXCEL_PLAY}; {request.method}; {"API" if api else "Form"} Request'
PhUtil.print_separator(main_text=f'{log_req} Received!!!')
requested_data_dict = request.get_json() if request.is_json else request.form.to_dict()
PhUtil.print_iter(requested_data_dict, header='Inputs')
if request.method == PhKeys.GET:
pass
if request.method == PhKeys.POST:
sample_processing = requested_data_dict.get(PhKeys.SAMPLE_PROCESSING, False)
# When submitting an HTML form,
# 1) unchecked checkboxes do not send any data, however checked checkboxes do send False (may send True as well)
pass
# 2) Everything is converted to String; below needs to be typecasted
pass
sample_data_dict = None
for key in requested_data_dict.keys():
if not key.startswith(PhKeys.SAMPLE):
continue
sample_data_dict = get_sample_data(key)
if sample_data_dict:
print('sample_data_dict is available')
break
if sample_data_dict and sample_processing == PhKeys.SAMPLE_LOAD_ONLY:
# Data Processing is not needed
pass
else:
# Data Processing is needed in all other cases
dic_received = sample_data_dict if sample_data_dict else requested_data_dict
# PhUtil.print_iter(dic_received, header='dic_received')
# Filter All Processing Related Keys
dic_to_process = {k: v for k, v in dic_received.items() if
not (k.startswith(PhKeys.SAMPLE) or k.startswith('process'))}
PhUtil.print_iter(dic_to_process, header='dic_to_process')
# data_type = DataTypeMaster()
# data_type.set_data_pool(data_pool=dic_to_process)
# data_type.parse_safe(PhErrorHandlingModes.CONTINUE_ON_ERROR)
# output_data = data_type.get_output_data()
# default_data.update({PhKeys.OUTPUT_DATA: output_data})
# if sample_data_dict:
# if PhKeys.RAW_DATA in sample_data_dict:
# default_data.update({PhKeys.RAW_DATA: sample_data_dict.get(PhKeys.RAW_DATA)})
# if 'length_in_decimal' in sample_data_dict:
# default_data.update({'length_in_decimal': sample_data_dict.get('length_in_decimal')})
# if 'value_in_ascii' in sample_data_dict:
# default_data.update({'value_in_ascii': sample_data_dict.get('value_in_ascii')})
# if 'one_liner' in sample_data_dict:
# default_data.update({'one_liner': sample_data_dict.get('one_liner')})
# if PhKeys.REMARKS_LIST in sample_data_dict:
# default_data.update({PhKeys.REMARKS_LIST: sample_data_dict.get(PhKeys.REMARKS_LIST)})
# else:
# if PhKeys.RAW_DATA in requested_data_dict:
# default_data.update({PhKeys.RAW_DATA: requested_data_dict[PhKeys.RAW_DATA]})
# if 'length_in_decimal' in requested_data_dict:
# default_data.update({'length_in_decimal': requested_data_dict['length_in_decimal']})
# if 'value_in_ascii' in requested_data_dict:
# default_data.update({'value_in_ascii': requested_data_dict['value_in_ascii']})
# if 'one_liner' in requested_data_dict:
# default_data.update({'one_liner': requested_data_dict['one_liner']})
# if PhKeys.REMARKS_LIST in requested_data_dict:
# default_data.update({PhKeys.REMARKS_LIST: requested_data_dict[PhKeys.REMARKS_LIST]})
default_data.update({PhKeys.SAMPLE_PROCESSING: sample_processing})
PhUtil.print_iter(default_data, header='Outputs')
PhUtil.print_separator(main_text=f'{log_req} Completed!!!')
return jsonify(**default_data) if api else render_template(Const.TEMPLATE_EXCEL_PLAY, **default_data)

0 comments on commit e2153f2

Please sign in to comment.