-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import OPML/CSE XML and more template buildout
- Loading branch information
Showing
10 changed files
with
146 additions
and
10 deletions.
There are no files selected for viewing
Empty file.
Empty file.
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,16 @@ | ||
from lxml import etree as ET | ||
from django.core.management.base import BaseCommand, CommandError | ||
from gcse.models import Annotation, CustomSearchEngine, Label | ||
|
||
|
||
class Command(BaseCommand): | ||
args = 'url_to_cse_xml' | ||
help = 'Import XML feed into CustomSearchEngine including Annotations' | ||
|
||
def handle(self, *args, **options): | ||
if len(args) != 1: | ||
self.stderr.write("import_cse " + Command.args) | ||
exit() | ||
url = args[0] | ||
cse = CustomSearchEngine.from_url(url, import_linked_annotations=True) | ||
cse.save() |
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,38 @@ | ||
from lxml import etree as ET | ||
from django.core.management.base import BaseCommand, CommandError | ||
from gcse.models import Annotation, CustomSearchEngine, Label | ||
|
||
|
||
class Command(BaseCommand): | ||
args = 'gid background_label path_to_opml.xml' | ||
help = 'Import outline elements from the specified opml.xml into the specified CustomSearchEngine as Annotations' | ||
|
||
def handle(self, *args, **options): | ||
if len(args) != 3: | ||
self.stderr.write("import_opml " + Command.args) | ||
exit() | ||
gid = args[0] | ||
try: | ||
cse = CustomSearchEngine.objects.get(gid=gid) | ||
except CustomSearchEngine.DoesNotExist: | ||
raise CommandError('CustomSearchEngine "%s" does not exist' % gid) | ||
|
||
try: | ||
label = Label.objects.get(name=args[1], | ||
background=True) | ||
except Label.DoesNotExist: | ||
raise CommandError('Background Label "%s" does not exist' % gid) | ||
|
||
tree = ET.parse(args[2]) | ||
for outline in tree.xpath('//outline'): | ||
annotation, created = Annotation.objects.get_or_create(comment=outline.attrib['title'], | ||
original_url=outline.attrib['xmlUrl']) | ||
if created: | ||
annotation.status = Annotation.STATUS.active | ||
annotation.about = Annotation.guess_google_url(annotation.original_url) | ||
annotation.labels.add(label) | ||
annotation.save() | ||
|
||
self.stdout.write('Successfully added Annotation "%s"' % annotation) | ||
else: | ||
self.stdout.write('Found existing Annotation "%s"' % annotation) |
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
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,31 @@ | ||
{% extends "gcse/base.html" %} | ||
{% load setting %} | ||
{% block title %}{% site "name" %} - {{ cse.title }} Annotations{% endblock %} | ||
|
||
{% block content %} | ||
<h1>{{ cse.title }} Annotations</h1> | ||
<p>There are {{count}} <span class="annotation tip">Annotations</span> for the <a href="{{ cse.get_absolute_url }}">{{ cse.title }} custom search engine</a> in the {% site "name" %} search database. You can also <a href="{% url 'gcse_browse_labels' %}">browse Annotations by label</a>.</p> | ||
{% block alpha-nav %} | ||
<ul class="alpha-nav pagination"> | ||
<colgroup>{% for i in index %}<col width="1*" />{%endfor%}</colgroup> | ||
{% for i in index %} | ||
<li class="{{i.style}}"><a href="?q={{i.i}}">{{i.i}}</a></li> | ||
{% endfor%} | ||
</ul> | ||
{% endblock alpha-nav %} | ||
<table class="table search-results"> | ||
<tbody> | ||
<tr><th>Name</th><th>Labels</th><th>URL</th></tr> | ||
{% for site in annotation_list %} | ||
<tr class="{% cycle 'odd' 'even' %}"><td><a href="{{site.get_absolute_url}}">{{ site.comment|escape }}</a></td><td>{{site.labels_as_links|safe}}</td><td><a href="{{site.original_url}}">{{site.original_url}}</a></td></tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% block pagination %} | ||
<ul class="pager"> | ||
<li class="previous"> {% if page_obj.has_previous %}<a href="?page={{ page_obj.previous_page_number }}">previous</a>{% endif %}</li> | ||
<li class="current">Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</li> | ||
<li class="next">{% if page_obj.has_next %}<a href="?page={{ page_obj.next_page_number }}">next</a>{% endif %}</li> | ||
</ul> | ||
{% endblock pagination %} | ||
{% endblock %} |
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 @@ | ||
{% extends "gcse/base.html" %} | ||
{% load setting %} | ||
{% block title %}{% site "name" %} - Custom Search Engine: {{ object.title }}{% endblock %} | ||
|
||
{% block content %} | ||
<h1>{{ object.title }}</h1> | ||
<p>This Google Custom Search Engine contains {{object.annotation_count}} Annotation entries.</p> | ||
<p><a href="{% url 'gcse_cse_annotation_list' gid=object.gid %}">View this Custom Search Engine's Annotations</a></p> | ||
<h2>Labels</h2> | ||
<table class="table search-results"> | ||
<tbody> | ||
<tr><th>Name</th></tr> | ||
{% for label in object.facetitems_labels %} | ||
<tr class="{% cycle 'odd' 'even' %}"><td><a href="{{label.get_absolute_url}}">{{ label.name|escape }}</a></td></tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endblock %} |
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