]> git.parisson.com Git - telemeta.git/commitdiff
ajout des fichiers
authorafilsaime <shadow_kungfu@hotmail.fr>
Mon, 20 Apr 2015 09:09:56 +0000 (11:09 +0200)
committerafilsaime <shadow_kungfu@hotmail.fr>
Mon, 20 Apr 2015 09:09:56 +0000 (11:09 +0200)
examples/sandbox/src/django-haystack [new submodule]
examples/sandbox/src/pip-delete-this-directory.txt [new file with mode: 0644]
telemeta/forms/haystack_form.py [new file with mode: 0644]
telemeta/haystack_urls.py [new file with mode: 0644]
telemeta/templates/search/indexes/telemeta/mediaitem_rec_date.txt [new file with mode: 0644]
telemeta/templates/search/mediaitem_listhaystack.html [new file with mode: 0644]
telemeta/templates/telemeta/hello_world.html [new file with mode: 0644]
telemeta/views/haystack_search.py [new file with mode: 0644]
telemeta/views/published.py [new file with mode: 0644]
telemeta/views/vuetest.py [new file with mode: 0644]

diff --git a/examples/sandbox/src/django-haystack b/examples/sandbox/src/django-haystack
new file mode 160000 (submodule)
index 0000000..97475f2
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 97475f2813a36e402296d5f2389fe10cd4cd1e0b
diff --git a/examples/sandbox/src/pip-delete-this-directory.txt b/examples/sandbox/src/pip-delete-this-directory.txt
new file mode 100644 (file)
index 0000000..c8883ea
--- /dev/null
@@ -0,0 +1,5 @@
+This file is placed here by pip to indicate the source was put
+here by pip.
+
+Once this package is successfully installed this source code will be
+deleted (unless you remove this file).
diff --git a/telemeta/forms/haystack_form.py b/telemeta/forms/haystack_form.py
new file mode 100644 (file)
index 0000000..cf1f5e5
--- /dev/null
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from django import forms
+from haystack.inputs import AutoQuery, Exact, Clean
+from haystack.forms import SearchForm
+from haystack.query import SearchQuerySet
+
+class HaySearchForm(SearchForm):
+
+    def search(self):
+        sqs=SearchQuerySet().load_all()
+
+        if not self.is_valid():
+            return sqs
+
+        if self.cleaned_data['q']:
+            sqs=sqs.filter(content__contains=self.cleaned_data['q'])
+
+        return sqs
+
diff --git a/telemeta/haystack_urls.py b/telemeta/haystack_urls.py
new file mode 100644 (file)
index 0000000..684abda
--- /dev/null
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+from django.conf.urls import patterns, url, include
+from telemeta.views.haystack_search import *
+from haystack.query import SearchQuerySet
+from haystack.views import SearchView
+from telemeta.forms.haystack_form import HaySearchForm
+
+
+urlpatterns = patterns('',
+    url(r'^$', SearchView(form_class=HaySearchForm), name='haystack_search'),
+)
diff --git a/telemeta/templates/search/indexes/telemeta/mediaitem_rec_date.txt b/telemeta/templates/search/indexes/telemeta/mediaitem_rec_date.txt
new file mode 100644 (file)
index 0000000..95e99e4
--- /dev/null
@@ -0,0 +1,4 @@
+
+{{ object.recorded_from_date }}
+{{ object.recorded_to_date }}
+
diff --git a/telemeta/templates/search/mediaitem_listhaystack.html b/telemeta/templates/search/mediaitem_listhaystack.html
new file mode 100644 (file)
index 0000000..da50f0f
--- /dev/null
@@ -0,0 +1,55 @@
+{% load telemeta_utils %}
+{% load i18n %}
+
+{% if page.object_list %}
+
+
+
+<table class="listing">
+<tr>
+    <th class="highlight">{% trans "Title" %}</th>
+    <th>{% trans "Digitized" %}</th>
+    <th>{% trans "Recordist" %}</th>
+    {% if location_name %}
+    <th>{% trans "Location" %}</th>
+    {% else %}
+    <th>{% trans "Country/Continent" %}</th>
+    {% endif %}
+    <th>{% trans "Year of recording" %}</th>
+    <th>{% trans "Code" %}</th>
+</tr>
+{% for result in page.object_list %}
+<tr {% if not forloop.counter0|divisibleby:"2" %}class="odd"{% endif %}>
+    <td class="highlight">
+        <a href="{% url "telemeta-item-detail" result.object.public_id %}">{{ result.object.title }}</a>
+    </td>
+    <td align="center">
+        {% if result.file %}
+         <a href="{% url "telemeta-item-detail" result.object.public_id %}">
+          <center><span class="glyphicon glyphicon-volume-up" style="font-size: 1.3em;"></span></center>
+        {% endif %}
+    </td>
+
+    <td>{{ result.object.collector }}</td>
+    {% if location_name %}
+    <td>{{ result.object.location.name }}</td>
+    {% else %}
+    <td>{{ result.object.country_or_continent|default:'&nbsp;' }}</td>
+    {% endif %}
+    <td>
+    {% if result.object.recorded_from_date %}
+        {{ result.object.recorded_from_date.year }}
+        {% if result.object.recorded_to_date and not result.object.recorded_to_date.year|equals:result.object.recorded_from_date.year %}
+            - {{ result.object.recorded_to_date.year }}
+        {% endif %}
+    {% endif %}
+    </td>
+    <td>
+        {{ result.object.code|default:result.object.old_code }}
+    </td>
+</tr>
+{% endfor %}
+</table>
+{% else %}
+    <p>{% trans "No item" %}</p>
+{% endif %}
diff --git a/telemeta/templates/telemeta/hello_world.html b/telemeta/templates/telemeta/hello_world.html
new file mode 100644 (file)
index 0000000..ef6efa2
--- /dev/null
@@ -0,0 +1,10 @@
+{% extends "telemeta/base.html" %}
+{% load telemeta_utils %}
+{% load i18n %}
+{% load bootstrap_pagination %}
+
+{% block content %}
+    <h1>Hello World</h1>
+    <p>Ceci est un test d'affichage</p>
+    <button type="button" id="btn" class="btn btn-default" onclick="location.href='{%url "telemeta-fullaccess-items"%}'"> <span class="glyphicon glyphicon-play" aria-hidden="true"></span> AccĂ©der aux items en libre acces</a>
+{% endblock %}
\ No newline at end of file
diff --git a/telemeta/views/haystack_search.py b/telemeta/views/haystack_search.py
new file mode 100644 (file)
index 0000000..ab0def1
--- /dev/null
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+
+from haystack.views import SearchView
+from haystack.query import SearchQuerySet
+
+class HaystackSearch(SearchView):
+
+    def get_query(self):
+        query=super(HaystackSearch, self).get_query()
+        return query
+
+
+
+
diff --git a/telemeta/views/published.py b/telemeta/views/published.py
new file mode 100644 (file)
index 0000000..f297b89
--- /dev/null
@@ -0,0 +1,141 @@
+# -*- coding: utf-8 -*-
+from telemeta.views.core import *
+
+class SearchViewPublished(ListView):
+    """Perform a search through resources"""
+
+    template_name='telemeta/search_results.html'
+    paginate_by = 20
+
+    def get_queryset(self):
+        input = self.request.GET
+        self.criteria = {}
+
+        self.type = None
+        if 'type' in self.kwargs:
+            self.type = self.kwargs['type']
+
+        self.collections = MediaCollection.objects.enriched()
+        self.items = MediaItem.objects.enriched().filter(code__contains="_E_")
+        self.corpus = MediaCorpus.objects.all()
+        self.fonds  = MediaFonds.objects.all()
+
+        switch = {
+            'pattern': lambda value: (
+                self.collections.quick_search(value),
+                self.items.quick_search(value),
+                self.corpus.quick_search(value),
+                self.fonds.quick_search(value),
+                ),
+            'title': lambda value: (
+                self.collections.word_search('title', value),
+                self.items.by_title(value),
+                self.corpus.word_search('title', value),
+                self.fonds.word_search('title', value)),
+            'location': lambda value: (
+                self.collections.by_location(Location.objects.get(name=value)),
+                self.items.by_location(Location.objects.get(name=value))),
+            'continent': lambda value: (
+                self.collections.by_continent(value),
+                self.items.filter(continent = value)),
+            'ethnic_group': lambda value: (
+                self.collections.by_ethnic_group(value),
+                self.items.filter(ethnic_group = value),
+                EthnicGroup.objects.get(pk=value)),
+            'creator': lambda value: (
+                self.collections.word_search('creator', value),
+                self.items.word_search('collection__creator', value)),
+            'collector': lambda value: (
+                self.collections.by_fuzzy_collector(value),
+                self.items.by_fuzzy_collector(value)),
+            'rec_year_from': lambda value: (
+                self.collections.by_recording_year(int(value), int(input.get('rec_year_to', value))),
+                self.items.by_recording_date(datetime.date(int(value), 1, 1),
+                                        datetime.date(int(input.get('rec_year_to', value)), 12, 31))),
+            'rec_year_to': lambda value: (self.collections, self.items),
+            'pub_year_from': lambda value: (
+                self.collections.by_publish_year(int(value), int(input.get('pub_year_to', value))),
+                self.items.by_publish_year(int(value), int(input.get('pub_year_to', value)))),
+            'pub_year_to': lambda value: (self.collections, self.items),
+            'sound': lambda value: (
+                self.collections.sound(),
+                self.items.sound()),
+            'instrument': lambda value: (
+                self.collections.by_instrument(value),
+                self.items.by_instrument(value)),
+        }
+
+        for key, value in input.items():
+            func = switch.get(key)
+            if func and value and value != "0":
+                try:
+                    res = func(value)
+                    if len(res)  > 4:
+                        self.collections, self.items, self.corpus, self.fonds, value = res
+                    elif len(res) == 4:
+                        self.collections, self.items, self.corpus, self.fonds = res
+                    elif len(res) == 3:
+                        self.collections, self.items, value = res
+                        self.corpus = self.corpus.none()
+                        self.fonds = self.fonds.none()
+                    else:
+                        self.collections, self.items = res
+                        self.corpus = self.corpus.none()
+                        self.fonds = self.fonds.none()
+
+                except ObjectDoesNotExist:
+                    self.collections = self.collections.none()
+                    self.items = self.items.none()
+                    self.corpus = self.corpus.none()
+                    self.fonds = self.fonds.none()
+
+                self.criteria[key] = value
+
+        # Save the search
+        user = self.request.user
+        if user:
+            if user.is_authenticated():
+                search = Search(username=user)
+                search.save()
+                if self.criteria:
+                    for key in self.criteria.keys():
+                        value = self.criteria[key]
+                        if key == 'ethnic_group':
+                            try:
+                                group = EthnicGroup.objects.get(value=value)
+                                value = group.id
+                            except:
+                                value = ''
+                        criter = Criteria(key=key, value=value)
+                        criter.save()
+                        search.criteria.add(criter)
+                    search.save()
+
+        if self.type is None:
+            if self.collections.count():
+                self.type = 'collections'
+            else:
+                self.type = 'items'
+
+        if self.type == 'items':
+            objects = self.items
+        elif self.type == 'collections':
+            objects = self.collections
+        elif self.type == 'corpus':
+            objects = self.corpus
+        elif self.type == 'fonds':
+            objects = self.fonds
+
+        self.objects = objects
+        return objects
+
+    def get_context_data(self, *args, **kwargs):
+        context = super(SearchView, self).get_context_data(*args, **kwargs)
+        context['criteria'] = self.criteria
+        context['collections_num'] =  self.collections.count()
+        context['items_num'] = self.items.count()
+        context['corpus_num']  = self.corpus.count()
+        context['fonds_num'] = self.fonds.count()
+        context['type'] = self.type
+        context['count'] = self.object_list.count()
+        return context
\ No newline at end of file
diff --git a/telemeta/views/vuetest.py b/telemeta/views/vuetest.py
new file mode 100644 (file)
index 0000000..40a96af
--- /dev/null
@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-