Added callbacks app with the base views

This commit is contained in:
Gonçalo Valério 2018-11-13 19:05:28 +00:00
parent 018ca3ff83
commit 24f47f34f3
9 changed files with 59 additions and 11 deletions

View File

@ -12,4 +12,4 @@ django = "==2.1.3"
channels = "==2.1.5"
[requires]
python_version = "3.6.6"
python_version = "3.6.7"

14
Pipfile.lock generated
View File

@ -1,11 +1,11 @@
{
"_meta": {
"hash": {
"sha256": "66738ee2668e8f81f37915ccb063d01fbcfda955ccb5aa932f8187ee8c53cf1f"
"sha256": "a1a6318c9a51fe4cd91cc030c573f2852081fa92365053bade1dcbbe3c3a96a0"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.6.6"
"python_version": "3.6.7"
},
"sources": [
{
@ -105,10 +105,7 @@
"pyhamcrest": {
"hashes": [
"sha256:6b672c02fdf7470df9674ab82263841ce8333fb143f32f021f6cb26f0e512420",
"sha256:7a4bdade0ed98c699d728191a058a60a44d2f9c213c51e2dd1e6fb42f2c6128a",
"sha256:8ffaa0a53da57e89de14ced7185ac746227a8894dbd5a3c718bf05ddbd1d56cd",
"sha256:bac0bea7358666ce52e3c6c85139632ed89f115e9af52d44b3c36e0bf8cf16a9",
"sha256:f30e9a310bcc1808de817a92e95169ffd16b60cbc5a016a49c8d0e8ababfae79"
"sha256:8ffaa0a53da57e89de14ced7185ac746227a8894dbd5a3c718bf05ddbd1d56cd"
],
"version": "==1.9.0"
},
@ -184,10 +181,10 @@
},
"autopep8": {
"hashes": [
"sha256:1b8d42ebba751a91090d3adb5c06840b1151d71ed43e1c7a9ed6911bfe8ebe6c"
"sha256:33d2b5325b7e1afb4240814fe982eea3a92ebea712869bfd08b3c0393404248c"
],
"index": "pypi",
"version": "==1.4.2"
"version": "==1.4.3"
},
"isort": {
"hashes": [
@ -240,7 +237,6 @@
},
"pycodestyle": {
"hashes": [
"sha256:74abc4e221d393ea5ce1f129ea6903209940c1ecd29e002e8c6933c2b21026e0",
"sha256:cbc619d09254895b0d12c2c691e237b2e91e9b2ecf5e84c26b35400f93dcfb83",
"sha256:cbfca99bd594a10f674d0cd97a3d802a1fdef635d4361e1a2658de47ed261e3a"
],

0
callbacks/__init__.py Normal file
View File

5
callbacks/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class CallbacksConfig(AppConfig):
name = 'callbacks'

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Webhook Logger</title>
</head>
<body></body>
</html>

3
callbacks/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

28
callbacks/views.py Normal file
View File

@ -0,0 +1,28 @@
from django.views.generic import RedirectView, TemplateView, View
from django.urls import reverse_lazy
from uuid import uuid4
class HomeView(RedirectView):
"""Initial page, just sends the visitor to an unique url"""
def get_redirect_url(self):
uuid = str(uuid4())
return f"{reverse_lazy('callback-check')}?cb={uuid}"
class CheckView(TemplateView):
"""Renders the page where users can monitor webhook
The activity shown is filtered by the unique ID assigned to
the visitor
"""
template_name = 'callbacks/check.html'
class CallbackView(View):
"""Webhook receiver view
This view receives any HTTP request, collects all the information
possible about the request, then sends it through the proper channel
"""

View File

@ -32,7 +32,8 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.staticfiles',
'channels'
'channels',
'callbacks'
]
MIDDLEWARE = [
@ -94,4 +95,5 @@ STATIC_URL = '/static/'
# Django Channels
ASGI_APPLICATION = "webhook_logger.routing.application"

View File

@ -14,6 +14,10 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import path
from callbacks.views import HomeView, CheckView, CallbackView
urlpatterns = [
path('check', CheckView.as_view(), name='callback-check'),
path('submit/<uuid>', CallbackView.as_view(), name='callback-submit'),
path('', HomeView.as_view(), name='callback-home')
]