fix for postgres master
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 28 Jan 2025 12:53:20 +0000 (13:53 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 28 Jan 2025 12:53:20 +0000 (13:53 +0100)
src/catalogue/wikidata.py
src/documents/models/chunk.py
src/documents/xml_tools.py
src/redakcja/static/css/html.scss
src/redakcja/static/js/wiki/view_editor_wysiwyg.js
src/redakcja/static/js/wiki/wikiapi.js
src/wiki/templates/wiki/tabs/annotations_view.html
src/wlxml/templates/wlxml/wl2html.xsl

index 84f899a..731e55f 100644 (file)
@@ -164,9 +164,10 @@ class WikidataModel(models.Model):
                 except:
                     pass
                 else:
                 except:
                     pass
                 else:
-                    max_length = getattr(model_field, 'max_length', None)
-                    if max_length:
-                        wdvalue = wdvalue[:max_length]
+                    if isinstance(wdvalue, str):
+                        max_length = getattr(model_field, 'max_length', None)
+                        if max_length:
+                            wdvalue = wdvalue[:max_length]
                     setattr(self, attname, wdvalue)
 
     def wikidata_link(self):
                     setattr(self, attname, wdvalue)
 
     def wikidata_link(self):
index 4d8f6d2..797fc17 100644 (file)
@@ -75,8 +75,10 @@ class Chunk(dvcs_models.Document):
 
     def split(self, slug, title='', **kwargs):
         """ Create an empty chunk after this one """
 
     def split(self, slug, title='', **kwargs):
         """ Create an empty chunk after this one """
-        self.book.chunk_set.filter(number__gt=self.number).update(
-                number=models.F('number')+1)
+        # Single update makes unique constr choke on postgres.
+        for chunk in self.book.chunk_set.filter(number__gt=self.number).order_by('-number'):
+            chunk.number += 1
+            chunk.save()
         new_chunk = None
         while not new_chunk:
             new_slug = self.book.make_chunk_slug(slug)
         new_chunk = None
         while not new_chunk:
             new_slug = self.book.make_chunk_slug(slug)
index ac145db..d7e3fcf 100644 (file)
@@ -107,7 +107,7 @@ def split_xml(text):
 
         # find the chapter's title
         name_elem = deepcopy(element)
 
         # find the chapter's title
         name_elem = deepcopy(element)
-        for tag in 'extra', 'motyw', 'pa', 'pe', 'pr', 'pt', 'uwaga':
+        for tag in 'extra', 'motyw', 'pa', 'pe', 'pr', 'pt', 'ptrad', 'uwaga':
             for a in name_elem.findall('.//' + tag):
                 a.text=''
                 del a[:]
             for a in name_elem.findall('.//' + tag):
                 a.text=''
                 del a[:]
index d9886d4..3819c82 100644 (file)
@@ -300,12 +300,19 @@ div[x-node] > .uwaga {
  * Przypisy w tekście
  */
  
  * Przypisy w tekście
  */
  
-.htmlview .annotation-inline-box {
-    &:hover > span[x-annotation-box] {
-        display: block;
+.htmlview .annotation-inline-box,
+.htmlview .reference-inline-box {
+    &:hover {
+       > span[x-annotation-box],
+       > span[x-preview]
+       {
+            display: block;
+       }
     }
 
     }
 
-    > span[x-annotation-box] {
+    > span[x-annotation-box],
+    > span[x-preview]
+    {
         display: none;
         width: 300px;
         font-size: 10pt;
         display: none;
         width: 300px;
         font-size: 10pt;
@@ -549,3 +556,27 @@ div[x-node] > .uwaga {
         }
     }
 }
         }
     }
 }
+
+
+
+div[x-node="numeracja"] {
+    background: lightblue;
+    margin: 2em;
+    padding: 2em;
+    border-radius: 1em;
+    &::before {
+       content: "Reset numeracji";
+    }
+}
+
+*[x-number]::before {
+    display: block;
+    content: attr(x-number);
+    position: absolute;
+    text-align: right;
+    width: 40px;
+    left: -60px;
+    font-size: .9em;
+    opacity: .8;
+    
+}
index e43905c..2e1c28d 100644 (file)
@@ -56,7 +56,7 @@
     }
 
     /* Convert HTML fragment to plaintext */
     }
 
     /* Convert HTML fragment to plaintext */
-    var ANNOT_FORBIDDEN = ['pt', 'pa', 'pr', 'pe', 'begin', 'end', 'motyw'];
+    var ANNOT_FORBIDDEN = ['pt', 'pa', 'pr', 'pe', 'ptrad', 'begin', 'end', 'motyw'];
 
     function html2plainText(fragment){
         var text = "";
 
     function html2plainText(fragment){
         var text = "";
             element: source,
             stripOuter: true,
             success: function(text){
             element: source,
             stripOuter: true,
             success: function(text){
-                $('textarea', $overlay).val($.trim(text));
+               let ttext = $.trim(text);
+                $('textarea', $overlay).val(ttext);
 
                 setTimeout(function(){
                     $('textarea', $overlay).elastic().focus();
 
                 setTimeout(function(){
                     $('textarea', $overlay).elastic().focus();
                         $('*[x-annotation-box]', editable).css({
                         }).show();
                     }
                         $('*[x-annotation-box]', editable).css({
                         }).show();
                     }
+                    if (editable.is('.reference-inline-box')) {
+                       let preview = $('*[x-preview]', editable);
+                       preview.show();
+                       let link = $("a", preview);
+                       let href = link.attr('href');
+                       if (link.attr('title') == '?' && href.startsWith('https://www.wikidata.org/wiki/')) {
+                           link.attr('title', '…');
+                           let qid = href.split('/').reverse()[0];
+                           $.ajax({
+                               url: 'https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/' + qid + '?_fields=labels',
+                               dataType: "json",
+                               success: function(data) {
+                                   link.attr(
+                                       'title',
+                                       data['labels']['pl'] || data['labels']['en']
+                                   );
+                               },
+                           });
+                       }
+                    }
                 });
 
                 self.caret = new Caret(element);
                 });
 
                 self.caret = new Caret(element);
                     callback();
             }
 
                     callback();
             }
 
+           let self = this;
             xml2html({
                 xml: this.doc.text,
                 base: this.doc.getBase(),
             xml2html({
                 xml: this.doc.text,
                 base: this.doc.getBase(),
 
                     var htmlView = $('#html-view');
                     htmlView.html(element);
 
                     var htmlView = $('#html-view');
                     htmlView.html(element);
+                   self.renumber();
                     if ('PropertiesPerspective' in $.wiki.perspectives)
                         $.wiki.perspectives.PropertiesPerspective.enable();
 
                     if ('PropertiesPerspective' in $.wiki.perspectives)
                         $.wiki.perspectives.PropertiesPerspective.enable();
 
                 }
             })
         }
                 }
             })
         }
+
+       renumber() {
+           let number = 0;
+            $('#html-view *').each((i, e) => {
+               let $e = $(e);
+               if ($e.closest('[x-node="abstrakt"]').length) return;
+               if ($e.closest('[x-node="nota_red"]').length) return;
+               let node = $e.attr('x-node');
+               if (node == 'numeracja') {
+                   number = 0;
+               } else if (['werset', 'akap', 'wers'].includes(node)) {
+                   number ++;
+                   $e.attr('x-number', number);
+               }
+           })
+       }
     }
 
     $.wiki.VisualPerspective = VisualPerspective;
     }
 
     $.wiki.VisualPerspective = VisualPerspective;
index 73642ac..5675913 100644 (file)
             $.xmlns["rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
             $('rdf|RDF', doc).remove();
             if (params.noFootnotes) {
             $.xmlns["rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
             $('rdf|RDF', doc).remove();
             if (params.noFootnotes) {
-                $('pa, pe, pr, pt', doc).remove();
+                $('pa, pe, pr, pt, ptrad', doc).remove();
             }
            if (params.noThemes) {
                $('motyw', doc).remove();
             }
            if (params.noThemes) {
                $('motyw', doc).remove();
index 6cfef19..1c6bcc0 100644 (file)
         <a href='#' class="nav-link refresh" title="Przypisy tłumacza" data-tag="pt">pt</a>
       </li>
       <li class="nav-item">
         <a href='#' class="nav-link refresh" title="Przypisy tłumacza" data-tag="pt">pt</a>
       </li>
       <li class="nav-item">
-        <a href='#' class="nav-link refresh" title="Wszystkie przypisy" data-tag="pa,pe,pr,pt">{% trans "all" %}</a>
+        <a href='#' class="nav-link refresh" title="Przypisy tradycyjne" data-tag="ptrad">ptrad</a>
+      </li>
+      <li class="nav-item">
+        <a href='#' class="nav-link refresh" title="Wszystkie przypisy" data-tag="pa,pe,pr,pt,ptrad">{% trans "all" %}</a>
       </li>
     </ul>
     <div id="annotations-container">
       </li>
     </ul>
     <div id="annotations-container">
index c3af0ff..9716e19 100644 (file)
       </div>
     </xsl:template>
 
       </div>
     </xsl:template>
 
+    <xsl:template match="numeracja">
+      <div>
+        <xsl:call-template name="standard-attributes" />
+        <div>
+          <xsl:attribute name="data-start">
+            <xsl:value-of select="@start" />
+          </xsl:attribute>
+          <xsl:attribute name="data-link">
+            <xsl:value-of select="@link" />
+          </xsl:attribute>
+        </div>
+      </div>
+    </xsl:template>
+
     <!--
         ********
         STROFA
     <!--
         ********
         STROFA
           <xsl:with-param name="extra-class" select="'reference-inline-box'" />
         </xsl:call-template>
         <a class="reference">📌</a>
           <xsl:with-param name="extra-class" select="'reference-inline-box'" />
         </xsl:call-template>
         <a class="reference">📌</a>
+        <span x-preview="true" x-pass-thru="true">
+         <a target="wiki" title="?">
+           <xsl:attribute name="href">
+             <xsl:value-of select="@href" />
+           </xsl:attribute>
+           <xsl:value-of select="@href" />
+         </a>
+        </span>
       </span>
     </xsl:template>
     
       </span>
     </xsl:template>