Merge branch 'femilamptey-master'
This commit is contained in:
commit
8bf0ae0a79
3 changed files with 40 additions and 2 deletions
|
@ -173,6 +173,25 @@ def update_event_searchable(event):
|
|||
|
||||
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)
|
||||
searchable.delete()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def slugify(s, ok=SLUG_OK, lower=True, spaces=False):
|
||||
# L and N signify letter/number.
|
||||
# http://www.unicode.org/reports/tr44/tr44-4.html#GC_Values_Table
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.test import TestCase
|
||||
from model_mommy import mommy
|
||||
|
||||
from ..models.events import Event
|
||||
from ..models.events import Event, delete_event_searchable
|
||||
from ..models.search import Searchable
|
||||
|
||||
# Create your tests here.
|
||||
|
@ -38,3 +38,20 @@ class SearchableCreationTest(TestCase):
|
|||
assert(searchables.count() == 1)
|
||||
assert(searchables[0].event_title == "New Title")
|
||||
|
||||
def test_delete_searchable_with_event(self):
|
||||
searchables = Searchable.objects.all()
|
||||
assert(searchables.count() == 0)
|
||||
|
||||
event = mommy.make(Event)
|
||||
event.save()
|
||||
|
||||
searchables = Searchable.objects.all()
|
||||
assert(searchables.count() == 1)
|
||||
|
||||
delete_event_searchable(event)
|
||||
event.delete()
|
||||
|
||||
searchables = Searchable.objects.all()
|
||||
assert(searchables.count() == 0)
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ from django.shortcuts import render, redirect, reverse, get_object_or_404
|
|||
from django.http import HttpResponse, JsonResponse
|
||||
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.forms import (
|
||||
TeamEventForm,
|
||||
|
@ -276,6 +277,7 @@ def delete_event(request, event_id):
|
|||
form = DeleteEventForm(request.POST)
|
||||
if form.is_valid() and form.cleaned_data['confirm']:
|
||||
team_id = event.team_id
|
||||
delete_event_searchable(event);
|
||||
event.delete()
|
||||
return redirect('show-team', team_id)
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue