mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 21:42:14 +00:00
Mockup webhook recieving view
This commit is contained in:
@@ -111,6 +111,7 @@ urlpatterns = [
|
||||
name='event_checkin_override'),
|
||||
|
||||
path('event/<int:pk>/thread/', permission_required_with_403('RIGS.change_event')(views.CreateForumThread.as_view()), name='event_thread'),
|
||||
path('event/webhook/', views.RecieveForumWebhook.as_view(), name='webhook_recieve'),
|
||||
|
||||
# Finance
|
||||
path('invoice/', permission_required_with_403('RIGS.view_invoice')(views.InvoiceIndex.as_view()),
|
||||
|
||||
@@ -5,6 +5,9 @@ import premailer
|
||||
import simplejson
|
||||
import urllib
|
||||
|
||||
from envparse import env
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.staticfiles import finders
|
||||
@@ -20,6 +23,7 @@ from django.urls import reverse_lazy
|
||||
from django.utils import timezone
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import generic
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from PyRIGS import decorators
|
||||
from PyRIGS.views import OEmbedView, is_ajax, ModalURLMixin, PrintView, get_related
|
||||
@@ -391,7 +395,18 @@ class CreateForumThread(generic.base.RedirectView):
|
||||
|
||||
params = {
|
||||
'title': str(event),
|
||||
'body': 'https://rigs.nottinghamtec.co.uk/event/{}'.format(event.pk),
|
||||
'body': '<span class="hidden" id="event-id">{}</span>https://rigs.nottinghamtec.co.uk/event/{}'.format(event.pk, event.pk),
|
||||
'category': 'rig-info'
|
||||
}
|
||||
return 'https://forum.nottinghamtec.co.uk/new-topic' + "?" + urllib.parse.urlencode(params)
|
||||
|
||||
|
||||
class RecieveForumWebhook(generic.View):
|
||||
@csrf_exempt
|
||||
def post(self, request, *args, **kwargs):
|
||||
if request.POST.get('secret') == env('FORUM_WEBHOOK_SECRET'):
|
||||
event_id = BeautifulSoup(request.POST.get('body'), "html.parser")
|
||||
event = models.Event.objects.filter(pk=soup.select_one('div[id="event-id"]')).first()
|
||||
if event:
|
||||
event.forum_url = ""
|
||||
event.save()
|
||||
|
||||
Reference in New Issue
Block a user