api student
This commit is contained in:
@@ -27,6 +27,7 @@ Long description of module's purpose
|
|||||||
'views/student_course_views.xml',
|
'views/student_course_views.xml',
|
||||||
'reports/student_report_template.xml',
|
'reports/student_report_template.xml',
|
||||||
'reports/student_report.xml',
|
'reports/student_report.xml',
|
||||||
|
'data/student_cron.xml',
|
||||||
'views/student_menus.xml',
|
'views/student_menus.xml',
|
||||||
],
|
],
|
||||||
# only loaded in demonstration mode
|
# only loaded in demonstration mode
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from . import controllers
|
from . import student_api
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
from odoo import http
|
||||||
|
from odoo.http import request
|
||||||
|
import json
|
||||||
|
|
||||||
|
class StudentAPI(http.Controller):
|
||||||
|
@http.route('/student/students', type='http', auth='none', methods=['GET'])
|
||||||
|
def get_students(self, **kwargs):
|
||||||
|
token = kwargs.get('token')
|
||||||
|
valid_token = 'token_123'
|
||||||
|
|
||||||
|
if not token or token != valid_token:
|
||||||
|
return {
|
||||||
|
'error': 'Unauthorized',
|
||||||
|
"message": "Invalid API token"
|
||||||
|
}, 401
|
||||||
|
|
||||||
|
students = request.env['student.student'].sudo().search([])
|
||||||
|
student_list = []
|
||||||
|
|
||||||
|
for student in students:
|
||||||
|
student_list.append({
|
||||||
|
'id': student.id,
|
||||||
|
'name': student.name,
|
||||||
|
'email': student.email,
|
||||||
|
'gender': student.gender,
|
||||||
|
'phone': student.phone,
|
||||||
|
})
|
||||||
|
|
||||||
|
return json.dumps({'students': student_list}, ensure_ascii=False)
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="ir_cron_import_students" model="ir.cron">
|
||||||
|
<field name="name">Import Students</field>
|
||||||
|
<field name="model_id" ref="model_student_student"/>
|
||||||
|
<field name="interval_number">1</field>
|
||||||
|
<field name="interval_type">days</field>
|
||||||
|
<field name="state">code</field>
|
||||||
|
<field name="code"></field>
|
||||||
|
<field name="active" eval="True" />
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user