Skip to main content

Store user access token for one-time-login

Project description

Odoo REST Framework

Version : 1.1.1

Package :

pip install odoo_rest_framework
package link :
https://pypi.org/project/odoo-rest-framework/
github link :
https://github.com/HanZawNyein/odoo-rest-framework.git
Author :
Han Zaw Nyein
Author_email:
hanzawnyineonline@gmail.com

Description :

Store user access token for one-time-login

Code Example

import json from odoo import http from odoo.http import request from .odoo_rest_framework import ( jwt_http, validator, util, create_serializer, read_serializer, fields_extractor, update_serializer, send_notifications, )

class Testing(http.Controller): @http.route('/api/testing/list') def testing_list(self, *args, **kwargs): http_method, body, headers, token = jwt_http.parse_request() result = validator.verify_token(token) if not result['status']: return jwt_http.errcode(code=result['code'], message=result['message']) model_obj = request.env['market.review'] all_fields = fields_extractor(model_object=model_obj) market_review_ids = model_obj.sudo().search_read([], fields=all_fields) value_object = read_serializer(value_object=market_review_ids) return jwt_http.response(success=True, data=value_object)

@http.route('/api/testing/create', type='http', auth='public', csrf=False, cors='*', methods=['POST'])
def testing_create(self, *args: dict, **kwargs: dict):
    http_method, body, headers, token = jwt_http.parse_request()
    result = validator.verify_token(token)
    if not result['status']:
        return jwt_http.errcode(code=result['code'], message=result['message'])

    raw_body_data = request.httprequest.data
    my_json = raw_body_data.decode('utf8').replace("'", '"')
    data = json.loads(my_json)
    data['prospect_condition_lines'] = create_serializer(data['prospect_condition_lines'])
    model_obj = request.env['market.review']
    market_review_id = model_obj.create(data)
    return jwt_http.response(data={'id': market_review_id.id})

@http.route('/api/testing/update', type='http', auth='public', csrf=False, cors='*')
def testing_update(self, *args, **kwargs):
    http_method, body, headers, token = jwt_http.parse_request()
    result = validator.verify_token(token)
    if not result['status']:
        return jwt_http.errcode(code=result['code'], message=result['message'])

    raw_body_data = request.httprequest.data
    my_json = raw_body_data.decode('utf8').replace("'", '"')
    data = json.loads(my_json)
    model_obj = request.env['market.review'].browse(data.get('id'))  # .search([('id', '=', data.get('id'))])
    try:
        if model_obj.create_date:
            data['prospect_condition_lines'] = update_serializer(data['prospect_condition_lines'])
            data.pop('id')
            model_obj.create(data)
    except Exception as e:
        return jwt_http.response(success=False, message=str(e))

Response Example

{ "success": true, "message": null, "data": [ { "id": 54, "name": "Market Review for February 2022", "month": "2", "year": "2022", "division_id": { "id": 1, "name": "Yangon" }, "date": "2022-09-02", "total_broker": 100, "feedback": "dsfsdf", "feedback_type": "normal", "action_plan_feedback": "dsf", "action_plan_market": "fsdf", "market_condition_lines": null, "mio_condition_lines": null, "focus_bu_id": { "id": 10, "name": "Gyobinkauk" }, "focus_segment_id": { "id": 1, "name": "Motor" }, "prospect_condition_lines": [ 52 ], "competitor_information_lines": null, "state": "draft", "reject_reason": null, "create_date": "2022-09-23", "write_date": "2022-09-23" }, { "id": 55, "name": "Market Review for February 2022", "month": "2", "year": "2022", "division_id": { "id": 1, "name": "Yangon" }, "date": "2022-09-02", "total_broker": 100, "feedback": "dsfsdf", "feedback_type": "normal", "action_plan_feedback": "dsf", "action_plan_market": "fsdf", "market_condition_lines": null, "mio_condition_lines": null, "focus_bu_id": { "id": 10, "name": "Gyobinkauk" }, "focus_segment_id": { "id": 1, "name": "Motor" }, "prospect_condition_lines": [ 53 ], "competitor_information_lines": null, "state": "draft", "reject_reason": null, "create_date": "2022-09-23", "write_date": "2022-09-23" }, { "id": 56, "name": "Market Review for February 2022", "month": "2", "year": "2022", "division_id": { "id": 1, "name": "Yangon" }, "date": "2022-09-02", "total_broker": 100, "feedback": "dsfsdf", "feedback_type": "normal", "action_plan_feedback": "dsf", "action_plan_market": "fsdf", "market_condition_lines": null, "mio_condition_lines": null, "focus_bu_id": { "id": 10, "name": "Gyobinkauk" }, "focus_segment_id": { "id": 1, "name": "Motor" }, "prospect_condition_lines": [ 54 ], "competitor_information_lines": null, "state": "draft", "reject_reason": null, "create_date": "2022-09-23", "write_date": "2022-09-23" }, { "id": 57, "name": "Market Review for February 2022", "month": "2", "year": "2022", "division_id": { "id": 1, "name": "Yangon" }, "date": "2022-09-02", "total_broker": 100, "feedback": "dsfsdf", "feedback_type": "normal", "action_plan_feedback": "dsf", "action_plan_market": "fsdf", "market_condition_lines": null, "mio_condition_lines": null, "focus_bu_id": { "id": 10, "name": "Gyobinkauk" }, "focus_segment_id": { "id": 1, "name": "Motor" }, "prospect_condition_lines": [ 55 ], "competitor_information_lines": null, "state": "draft", "reject_reason": null, "create_date": "2022-09-23", "write_date": "2022-09-23" }, { "id": 58, "name": "Market Review for February 2022", "month": "2", "year": "2022", "division_id": { "id": 1, "name": "Yangon" }, "date": "2022-09-02", "total_broker": 100, "feedback": "dsfsdf", "feedback_type": "normal", "action_plan_feedback": "dsf", "action_plan_market": "fsdf", "market_condition_lines": null, "mio_condition_lines": null, "focus_bu_id": { "id": 10, "name": "Gyobinkauk" }, "focus_segment_id": { "id": 1, "name": "Motor" }, "prospect_condition_lines": [ 56 ], "competitor_information_lines": null, "state": "draft", "reject_reason": null, "create_date": "2022-09-23", "write_date": "2022-09-23" }, { "id": 59, "name": "Market Review for February 2022", "month": "2", "year": "2022", "division_id": { "id": 1, "name": "Yangon" }, "date": "2022-09-02", "total_broker": 100, "feedback": "dsfsdf", "feedback_type": "normal", "action_plan_feedback": "dsf", "action_plan_market": "fsdf", "market_condition_lines": null, "mio_condition_lines": null, "focus_bu_id": { "id": 10, "name": "Gyobinkauk" }, "focus_segment_id": { "id": 1, "name": "Motor" }, "prospect_condition_lines": [ 57 ], "competitor_information_lines": null, "state": "draft", "reject_reason": null, "create_date": "2022-09-23", "write_date": "2022-09-23" }, { "id": 60, "name": "Market Review for February 2022", "month": "2", "year": "2022", "division_id": { "id": 1, "name": "Yangon" }, "date": "2022-09-02", "total_broker": 100, "feedback": "dsfsdf", "feedback_type": "normal", "action_plan_feedback": "dsf", "action_plan_market": "fsdf", "market_condition_lines": null, "mio_condition_lines": null, "focus_bu_id": { "id": 10, "name": "Gyobinkauk" }, "focus_segment_id": { "id": 1, "name": "Motor" }, "prospect_condition_lines": [ 58 ], "competitor_information_lines": null, "state": "draft", "reject_reason": null, "create_date": "2022-09-23", "write_date": "2022-09-23" }, { "id": 61, "name": "Market Review for February 2022", "month": "2", "year": "2022", "division_id": { "id": 1, "name": "Yangon" }, "date": "2022-09-02", "total_broker": 100, "feedback": "dsfsdf", "feedback_type": "normal", "action_plan_feedback": "dsf", "action_plan_market": "fsdf", "market_condition_lines": null, "mio_condition_lines": null, "focus_bu_id": { "id": 10, "name": "Gyobinkauk" }, "focus_segment_id": { "id": 1, "name": "Motor" }, "prospect_condition_lines": [ 59 ], "competitor_information_lines": null, "state": "draft", "reject_reason": null, "create_date": "2022-09-23", "write_date": "2022-09-23" } ] }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

odoo_rest_framework-1.1.1.tar.gz (8.3 kB view details)

Uploaded Source

File details

Details for the file odoo_rest_framework-1.1.1.tar.gz.

File metadata

  • Download URL: odoo_rest_framework-1.1.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for odoo_rest_framework-1.1.1.tar.gz
Algorithm Hash digest
SHA256 dde8c2192d1c36edf31edd79d3cf9537d6c06743d52dfbd21d29b43ce9350e4e
MD5 a3481a98d4d1a6ceb03558ffd56e092c
BLAKE2b-256 96679570f2b955c10626feabdd2cd7e052ab76f8336b314224669eff59fcd258

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page