src/hdalab/views/profile.py
changeset 302 106c33871db4
parent 301 3ec8fb1afed8
child 308 eab6629b5b31
--- a/src/hdalab/views/profile.py	Tue Jul 22 17:06:21 2014 +0200
+++ b/src/hdalab/views/profile.py	Wed Jul 23 12:59:35 2014 +0200
@@ -98,12 +98,21 @@
             rk = get_object_or_404(Renkan, rk_id=rk_id)
             return HttpResponse(rk.content, content_type="application/json")
         
-        # Otherwise we build the datas    
+        # Otherwise we build the datas
+        # Get tags and countries
+        labels = request.GET.get("label", "").split(",")
+        countries = request.GET.get("country", "").split(",")
+        # Tags arrive with french label, countries with dbpedia uri
+        label_list = [t for t in labels if t!=""]
+        country_list = [c for c in countries if c!=""]
+        all_tags = Tag.objects.filter( Q(label__in=label_list) | Q(dbpedia_uri__in=country_list) ).select_related("dbpedia_fields")
+        
+        
         now = datetime.now().strftime("%Y-%m-%d %H:%M")
         
         content = {
           "id": unicode(uuid.uuid1()),
-          "title": "Renkan généré " + now,
+          "title": "",
           "description": "(empty description)",
           "created": now,
           "updated": now,
@@ -113,13 +122,6 @@
           "users": [],
         }
         
-        # Get tags and countries
-        labels = request.GET.get("label", "").split(",")
-        countries = request.GET.get("country", "").split(",")
-        # Tags arrive with french label, countries with dbpedia uri
-        label_list = [t for t in labels if t!=""]
-        country_list = [c for c in countries if c!=""]
-        all_tags = Tag.objects.filter( Q(label__in=label_list) | Q(dbpedia_uri__in=country_list) ).select_related("dbpedia_fields")
         
         # Get datasheets from ajax filter search
         filter_output = filter_generic(request.GET.get('lang',request.LANGUAGE_CODE), None, ",".join(label_list), ",".join(country_list))
@@ -131,6 +133,8 @@
         # Prepare other tags
         related_tags = []
         all_labels = [t.label for t in all_tags]
+        title = "Recherche " + ", ".join(all_labels)
+        content["title"] = title
         related_tags_dict = {}
         for c in filter_output["contents"]:
             c["id"] = unicode(uuid.uuid1())
@@ -208,7 +212,21 @@
                     #"created_by": "de68xf75y6hs5rgjhgghxbm217xk"
                 })
         
-        return HttpResponse(json.dumps(content), content_type="application/json")
+        response = json.dumps(content)
+        
+        if request.user.is_authenticated():
+            rk = Renkan()
+            rk.rk_id = unicode(uuid.uuid1())
+            rk.title = title
+            rk.content = response
+            rk.owner = request.user
+            rk.save()
+            hr = HdalabRenkan()
+            hr.renkan = rk
+            hr.state = HdalabRenkan.EDITION
+            hr.save()
+        
+        return HttpResponse(response, content_type="application/json")