-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
56 lines (46 loc) · 1.89 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import logging
from django.http import HttpResponse
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import View, TemplateView
logger = logging.getLogger('django.field_updater')
@method_decorator(ensure_csrf_cookie, name='dispatch')
class ExampleView(TemplateView):
''' An endpoint to provide example use of this apps components '''
template_name = "field_updater/example.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['updater_options_number'] = dict(
inputAttributes=dict(type='number'),
)
context['updater_options_delete'] = dict(
allowDelete=True,
)
context['updater_options_headers'] = dict(
headers=dict(yourHeader='yourHeaderValue'),
)
context['updater_options_regex'] = dict(
inputAttributes=dict(
type='text',
pattern="[\w]{3}",
title='3 word characters'),
)
return context
class LoggingSubmitView(View):
''' An example submit view that does nothing just logs usefully '''
log_headers = ['Content-Type', 'Accept', 'IfMatch', 'IfUnmodifiedSince']
def post(self, request, *args, **kwargs):
''' update or create your stored value '''
logger.info(request)
for key in self.log_headers:
if key in request.headers:
logger.info("{}: {}".format(key, request.headers[key]))
logger.info(request.POST)
return HttpResponse()
def delete(self, request, *args, **kwargs):
''' delete your stored value '''
logger.info(request)
for key in self.log_headers:
if key in request.headers:
logger.info("{}: {}".format(key, request.headers[key]))
return HttpResponse()