Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |