# HG changeset patch # User cavaliet # Date 1409321971 -7200 # Node ID 67cff4e39ad8e9c97096322172add57272139f2f # Parent 4c72bc520e191b6da34b37a8f964e0e6bf823009 search in notice json, and renkan search bin for notices. diff -r 4c72bc520e19 -r 67cff4e39ad8 src/hdabo/urls.py --- a/src/hdabo/urls.py Thu Aug 28 18:16:02 2014 +0200 +++ b/src/hdabo/urls.py Fri Aug 29 16:19:31 2014 +0200 @@ -52,6 +52,6 @@ url(r'^folders/$', login_required(Folders.as_view()), name='folders'), url(r'^folder/$', login_required(AddOrUpdateFolder.as_view()), name='add_or_update_folder'), url(r'^folder/(?P[\w-]+)$', login_required(AddOrUpdateFolder.as_view()), name='add_or_update_folder'), - url(r'^searchajax/$', login_required(SearchDatasheet()), name='searchajax'), + url(r'^searchajax/$', SearchDatasheet(), name='searchajax'), url(r'^deletefolder/(?P[\w-]+)$', login_required(DeleteFolder.as_view()), name='delete_folder'), ) diff -r 4c72bc520e19 -r 67cff4e39ad8 src/hdabo/views.py --- a/src/hdabo/views.py Thu Aug 28 18:16:02 2014 +0200 +++ b/src/hdabo/views.py Fri Aug 29 16:19:31 2014 +0200 @@ -19,6 +19,7 @@ import re from django.views.generic.base import TemplateView, View from haystack.views import SearchView +from django.http.response import HttpResponse @login_required @@ -630,6 +631,42 @@ template = "partial/search_datasheet_for_folders.html" + def create_response(self): + """ + Generates the actual HttpResponse to send back to the user. + """ + limit = self.request.GET.get("limit", -1) + try: + limit = int(limit) + except: + pass + if limit>0: + self.results_per_page = limit + + (paginator, page) = self.build_page() + + context = { + 'query': self.query, + 'form': self.form, + 'page': page, + 'paginator': paginator, + 'suggestion': None, + } + + if self.results and hasattr(self.results, 'query') and self.results.query.backend.include_spelling: + context['suggestion'] = self.form.get_suggestion() + + context.update(self.extra_context()) + + if self.request.GET.get("format", "")=="json": + output = { "results": [] } + for result in page.object_list: + o = result.object + output["results"].append({"title":o.title, "description":o.description, "url":o.url, "hda_id":o.hda_id}) + return HttpResponse(json.dumps(output, indent=2), content_type="application/json") + + return render_to_response(self.template, context, context_instance=self.context_class(self.request)) + class DeleteFolder(View): diff -r 4c72bc520e19 -r 67cff4e39ad8 src/hdalab/static/hdalab/css/additionnal_renkan.css --- a/src/hdalab/static/hdalab/css/additionnal_renkan.css Thu Aug 28 18:16:02 2014 +0200 +++ b/src/hdalab/static/hdalab/css/additionnal_renkan.css Fri Aug 29 16:19:31 2014 +0200 @@ -16,4 +16,11 @@ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; +} +.Rk-HdaNotices-Title-Icon { + background: url("../img/page_icon.png") no-repeat 0 -5px; + height: 20px; +} +.Rk-HdaNotices-Search-Icon { + background: url("../img/page_icon.png") no-repeat 0 -5px; } \ No newline at end of file diff -r 4c72bc520e19 -r 67cff4e39ad8 src/hdalab/static/hdalab/js/hdalab-renkan-bins.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hdalab/static/hdalab/js/hdalab-renkan-bins.js Fri Aug 29 16:19:31 2014 +0200 @@ -0,0 +1,212 @@ +/* Rkns.HdaNotices bin definition : search form and result rendering */ + +Rkns.HdaNotices = { +}; + +Rkns.HdaNotices.Search = function(_renkan, _opts) { + this.renkan = _renkan; + this.lang = _opts.lang || "fr"; + this.image = _opts.image; + this.url = _opts.url; +}; + +Rkns.HdaNotices.Search.prototype.getBgClass = function() { + return "Rk-HdaNotices-Search-Icon"; +}; + +Rkns.HdaNotices.Search.prototype.getSearchTitle = function() { + return this.renkan.translate("Notices Hda"); +}; + +Rkns.HdaNotices.Search.prototype.search = function(_q) { + this.renkan.tabs.push( + new Rkns.HdaNotices.Bin(this.renkan, { + lang: this.lang, + url: this.url, + image: this.image, + search: _q + }) + ); +}; + +Rkns.HdaNotices.Bin = Rkns.Utils.inherit(Rkns._BaseBin); + +Rkns.HdaNotices.Bin.prototype.resultTemplate = Rkns._.template( + '
  • ' + + '

    <%=htitle%>

    ' + + '

    <%=hdescription%>

  • ' +); + +Rkns.HdaNotices.Bin.prototype._init = function(_renkan, _opts) { + this.renkan = _renkan; + this.search = _opts.search; + this.lang = _opts.lang || "fr"; + this.url = _opts.url; + this.image = _opts.image; + this.title_icon_$.addClass('Rk-HdaNotices-Title-Icon'); + this.title_$.html(this.search).addClass("Rk-HdaNotices-Title"); + this.refresh(); +}; + +Rkns.HdaNotices.Bin.prototype.render = function(searchbase) { + var search = searchbase || Rkns.Utils.regexpFromTextOrArray(); + var highlightrx = (search.isempty ? Rkns.Utils.regexpFromTextOrArray(this.search) : search); + function highlight(_text) { + return highlightrx.replace(_(_text).escape(), "$1"); + } + var _html = "", + _this = this, + count = 0; + Rkns._(this.data.results).each(function(_result) { + console.log(_result); + var title = _result.title, + url = _result.url, + full_description = _result.description, + description = _result.description.substr(0, _result.description.indexOf(" ", 170)) + "...", + image = "http://www.histoiredesarts.culture.fr/images/pf/" + _result.hda_id + ".jpg"; + if (!search.isempty && !search.test(title) && !search.test(description)) { + return; + } + count++; + _html += _this.resultTemplate({ + url: url, + title: title, + htitle: highlight(title), + full_description: full_description, + description: description, + hdescription: highlight(description), + image: image + }); + }); + _this.main_$.html(_html); + if (!search.isempty && count) { + this.count_$.text(count).show(); + } else { + this.count_$.hide(); + } + if (!search.isempty && !count) { + this.$.hide(); + } else { + this.$.show(); + } + this.renkan.resizeBins(); +}; + +Rkns.HdaNotices.Bin.prototype.refresh = function() { + var _this = this; + console.log("refresh"); + Rkns.$.ajax({ + url: this.url + "?q=" + encodeURIComponent(this.search) + "&format=json&limit=50", + success: function(_data) { + console.log("ntm"); + _this.data = _data; + _this.render(); + } + }); +}; + + +/* Rkns.HdaTags bin definition : search form and result rendering */ +/* +Rkns.HdaTags = { +}; + +Rkns.HdaTags.Search = function(_renkan, _opts) { + this.renkan = _renkan; + this.lang = _opts.lang || "fr"; + this.image = _opts.image; + console.log("2",this.image); +}; + +Rkns.HdaTags.Search.prototype.getBgClass = function() { + return "Rk-HdaTags-Search-Icon"; +}; + +Rkns.HdaTags.Search.prototype.getSearchTitle = function() { + return this.renkan.translate("Tags Hda"); +}; + +Rkns.HdaTags.Search.prototype.search = function(_q) { + this.renkan.tabs.push( + new Rkns.HdaTags.Bin(this.renkan, { + lang: this.lang, + image: this.image, + search: _q + }) + ); +}; + +Rkns.HdaTags.Bin = Rkns.Utils.inherit(Rkns._BaseBin); + +Rkns.HdaTags.Bin.prototype.resultTemplate = Rkns._.template( + '
  • ' + + '

    HDA TAGS : <%=htitle%>

    ' + + '

    <%=hdescription%>

  • ' +); + +Rkns.HdaTags.Bin.prototype._init = function(_renkan, _opts) { + this.renkan = _renkan; + this.search = _opts.search; + this.lang = _opts.lang || "fr"; + this.image = _opts.image; + console.log("1",this.image,_opts); + this.title_icon_$.addClass('Rk-Wikipedia-Title-Icon'); + this.title_$.html(this.search).addClass("Rk-Wikipedia-Title"); + this.refresh(); +}; + +Rkns.HdaTags.Bin.prototype.render = function(searchbase) { + var search = searchbase || Rkns.Utils.regexpFromTextOrArray(); + var highlightrx = (search.isempty ? Rkns.Utils.regexpFromTextOrArray(this.search) : search); + function highlight(_text) { + return highlightrx.replace(_(_text).escape(), "$1"); + } + var _html = "", + _this = this, + count = 0; + Rkns._(this.data.query.search).each(function(_result) { + var title = _result.title, + url = "http://" + _this.lang + ".wikipedia.org/wiki/" + encodeURI(title.replace(/ /g,"_")), + description = Rkns.$('
    ').html(_result.snippet).text(); + if (!search.isempty && !search.test(title) && !search.test(description)) { + return; + } + count++; + _html += _this.resultTemplate({ + url: url, + title: title, + htitle: highlight(title), + description: description, + hdescription: highlight(description), + static_url: _this.renkan.options.static_url, + image: _this.image + }); + }); + _this.main_$.html(_html); + if (!search.isempty && count) { + this.count_$.text(count).show(); + } else { + this.count_$.hide(); + } + if (!search.isempty && !count) { + this.$.hide(); + } else { + this.$.show(); + } + this.renkan.resizeBins(); +}; + +Rkns.HdaTags.Bin.prototype.refresh = function() { + var _this = this; + Rkns.$.ajax({ + url: "http://" + _this.lang + ".wikipedia.org/w/api.php?action=query&list=search&srsearch=" + encodeURIComponent(this.search) + "&format=json", + dataType: "jsonp", + success: function(_data) { + _this.data = _data; + _this.render(); + } + }); +}; +*/ \ No newline at end of file diff -r 4c72bc520e19 -r 67cff4e39ad8 src/hdalab/templates/renkan_edit.html --- a/src/hdalab/templates/renkan_edit.html Thu Aug 28 18:16:02 2014 +0200 +++ b/src/hdalab/templates/renkan_edit.html Fri Aug 29 16:19:31 2014 +0200 @@ -25,7 +25,8 @@ - + +