natanaelfneto / django_rest_autocomplete_tree

Django app simple example with rest framework to return autocomplete sugestions based on query formatted as json

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

autocomplete

Django REST Autocomplete Tree

Django app example with autocomplete suggestions based on query.
Version: 0.4


Dependencies:

  • Python 3 🐍
  • Django 2.1.3
  • django-filter 2.0.0
  • djangorestframework 3.9.0
  • Markdown 3.0.1
  • pytz 2018.7
  • sortedcontainers 2.1.0

Deprecated dependencies:

  • PyTrie 0.3.1

API:

URL Name Http Method Action URL Style Type of parameter
autocomplete GET List /autocomplete/{query} String

How run locally:

:octocat: Clone the repository
git clone https://github.com/natanaelfneto/django_rest_autocomplete_tree.git
πŸ‘Ύ Create a virtual environment, activate it and install project dependencies
mkvirtualenv autocomplete
workon autocomplete
pip install -r requirements.ext
πŸ“ˆ test and run it
python src/manage.py test api
python src/manage.py runserver
🌐 Access url in browser:

Example

Request:

curl -X GET -H "Content-Type: application/json" http://localhost:8000/autocomplete/lee

Response:

HTTP 200 OK
Allow: OPTIONS, GET
Content-Type: application/json
Vary: Accept
{
    "patients": [
        "lee chambers",
        "lee chavez",
        "lee clark",
        "lee hanson",
        "lee price",
        "leevi anttila",
        "leevi takala"
    ]
}

πŸ•— πŸ•“ πŸ•– Long runtime tests:

python src/manage.py test api --pattern="long_tests.py"

Obs: insted of default random values, run test on all possible values

TODOS and possible implementations:

  • βœ”οΈ API with Django 2 and REST Framework [OK]
  • βœ”οΈ Django App to return suggestion for patients names based on query as JSON [OK]
  • βœ”οΈ Implementation of automated tests [OK]
  • πŸ•“ Replace csv object with a database structure [PENDING]
  • πŸ•“ Replace virtual environment and requirements file with an automatic pyenv dependecies control [PENDING]
  • πŸ•“ Improve tests for a broadspects sets of values [PENDING]

CHANGELOG

0.4 2018-12-07

  • Own implemented tree class function with inheritance of python mapping
  • Node object class for tree nodes instancies
  • Null class for not interesting (complete) but true results of autocomplete routine
  • Replaced Pytrie library with own tree solution
  • Removed unecessary migrate command from readme

0.3 2018-11-28

  • Updated readme file
  • Add requirements file
  • Update commnetaries for better review on code
  • Api app test to assert example request status value splited in single and all values
  • Api app test to assert example request status value for all values commented due to its long runtime

0.2 2018-11-27

  • Added csv for patient data in ./assets/patient.csv
  • Updated readme file

0.1 2018-11-27

  • Django project created
  • Django app created for api
  • Api django app view for patient autocomplete suggestion created
  • Api app class for patients csv data base instance created
  • Api app url created
  • Api app test to assert request status value created
  • Api app test to assert example request data value created
  • Api app test response function to reduce code repetition

0.0 2018-11-27

  • Project folder created
  • Django implemented
  • Django REST Framework implemented

About

Django app simple example with rest framework to return autocomplete sugestions based on query formatted as json


Languages

Language:Python 100.0%