Permalink
Browse files

Search tweets backend

  • Loading branch information...
FrancoisConstant committed Jul 8, 2018
1 parent 8daa662 commit 897478851f88431cfc79c361e387288aabf64127
Showing with 52 additions and 0 deletions.
  1. +18 −0 ede/services.py
  2. +2 −0 ede/urls.py
  3. +18 −0 ede/views.py
  4. +14 −0 templates/ede/search.html
View
@@ -0,0 +1,18 @@
from ede.models import Tweet
def get_tweets_search_data():
return dict(
tweets=[
{
'author_url': tweet.author.url,
'author_name': tweet.author.name,
'content': tweet.content,
'searchString': "{username} {name} {content}".format(
username=tweet.author.username,
name=tweet.author.name,
content=tweet.content
).lower(),
} for tweet in Tweet.objects.prefetch_related('author').all()
]
)
View
@@ -4,4 +4,6 @@
urlpatterns = [
path('', views.index, name="index"),
path('search-tweets', view=views.search_tweets, name='search_tweets'),
path('search-tweets.json', view=views.search_tweets_json, name='search_tweets_json'),
]
View
@@ -1,5 +1,23 @@
from django.http import JsonResponse
from django.shortcuts import render
from ede.services import get_tweets_search_data
def index(request):
return render(request, "ede/index.html", {})
def search_tweets(request):
"""
Search tweets
search is handled via elm, we provide a json with all the necessary data via search_tweets_json below
"""
return render(request, 'ede/search.html')
def search_tweets_json(request):
""" All the tweets """
return JsonResponse(
data=get_tweets_search_data()
)
View
@@ -0,0 +1,14 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Elm Django Example</title>
</head>
<body>
<h1>Elm Django Example - Search</h1>
<div id="elm-search"></div>
<script src="{% static 'ede/elm.js' %}"></script>
<script type="text/javascript">Elm.Ede.embed(document.querySelector("#elm-search"));</script>
</body>
</html>

0 comments on commit 8974788

Please sign in to comment.