create model meta

autogenerate_flutter
Mustafa Yontar 4 years ago
parent 590a3e8f93
commit e473ad4045
  1. 14
      models/User.py
  2. 36
      restapi/views.py

@ -4,9 +4,23 @@ from internal_lib.EncryptedField import EncryptedStringField
from models.EmbededDocuments import Descriptions from models.EmbededDocuments import Descriptions
from models.Group import Group from models.Group import Group
from models.Union import Union from models.Union import Union
from restapi import Methods
class User(Document): class User(Document):
meta = {
'index_background': True,
'index_cls': False,
'auto_create_index': True,
'can_query': True,
"quyery": {},
'methods': [Methods.Get, Methods.List, Methods.Create],
"indexes": [
('union'),
('username','union'),
('accept_date')
]
}
union = ReferenceField(Union) union = ReferenceField(Union)
member_no = LongField() member_no = LongField()
username = StringField() username = StringField()

@ -13,6 +13,7 @@ from restapi.resource import Resource
class ApiView(View): class ApiView(View):
model = None model = None
authentication_methods = [] authentication_methods = []
def __init__(self, model): def __init__(self, model):
self.start = time.time() self.start = time.time()
self.model = model self.model = model
@ -44,7 +45,12 @@ class ApiView(View):
return {'error': str(e)}, '404 Not Found' return {'error': str(e)}, '404 Not Found'
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
"""
TODO: check permissions
:param args:
:param kwargs:
:return:
"""
if 'pk' in kwargs: if 'pk' in kwargs:
try: try:
count, data = self.resource.to_json(pk=kwargs.get('pk')) count, data = self.resource.to_json(pk=kwargs.get('pk'))
@ -79,6 +85,13 @@ class ApiView(View):
return jsonify(response), kwargs.get('code', 200) return jsonify(response), kwargs.get('code', 200)
def post(self, *args, **kwargs): def post(self, *args, **kwargs):
"""
TODO: check permissions
:param args:
:param kwargs:
:return:
"""
try: try:
item = self.model(**request.json) item = self.model(**request.json)
item.validate() item.validate()
@ -97,10 +110,17 @@ class ApiView(View):
return self.get(pk=data.id, code=201) return self.get(pk=data.id, code=201)
def put(self, *args, **kwargs): def put(self, *args, **kwargs):
"""
TODO: check permissions
:param args:
:param kwargs:
:return:
"""
if "pk" not in kwargs: if "pk" not in kwargs:
return jsonify({ return jsonify({
'status': False, 'status': False,
"error":"Method not allowed" "error": "Method not allowed"
}), 403 }), 403
else: else:
try: try:
@ -118,5 +138,17 @@ class ApiView(View):
'errors': str(e) 'errors': str(e)
}), 400 }), 400
def has_read_permission(self, request, qs):
return qs
def has_add_permission(self, request, obj):
return True
def has_change_permission(self, request, obj):
return True
def has_delete_permission(self, request, obj):
return True
def delete(self, *args, **kwargs): def delete(self, *args, **kwargs):
"delete method" "delete method"

Loading…
Cancel
Save