summaryrefslogtreecommitdiffstats
path: root/doc-publik/update-publik-doc-from-redmine.py
blob: 53c68bbe9132295f938f685124f1520d9f064f5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-

from bs4 import BeautifulSoup
import html5lib
import requests

from combo.data.models import TextCell

DOCS = {
    'passerelle-connecteur-dev': "https://dev.entrouvert.org/projects/passerelle/wiki/D%C3%A9veloppement_d'un_connecteur.html",
    'passerelle-json-data-store': "https://dev.entrouvert.org/projects/passerelle/wiki/Stockage_de_donn%C3%A9es_JSON.html",
    'combo-json-cell': "https://dev.entrouvert.org/projects/combo/wiki/D%C3%A9veloppement_d'une_cellule_aliment%C3%A9e_par_JSON.html",
    'developer-installation': "https://dev.entrouvert.org/projects/publik-devinst/wiki/Installation_d'un_environnement_de_développement_local.html",
    'redmine-contribuer-a-publik': "https://dev.entrouvert.org/projects/publik/wiki/Contribuer_%C3%A0_Publik.html",
}

for cell in TextCell.objects.filter(slug__in=DOCS.keys(), page__snapshot__isnull=True):
    resp = requests.get(DOCS[cell.slug])
    if resp.status_code != 200:
        continue
    document = BeautifulSoup(resp.content, 'html5lib')
    content = document.find('body')
    new_content = content.decode().replace('<body>', '').replace('</body>', '')
    cell.text = new_content
    cell.order = 1
    cell.save()

    url = DOCS[cell.slug].replace('.html', '')
    cell, created = TextCell.objects.get_or_create(
            page=cell.page,
            slug='editor-warning', defaults={'order': 0})
    cell.placeholder = 'content'
    cell.order = 0
    cell.text = u'''<div class="note note-tip"><div>Cette page est tirée de redmine, l'édition se fait là :<br>
                       <a href="%s">%s</a>.</div></div>''' % (url, url)
    cell.public = False
    cell.save()