editor main_index api
This commit is contained in:
parent
daf037d136
commit
5c87cb9592
2 changed files with 21 additions and 4 deletions
|
@ -192,6 +192,22 @@ class APIHybridFormTemplateResponse(APIHybridResponse):
|
|||
return render(request, self.template, self.ctx)
|
||||
|
||||
|
||||
class APIHybridTemplateContextResponse(APIHybridResponse):
|
||||
def __init__(self, template: str, ctx: dict, fields=None):
|
||||
self.template = template
|
||||
self.ctx = ctx
|
||||
self.fields = fields
|
||||
|
||||
def get_api_response(self, request):
|
||||
result = self.ctx
|
||||
if self.fields:
|
||||
result = {name: value for name, value in result.items() if name in self.fields}
|
||||
return result
|
||||
|
||||
def get_html_response(self, request):
|
||||
return render(request, self.template, self.ctx)
|
||||
|
||||
|
||||
class NoAPIHybridResponse(Exception):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue