ulsdevteam / ccvgd-backend Goto Github PK
View Code? Open in Web Editor NEWContemporary Chinese Village Gazetteer Data backend application
License: MIT License
Contemporary Chinese Village Gazetteer Data backend application
License: MIT License
In reviewing the code, @wopsononock and I noted that the logic is essentially identical between:
en_search/advancesearch
ccvgd-backend/app_func/en_search.py
Lines 693 to 836 in 3c15ca1
and
advancesearch
ccvgd-backend/app_func/advance_search.py
Lines 20 to 187 in 3c15ca1
This should be consolidated to a helper function which is called by both endpoints. Any time you are duplicating large sections of code, this should be abstracted into one or more functions to perform the action which can be reusable across the different callers.
When deploying the application, the administrator will need to modify config.py, especially the SQLALCHEMY_DATABASE_URL
. Some of the options in config.py are probably meant to be ignored by an administrator, and the value JSON_AS_ASCII
appears twice.
The configuration requirements should be documented in the readme file, with explanation of the relevant configuration options.
These configuration options also need to be used in the python files. Currently the database username and password is hardcoded in multiple locations:
ccvgd-backend/app_func/advance_search.py
Lines 31 to 36 in 9e08e87
ccvgd-backend/app_func/en_search.py
Lines 28 to 34 in 9e08e87
Instead, the database credentials should only be represented once, and only in the configuration file. The configuration file should represent example credentials, which the administrator will be required to customize.
The Multiple Village Download URL is currently structured to concatenate the villages and the topic with underscores as a GET request.
For example:
http://backend.tld/advancesearch/download/1_3_2_economy
Here 1, 2, and 3 are village ids and economy is the topic.
This does not align well with REST principles as it combines different query terms (objects) together.
This might be better represented as:
http://backend.tld/advancesearch/download/1_3_2/economy
or
http://backend.tld/advancesearch/download/1,3,2/economy
or
http://backend.tld/advancesearch/download/?village=1,3,2&term=economy
It might be tempting to pass query data via POST
, so that you can hand of a JSON object directly, like:
{
"village": [1, 2, 3],
"term": "economy"
}
But a POST
request should represent a data-change event, and this limits the ability for effective caching because the query context is removed from the URI.
Currently the en/search endpoint takes the topic as part of the post body. Given that the logic and format of the output are different for each topic, it might make more sense to give each topic its own route, and therefore its own function. The common code currently at the end of the function
ccvgd-backend/app_func/en_search.py
Lines 594 to 644 in 6e82448
Please document in the README the necessary python modules.
When initially run:
$ python app.py runserver -p 8081
Traceback (most recent call last):
File "app.py", line 2, in <module>
from manager import create_app
File "/opt/local/ccvgd/backend/manager.py", line 1, in <module>
from flask import Flask
ModuleNotFoundError: No module named 'flask'
Flask was identified as a dependency.
After installing Flask:
$ pip install Flask
Re-running the command continues to identify dependencies:
$ python app.py runserver -p 8081
Traceback (most recent call last):
File "app.py", line 2, in <module>
from manager import create_app
File "/opt/local/ccvgd/backend/manager.py", line 6, in <module>
from flask_cors import CORS
Similar to ulsdevteam/ccvgd-frontend#6, the compiled python bytecode represents more of a distribution or packaged form of the source code, and is probably not appropriate for the git repo.
Consider this default .gitignore
file for python:
https://github.com/github/gitignore/blob/master/Python.gitignore
The code in https://github.com/ulsdevteam/ccvgd-backend/tree/d637815432f32695484077d65830252b38dc72dd is a duplicate of https://github.com/ulsdevteam/ccvgd-database/tree/master/pythonScript.
As changes are added to https://github.com/ulsdevteam/ccvgd-database/tree/master/pythonScript, this local copy will become increasingly out of date. See, for example:
https://github.com/ulsdevteam/ccvgd-database/tree/master/pythonScript
Instead of copying the code from the other repository, please include instructions which link to the other repository, or include the other repository as a git submodule.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.