Created function to delete Searchables when event is deleted

Added the function
delete_event_searchable

in events\model\events.py, which deletes the searchable for an event, and called that function in

get_together\views\events.py

in the delete_event function to delete the searchable for the event before deleting the event
This commit is contained in:
Femi Lamptey 2018-04-17 11:47:38 +00:00
parent 23ab01b374
commit d124585079
2 changed files with 26 additions and 1 deletions

View file

@ -173,6 +173,29 @@ def update_event_searchable(event):
searchable.save() searchable.save()
def delete_event_searchable(event):
site = Site.objects.get(id=1)
event_url = "https://%s%s" % (site.domain, event.get_absolute_url())
origin_url = "https://%s%s" % (site.domain, reverse('searchables'))
md5 = hashlib.md5()
federation_url = event_url.split('/')
federation_node = '/'.join(federation_url[:3])
federation_id = '/'.join(federation_url[:5])
md5.update(bytes(federation_id, 'utf8'))
event_uri = federation_node + '/' + md5.hexdigest()
try:
searchable = Searchable.objects.get(event_uri=event_uri)
except:
searchable = Searchable(event_uri)
searchable.origin_node = origin_url
searchable.federation_node = origin_url
searchable.federation_time = timezone.now()
searchable.event_url = event_url
searchable.delete()
def slugify(s, ok=SLUG_OK, lower=True, spaces=False): def slugify(s, ok=SLUG_OK, lower=True, spaces=False):
# L and N signify letter/number. # L and N signify letter/number.
# http://www.unicode.org/reports/tr44/tr44-4.html#GC_Values_Table # http://www.unicode.org/reports/tr44/tr44-4.html#GC_Values_Table

View file

@ -7,7 +7,8 @@ from django.shortcuts import render, redirect, reverse, get_object_or_404
from django.http import HttpResponse, JsonResponse from django.http import HttpResponse, JsonResponse
from django.utils import timezone from django.utils import timezone
from events.models.events import Event, CommonEvent, EventSeries, EventPhoto, Place, Attendee from events.models.events import Event, CommonEvent, EventSeries, EventPhoto, Place, Attendee, update_event_searchable, \
delete_event_searchable
from events.models.profiles import Team, Organization, UserProfile, Member from events.models.profiles import Team, Organization, UserProfile, Member
from events.forms import ( from events.forms import (
TeamEventForm, TeamEventForm,
@ -276,6 +277,7 @@ def delete_event(request, event_id):
form = DeleteEventForm(request.POST) form = DeleteEventForm(request.POST)
if form.is_valid() and form.cleaned_data['confirm']: if form.is_valid() and form.cleaned_data['confirm']:
team_id = event.team_id team_id = event.team_id
delete_event_searchable(event);
event.delete() event.delete()
return redirect('show-team', team_id) return redirect('show-team', team_id)
else: else: