update model and fixture
authorymh <ymh.work@gmail.com>
Fri, 17 Jun 2011 14:17:49 +0200
changeset 43 e0812bc3ef44
parent 42 861a78f74a37
child 44 244d805b4921
update model and fixture - wikipedia_activated - Categories Add check existing tag on datasheet
web/hdabo/fixtures/datasheet_10.yaml.bz2
web/hdabo/fixtures/datasheet_347.yaml.bz2
web/hdabo/fixtures/datasheet_all.yaml.bz2
web/hdabo/management/commands/querywikipedia.py
web/hdabo/models.py
web/hdabo/static/hdabo/js/hdabo.js
web/hdabo/templates/all_tags.html
web/hdabo/templates/list_for_orga.html
web/hdabo/templates/partial/all_tags_table.html
web/hdabo/urls.py
web/hdabo/views.py
web/hdabo/wp_utils.py
Binary file web/hdabo/fixtures/datasheet_10.yaml.bz2 has changed
Binary file web/hdabo/fixtures/datasheet_347.yaml.bz2 has changed
Binary file web/hdabo/fixtures/datasheet_all.yaml.bz2 has changed
--- a/web/hdabo/management/commands/querywikipedia.py	Fri Jun 17 02:09:37 2011 +0200
+++ b/web/hdabo/management/commands/querywikipedia.py	Fri Jun 17 14:17:49 2011 +0200
@@ -29,7 +29,6 @@
         tag.url_status = status
     if url is not None:
         tag.wikipedia_url = url
-        tag.wikipedia_activated = True
     if pageid is not None:
         tag.wikipedia_pageid = pageid
         
--- a/web/hdabo/models.py	Fri Jun 17 02:09:37 2011 +0200
+++ b/web/hdabo/models.py	Fri Jun 17 14:17:49 2011 +0200
@@ -67,6 +67,15 @@
 
     def __unicode__(self):
         return unicode(self.label)
+    
+class TagCategory(models.Model):
+    label = models.CharField(max_length=512, unique=True, blank=False, null=False)
+    
+    def __unicode__(self):
+        return unicode(self.label)
+    
+    class Meta:
+        verbose_name_plural = "TagCategories"
 
 class Tag(models.Model):
     TAG_URL_STATUS_CHOICES = (
@@ -86,11 +95,11 @@
     label = models.CharField(max_length=1024, unique=False, blank=False, null=False)
     original_label = models.CharField(max_length=1024, unique=True, blank=False, null=False, editable=False)
     alias = models.CharField(max_length=1024, unique=False, blank=True, null=True)
+    category = models.ForeignKey(TagCategory, null=True, blank=True)
     wikipedia_url = models.URLField(verify_exists=False, max_length=2048, blank=True, null=True)
     wikipedia_pageid = models.BigIntegerField(unique=False, blank=True, null=True)
     url_status = models.IntegerField(choices=TAG_URL_STATUS_CHOICES, blank=True, null=True, default=None)
     dbpedia_uri = models.URLField(verify_exists=False, max_length=2048, blank=True, null=True)
-    wikipedia_activated = models.BooleanField(default=False)
 
     @Property
     def url_status_text(): #@NoSelf
@@ -98,14 +107,7 @@
             return self.TAG_URL_STATUS_CHOICES[self.url_status][1]
         
         return locals() 
-    
-
-class TagCategory(models.Model):
-    label = models.CharField(max_length=512, unique=True, blank=False, null=False)
-    
-    def __unicode__(self):
-        return unicode(self.label)
-    
+        
 class Location(models.Model):
     name = models.CharField(max_length=512, unique=False, blank=False, null=False)
     insee = models.CharField(max_length=5, unique=True, blank=False, null=False)
@@ -271,8 +273,6 @@
     tag = models.ForeignKey(Tag)
     original_order = models.IntegerField(default=0)
     order = models.IntegerField(default=0)
-    index_note = models.FloatField(default=0.0)
-    categories = models.ManyToManyField(TagCategory)
+    index_note = models.FloatField(default=0.0)    
     
     
-    
--- a/web/hdabo/static/hdabo/js/hdabo.js	Fri Jun 17 02:09:37 2011 +0200
+++ b/web/hdabo/static/hdabo/js/hdabo.js	Fri Jun 17 14:17:49 2011 +0200
@@ -7,23 +7,6 @@
     });
     
     // Tag simple operations : activate/unactivate wp link, reset wp info, remove wp link, remove tag from list
-    $(".activate_wp_cb").click(function(e){
-        new_checked = $(this).is(':checked');
-        if(new_checked){
-            question = "Confirmez-vous l'activation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?";
-        } else {
-            question = "Confirmez-vous la désactivation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?";
-        }
-        if(confirm(question)){
-            //validate_wp_link(this);
-            update_tag(this);
-        }
-        else{
-            // Since the click event is dispatched after the checked changed, we change the checked changed if confirm is false.
-            e.preventDefault(); // unvalidates user's click
-            $(this).attr('checked', !new_checked);
-        }
-    });
     $(".reset_wp_info").click(function(e){
         if(confirm("Confirmez-vous le rétablissement du label original de ce tag ?")){
             update_tag(this);
@@ -196,11 +179,6 @@
         var url = remove_wp_link_url;
         var id_tag = $(btn).attr('id');
     }
-    else if ($(btn).is(".activate_wp_cb")) {
-        var url = validate_wp_link_url;
-        var id_tag = $(btn).attr('id');
-        new_checked = $(btn).is(':checked');
-    }
     
     // 2 cases : 
     // - ordered tag for one datasheet : $('#datasheet_id') is not null
@@ -272,6 +250,10 @@
             // And scroll to the bottom
             $("html").animate({ scrollTop: $(document).height() }, 500);
         },
+        error: function(jqXHR, textStatus, errorThrown) {
+			resp = $.parseJSON(jqXHR.responseText);
+			alert(resp.message);
+        },
         complete: function(){
             // We empty the input and hide the ok button
             $("#wp_search").val("");
--- a/web/hdabo/templates/all_tags.html	Fri Jun 17 02:09:37 2011 +0200
+++ b/web/hdabo/templates/all_tags.html	Fri Jun 17 14:17:49 2011 +0200
@@ -15,7 +15,6 @@
     var static_url = "{{STATIC_URL}}";
     var tag_up_down_url = "{% url hdabo.views.tag_up_down %}";
     var remove_tag_from_list_url = "{% url hdabo.views.remove_tag_from_list %}";
-    var validate_wp_link_url = "{% url hdabo.views.validate_wp_link %}";
     var modify_tag_url = "{% url hdabo.views.modify_tag %}";
     var reset_wp_info_url = "{% url hdabo.views.reset_wikipedia_info %}";
     var add_tag_url = "{% url hdabo.views.add_tag %}";
--- a/web/hdabo/templates/list_for_orga.html	Fri Jun 17 02:09:37 2011 +0200
+++ b/web/hdabo/templates/list_for_orga.html	Fri Jun 17 14:17:49 2011 +0200
@@ -16,7 +16,6 @@
     var static_url = "{{STATIC_URL}}";
     var tag_up_down_url = "{% url hdabo.views.tag_up_down %}";
     var remove_tag_from_list_url = "{% url hdabo.views.remove_tag_from_list %}";
-    var validate_wp_link_url = "{% url hdabo.views.validate_wp_link %}";
     var modify_tag_url = "{% url hdabo.views.modify_tag_datasheet %}";
     var reset_wp_info_url = "{% url hdabo.views.reset_wikipedia_info %}";
     var add_tag_url = "{% url hdabo.views.add_tag %}";
--- a/web/hdabo/templates/partial/all_tags_table.html	Fri Jun 17 02:09:37 2011 +0200
+++ b/web/hdabo/templates/partial/all_tags_table.html	Fri Jun 17 14:17:49 2011 +0200
@@ -5,7 +5,6 @@
         {% comment %}<th>original_label</th>{% endcomment %}
         <th class="text_centered">Lien W</th>
         <th>Facette</th>
-        <th class="large_25 text_centered">Lien W activé</th>
         <th class="large_25 text_centered">Supprimer<br/>le lien W</th>
         <th>Alias</th></tr>
     {% for tag in tags %}
@@ -27,7 +26,6 @@
             <option value="ecole">Ecole/Mouvement</option>
             <option value="discipline">Discipline artistique</option>
             </select></td>
-        <td class="text_centered"><input type="checkbox" class="activate_wp_cb" id="{{tag.id}}" alt="{{tag.label}}" {% if tag.wikipedia_activated %}checked{% endif %} /></td>
         <td class="text_centered"><img src="{{STATIC_URL}}hdabo/img/red_cross.png" class="remove_wp_link" id="{{tag.id}}" alt="{{tag.label}}" /></td>
         <td class="tag_alias" id="{{tag.id}}" >{% if tag.alias %}{{tag.alias}}{% endif %}</td></tr>
     {% endfor %}
--- a/web/hdabo/urls.py	Fri Jun 17 02:09:37 2011 +0200
+++ b/web/hdabo/urls.py	Fri Jun 17 14:17:49 2011 +0200
@@ -22,7 +22,6 @@
     url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/(?P<start_index>[\w-]+)/(?P<length>[\w-]+)/$', 'hdabo.views.list_for_orga', name='list_for_orga'),
     url(r'^tagupdown$', 'hdabo.views.tag_up_down'),
     url(r'^removetagfromlist$', 'hdabo.views.remove_tag_from_list'),
-    url(r'^validatewplink$', 'hdabo.views.validate_wp_link'),
     url(r'^modifytag$', 'hdabo.views.modify_tag'),
     url(r'^modifytagds$', 'hdabo.views.modify_tag_datasheet'),
     url(r'^resetwpinfo$', 'hdabo.views.reset_wikipedia_info'),
--- a/web/hdabo/views.py	Fri Jun 17 02:09:37 2011 +0200
+++ b/web/hdabo/views.py	Fri Jun 17 14:17:49 2011 +0200
@@ -206,27 +206,6 @@
 
 
 #@login_required
-def validate_wp_link(request=None):
-    # 2 cases : 
-    # - ordered tag for one datasheet : POST["datasheet_id"] is not null
-    # - all tags list : POST["datasheet_id"] is null and POST["num_page"] and POST["nb_by_page"] are not null
-    tag_id = request.POST["tag_id"]
-    if request.POST["activated"] != "false" :
-        wp_activ = True
-    else :
-        wp_activ = False
-    # First we get the tag object
-    tag = Tag.objects.filter(id=tag_id)[0]
-    tag.wikipedia_activated = wp_activ
-    tag.save()
-    
-    if u"datasheet_id" in request.POST :
-        return get_tag_table(request=request, ds_id=request.POST["datasheet_id"], valid=0)
-    else :
-        return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"])
-
-
-#@login_required
 def modify_tag(request):
 
     tag_id = request.POST["id"]
@@ -245,10 +224,8 @@
             tag.url_status = status
         if url is not None:
             tag.wikipedia_url = url
-            tag.wikipedia_activated = True
         else:
             tag.wikipedia_url = None
-            tag.wikipedia_activated = False
             
         if pageid is not None:
             tag.wikipedia_pageid = pageid
@@ -307,7 +284,6 @@
     #reset tag info
     tag.wikipedia_url = None
     tag.wikipedia_pageid = None
-    tag.wikipedia_activated = False
     
     process_tag(site, tag, 0)
     
@@ -322,11 +298,16 @@
     
     ds_id = request.POST["datasheet_id"]
     tag_label = request.POST["value"]
+    
+    ds = Datasheet.objects.get(id=ds_id)
+    if tag_label.lower() in [t.label.lower() for t in ds.tags.all()]:
+        return  HttpResponseBadRequest(json.dumps({'error': 'duplicate_tag', 'message': u"Le tag %s existe déjà pour cette fiche." % (tag_label)}), mimetype="application/json")
+
 
     tag, created = get_or_create_tag(tag_label)    
     # We put the tag at the bottom of the datasheet's tag list 
     # if the tag is created or if the tag is not in the list
-    ds = Datasheet.objects.get(id=ds_id)
+    
     list_ts = TaggedSheet.objects.filter(datasheet=ds)
     if created or len(list_ts.filter(tag=tag))==0 :
         new_order = list_ts.aggregate(Max('order'))['order__max'] + 1
@@ -343,7 +324,6 @@
     # - all tags list : POST["datasheet_id"] is null and POST["num_page"] and POST["nb_by_page"] are not null
     tag_id = request.POST["tag_id"]
     tag = Tag.objects.filter(id=tag_id)[0]
-    tag.wikipedia_activated = False
     tag.wikipedia_url = None
     tag.wikipedia_pageid = None
     tag.url_status = 0;
--- a/web/hdabo/wp_utils.py	Fri Jun 17 02:09:37 2011 +0200
+++ b/web/hdabo/wp_utils.py	Fri Jun 17 14:17:49 2011 +0200
@@ -69,10 +69,8 @@
             tag.url_status = status
         if url is not None:
             tag.wikipedia_url = url
-            tag.wikipedia_activated = True
         else:
             tag.wikipedia_url = None
-            tag.wikipedia_activated = False
             
         if pageid is not None:
             tag.wikipedia_pageid = pageid