浏览代码

[search] Default template list all the fields

Romain Rigaux 12 年之前
父节点
当前提交
f768079

+ 6 - 7
apps/search/src/search/conf.py

@@ -25,6 +25,12 @@ SOLR_URL = Config(
   help=_("URL of the Solr Server."),
   default="http://localhost:8983/solr/")
 
+EMPTY_QUERY = Config(
+  key="empty_query",
+  help=_("Query sent when no term is entered."),
+  default="*:*")
+
+
 #SOLR_URLS = UnspecifiedConfigSection(
 #  "solr_urls",
 #  help="One entry for each Solr server",
@@ -38,10 +44,3 @@ SOLR_URL = Config(
 #)
 
 # ZOOKEEPER URL
-# for COLLECTIONS
-
-
-EMPTY_QUERY = Config(
-  key="empty_query",
-  help=_("Query sent when no term is entered."),
-  default="*:*")

+ 18 - 145
apps/search/src/search/models.py

@@ -198,154 +198,15 @@ class CollectionManager(models.Manager):
                    'dates': []
                 }))
       result = Result.objects.create(data=json.dumps({
-                  'template': """
-<div class="row-fluid">
-  <div class="span1"><img src="http://twitter.com/api/users/profile_image/{{user_screen_name}}" style="margin:10px"></div>
-  <div class="span9">
-    <h5><a href="https://twitter.com/{{user_screen_name}}/status/{{id}}" target="_blank" title="Open in Twitter"></a><a target="_blank" href="https://twitter.com/{{user_screen_name}}">{{user_name}}</a></h5>
-
-    {{text}}
-
-    <br>
-    <a href="/filebrowser/view/{{file_path}}">
-      {{file_name}} {{file_length}}{{#file_length}} bytes {{content_type}}{{/file_length}}
-    </a>
-    {{#file_path}}
-    <a href="/filebrowser/download{{file_path}}?disposition=inline">
-      Download
-    </a>
-    {{/file_path}}
-     <div class="stream-item-footer">
-        <ul class="tweet-actions">
-          <li class="action">
-            <a href="https://twitter.com/intent/tweet?in_reply_to={{id}}" target="_blank">
-              <i class="icon icon-reply"></i>
-              <b>Reply</b>
-            </a>
-          </li>
-          <li class="action">
-            <a href="https://twitter.com/intent/retweet?tweet_id={{id}}" target="_blank">
-              <i class="icon icon-retweet"></i>
-              <b>Retweet</b>
-            </a>
-          </li>
-        </ul>
-      </div>
-
-  </div>
-  <div class="span2">
-    <br><a class="btn" href="https://twitter.com/{{user_screen_name}}/status/{{id}}" target="_blank" title="Open in Twitter">
-    <i class="icon-share-alt"></i></a>
-    <small class="time">
-      <a href="https://twitter.com/{{user_screen_name}}/status/{{id}}" target="_blank" data-dt="{{created_at}}" rel="tooltip" data-placement="left" title="{{created_at}}">{{created_at}}</a>
-    </small>
-  </div>
-</div>
-                  """,
+                  'template': '',
                   'highlighting': [],
                   'properties': {'highlighting_enabled': False},
-                  'extracode': #"<style>\n</style>\n\n<script>\n</script>"
+                  'extracode':
                   """
 <style>
-.content {
-margin-left: 58px;
-}
-
-.action {
-margin-right: 5px;
-}
-
-.action a, .time a, .account-group, .retweeted {
-color: #999999;
-}
-
-.account-group a {
-text-decoration: none;
-font-weight: normal;
-}
-
-.username {
-font-size: 12px;
-}
-
-.time {
-color: #BBBBBB;
-float: right;
-margin-top: 1px;
-position: relative;
-}
-
-.avatar {
-position: absolute;
-margin-left: -56px!important;
-margin-top: 4px!important;
--webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
--moz-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
--webkit-border-radius: 5px;
--moz-border-radius: 5px;
-border-radius: 5px;
-}
-
-.text {
-margin-bottom: 4px;
-cursor: pointer;
-}
-
-.tweet-actions li {
-display: inline;
-}
-
-.stream-item-footer {
-font-size: 12px;
-color: #999999;
-}
-
-ul.tweet-actions {
-list-style: none outside none;
-}
-
-ul.tweet-actions {
-margin: 0;
-padding: 0;
-}
-
-.fullname {
-color: #333333;
-font-weight: bold;
-}
-
-.stream-item-footer, .retweeted {
-font-size: 12px;
-padding-top: 1px;
-}
-
-.icon {
-background-position: 0 0;
-background-repeat: no-repeat;
-display: inline-block;
-vertical-align: text-top;
-height: 13px;
-width: 14px;
-margin-top: 0;
-margin-left: -2px;
+em {
+  color: red;
 }
-.icon-reply {
-background-image: url("/search/static/art/reply.png");
-}
-.icon-retweet {
-background-image: url("/search/static/art/retweet.png");
-}
-.twitter-logo {
-background-image: url("/search/static/art/bird_gray_32.png");
-width: 32px;
-height: 32px;
-background-repeat: no-repeat;
-display: inline-block;
-vertical-align: top;
-margin-top: 2px;
-}
-
 </style>
 
 <script>
@@ -355,7 +216,7 @@ margin-top: 2px;
       sorting = Sorting.objects.create(data=json.dumps({'properties': {'is_enabled': False}, 'fields': []}))
       cores = json.dumps(solr_properties)
 
-      return Collection.objects.create(
+      collection = Collection.objects.create(
           name=name,
           label=name,
           enabled=is_enabled,
@@ -364,7 +225,19 @@ margin-top: 2px;
           facets=facets,
           result=result,
           sorting=sorting
-      ), True
+      )
+
+      template = """
+<div class="row-fluid">
+  <div class="row-fluid">
+    <div class="span12">%s</div>
+  </div>
+</div>""" % ' '.join(['{{%s}}' % field for field in collection.fields])
+
+      result.update_from_post({'template': json.dumps(template)})
+      result.save()
+
+      return collection, True
 
 
 class Collection(models.Model):

+ 4 - 4
apps/search/src/search/search_controller.py

@@ -94,7 +94,7 @@ class SearchController(object):
     try:
       copy = Collection.objects.get(id=collection_id)
       copy.label += _(' (Copy)')
-      copy.id = copy.pk = None      
+      copy.id = copy.pk = None
       copy.save()
 
       facets = copy.facets
@@ -112,9 +112,9 @@ class SearchController(object):
       sorting.id = None
       sorting.save()
       copy.sorting = sorting
-      
-      copy.save() 
-                
+
+      copy.save()
+
       id = copy.id
     except Exception, e:
       LOG.warn('Error copying collection: %s' % e)

+ 2 - 2
apps/search/src/search/templates/admin_collection_properties.mako

@@ -63,9 +63,9 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
     <div class="tab-content">
       <div class="tab-pane active" id="index">
         <div class="fieldWrapper">
-          ${ utils.render_field(collection_form['enabled']) }          
+          ${ utils.render_field(collection_form['enabled']) }
           ${ utils.render_field(collection_form['label']) }
-          ${ utils.render_field(collection_form['name']) }          
+          ${ utils.render_field(collection_form['name']) }
         </div>
 
 	    <div class="form-actions">

+ 1 - 1
apps/search/src/search/templates/admin_collections.mako

@@ -65,7 +65,7 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
   </div>
 
   <script id="collectionTemplate" type="text/html">
-    <li style="cursor: pointer" data-bind="click: $root.editCollection">
+    <li style="cursor: pointer" data-bind="click: $root.editCollection" title="${ _('Click to edit') }">
       <div class="pull-right" style="margin-top: 10px;margin-right: 10px; cursor: pointer">
         <a data-bind="click: $root.copyCollection, clickBubble: false"><i class="icon-copy"></i> ${_('Copy')}</a> &nbsp;
         <a data-bind="click: $root.markForDeletion, clickBubble: false"><i class="icon-remove"></i> ${_('Delete')}</a>

+ 1 - 1
apps/search/src/search/templates/layout.mako

@@ -25,7 +25,7 @@
   <link rel="stylesheet" href="/static/ext/chosen/chosen.css">
   <script src="/static/ext/chosen/chosen.jquery.min.js" type="text/javascript" charset="utf-8"></script>
   <script src="/static/ext/js/knockout-2.1.0.js" type="text/javascript" charset="utf-8"></script>
-  
+
   <div class="search-bar" style="height: 30px">
     % if not hasattr(caller, "no_navigation"):
       <div class="pull-right" style="margin-top: 4px; margin-right: 20px">

+ 1 - 1
apps/search/src/search/templates/search.mako

@@ -255,7 +255,7 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
         $(".change-settings").attr("href", collectionUrl);
       % endif
     % endif
-    
+
     $(".dropdown-collection").click(function (e) {
       e.preventDefault();
       var collectionId = $(this).data("value");

+ 1 - 1
apps/search/src/search/views.py

@@ -58,7 +58,7 @@ def index(request):
   if search_form.is_valid():
     collection_id = search_form.cleaned_data['collection']
     if request.GET.get('collection') is None:
-      collection_id = request.COOKIES.get('hueSearchLastCollection', collection_id)    
+      collection_id = request.COOKIES.get('hueSearchLastCollection', collection_id)
     solr_query['q'] = search_form.cleaned_data['query']
     solr_query['fq'] = search_form.cleaned_data['fq']
     if search_form.cleaned_data['sort']: