# HG changeset patch # User gibus # Date 1344607949 -7200 # Node ID 2fdb7d095d5c6eb668c8cbabcf64a90ae8afb7c9 # Parent a69421197502ac53abb6d94ced05c1450ac07d64 Added import from XML file, including text, comments and attachments. diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/bg/LC_MESSAGES/django.mo Binary file src/cm/locale/bg/LC_MESSAGES/django.mo has changed diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/bg/LC_MESSAGES/django.po --- a/src/cm/locale/bg/LC_MESSAGES/django.po Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/locale/bg/LC_MESSAGES/django.po Fri Aug 10 16:12:29 2012 +0200 @@ -152,6 +152,10 @@ msgid "Text %(link_to_text)s added by %(creator)s" msgstr "Текстът %(link_to_text)s е добавен" +#: models.py:763 +msgid "Text %(link_to_text)s imported by %(creator)s" +msgstr "Текст %(link_to_text)s внесени от %(creator)s" + #: models.py:759 #, python-format msgid "Text %(link_to_text)s removed" @@ -439,6 +443,20 @@ msgstr "" #: templates/site/dashboard.html:50 +#: templates/site/text_create_import.html:4 +#: templates/site/text_create_import.html:30 +#: templates/site/text_create_content.html:32 +#: templates/site/text_create_upload.html:30 +#: templates/site/text_list.html:44 +#: templates/site/layout/header.html:12 +msgid "Import a co-mented text" +msgstr "Импортиране cо-ментира текст" + +#: templates/site/dashboard.html:50 +msgid "Import a text, possibly with comments and attachments, which has been previously exported in XML format from co-ment interface" +msgstr "Импортиране на текст, с възможност за коментари и прикачени файлове, който е бил преди, изнесени във формат XML от co-ment" + +#: templates/site/dashboard.html:50 msgid "Invite user" msgstr "Покани потребител" @@ -1651,6 +1669,26 @@ msgid "You should specify a file to upload." msgstr "Необходимо е да изберете файл за качване." +#: views/create.py:49 +msgid "Upload XML file" +msgstr "Качване на XML файл" + +#: views/create.py:50 +msgid "Upload a previously exported XML file from your computer" +msgstr "Качи изнесеното преди XML файл от вашия компютър" + +#: views/create.py:65 +msgid "The imported file should be an XML file generated by co-ment when exporting a text and comments." +msgstr "Внесеното файла трябва да бъде един XML файл, генериран от co-ment, при износ на текст и коментари." + +#: views/create.py:71 +msgid "No co_ment_text node found in XML." +msgstr "Не co_ment_text_node възел в XML." + +#: views/create.py:76 +msgid "No %(tag)s node found in XML." +msgstr "Не %(tag)s възел в XML." + #: views/create.py:46 msgid "The title of your text" msgstr "Заглавие на вашия текст" @@ -1660,6 +1698,10 @@ msgid "Text \"%(text_title)s\" has been created" msgstr "Текстът \"%(text_title)s\" е създаден" +#: views/create.py:244 +msgid "Text \"%(text_title)s\" has been imported" +msgstr "Текстът \"%(text_title)s\" е внесено" + #: views/feeds.py:25 #, python-format msgid "%(workspace_name)s's public feed" diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/en/LC_MESSAGES/django.po --- a/src/cm/locale/en/LC_MESSAGES/django.po Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/locale/en/LC_MESSAGES/django.po Fri Aug 10 16:12:29 2012 +0200 @@ -150,6 +150,10 @@ msgid "Text %(link_to_text)s added by %(creator)s" msgstr "" +#: models.py:763 +msgid "Text %(link_to_text)s imported by %(creator)s" +msgstr "" + #: models.py:759 #, python-format msgid "Text %(link_to_text)s removed" @@ -432,6 +436,20 @@ msgstr "" #: templates/site/dashboard.html:50 +#: templates/site/text_create_import.html:4 +#: templates/site/text_create_import.html:30 +#: templates/site/text_create_content.html:32 +#: templates/site/text_create_upload.html:30 +#: templates/site/text_list.html:44 +#: templates/site/layout/header.html:12 +msgid "Import a co-mented text" +msgstr "" + +#: templates/site/dashboard.html:50 +msgid "Import a text, possibly with comments and attachments, which has been previously exported in XML format from co-ment interface" +msgstr "" + +#: templates/site/dashboard.html:50 msgid "Invite user" msgstr "" @@ -1594,6 +1612,26 @@ msgid "You should specify a file to upload." msgstr "" +#: views/create.py:49 +msgid "Upload XML file" +msgstr "" + +#: views/create.py:50 +msgid "Upload a previously exported XML file from your computer" +msgstr "" + +#: views/create.py:65 +msgid "The imported file should be an XML file generated by co-ment when exporting a text and comments." +msgstr "" + +#: views/create.py:71 +msgid "No co_ment_text node found in XML." +msgstr "" + +#: views/create.py:76 +msgid "No %(tag)s node found in XML." +msgstr "" + #: views/create.py:46 msgid "The title of your text" msgstr "" @@ -1603,6 +1641,10 @@ msgid "Text \"%(text_title)s\" has been created" msgstr "" +#: views/create.py:244 +msgid "Text \"%(text_title)s\" has been imported" +msgstr "" + #: views/feeds.py:25 #, python-format msgid "%(workspace_name)s's public feed" diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/es/LC_MESSAGES/django.mo Binary file src/cm/locale/es/LC_MESSAGES/django.mo has changed diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/es/LC_MESSAGES/django.po --- a/src/cm/locale/es/LC_MESSAGES/django.po Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/locale/es/LC_MESSAGES/django.po Fri Aug 10 16:12:29 2012 +0200 @@ -151,6 +151,10 @@ msgid "Text %(link_to_text)s added by %(creator)s" msgstr "Texto %(link_to_text)s añadido por %(creator)s" +#: models.py:763 +msgid "Text %(link_to_text)s imported by %(creator)s" +msgstr "El texto de %(link_to_text)s importado por %(creator)s" + #: models.py:759 #, python-format msgid "Text %(link_to_text)s removed" @@ -438,6 +442,20 @@ "format, Word doc.)" #: templates/site/dashboard.html:50 +#: templates/site/text_create_import.html:4 +#: templates/site/text_create_import.html:30 +#: templates/site/text_create_content.html:32 +#: templates/site/text_create_upload.html:30 +#: templates/site/text_list.html:44 +#: templates/site/layout/header.html:12 +msgid "Import a co-mented text" +msgstr "Importar un texto co-mentado" + +#: templates/site/dashboard.html:50 +msgid "Import a text, possibly with comments and attachments, which has been previously exported in XML format from co-ment interface" +msgstr "Importar un texto, posiblemente con comentarios y archivos adjuntos, lo que ha sido previamente exportadas en formato XML a partir de interfaz de co-ment" + +#: templates/site/dashboard.html:50 msgid "Invite user" msgstr "Invitar a un usuario" @@ -1737,6 +1755,26 @@ msgid "You should specify a file to upload." msgstr "Debería especificar un archivo que subir." +#: views/create.py:49 +msgid "Upload XML file" +msgstr "Subir archivo XML" + +#: views/create.py:50 +msgid "Upload a previously exported XML file from your computer" +msgstr "Subir un archivo XML exportado previamente desde el ordenador" + +#: views/create.py:65 +msgid "The imported file should be an XML file generated by co-ment when exporting a text and comments." +msgstr "El archivo importado debe ser un archivo XML generado por la co-ment cuando se exporta un texto y comentarios." + +#: views/create.py:71 +msgid "No co_ment_text node found in XML." +msgstr "Ningún nodo co_ment_text se encuentra en XML." + +#: views/create.py:76 +msgid "No %(tag)s node found in XML." +msgstr "Ningún nodo %(tag)s se encuentra en XML." + #: views/create.py:46 msgid "The title of your text" msgstr "El título de su texto" @@ -1746,6 +1784,10 @@ msgid "Text \"%(text_title)s\" has been created" msgstr "El texto \"%(text_title)s\" ha sido creado" +#: views/create.py:244 +msgid "Text \"%(text_title)s\" has been imported" +msgstr "El texto \"%(text_title)s\" ha sido importado" + #: views/feeds.py:25 #, python-format msgid "%(workspace_name)s's public feed" diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/fr/LC_MESSAGES/django.mo Binary file src/cm/locale/fr/LC_MESSAGES/django.mo has changed diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/fr/LC_MESSAGES/django.po --- a/src/cm/locale/fr/LC_MESSAGES/django.po Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/locale/fr/LC_MESSAGES/django.po Fri Aug 10 16:12:29 2012 +0200 @@ -157,6 +157,10 @@ msgid "Text %(link_to_text)s added by %(creator)s" msgstr "Le texte %(link_to_text)s a été ajouté par %(creator)s" +#: models.py:763 +msgid "Text %(link_to_text)s imported by %(creator)s" +msgstr "Le texte %(link_to_text)s a été importé par %(creator)s" + #: models.py:759 #, python-format msgid "Text %(link_to_text)s removed" @@ -445,6 +449,20 @@ "Open Format, document Word)" #: templates/site/dashboard.html:50 +#: templates/site/text_create_import.html:4 +#: templates/site/text_create_import.html:30 +#: templates/site/text_create_content.html:32 +#: templates/site/text_create_upload.html:30 +#: templates/site/text_list.html:44 +#: templates/site/layout/header.html:12 +msgid "Import a co-mented text" +msgstr "Importer un texte co-menté" + +#: templates/site/dashboard.html:50 +msgid "Import a text, possibly with comments and attachments, which has been previously exported in XML format from co-ment interface" +msgstr "Importer un texte, éventuellement avec des commentaires et des pièces jointes, ce qui a été préalablement exportés au format XML à partir de l'interface de co-ment" + +#: templates/site/dashboard.html:50 msgid "Invite user" msgstr "Inviter un utilisateur" @@ -1746,6 +1764,26 @@ msgid "You should specify a file to upload." msgstr "Vous devez fournir un fichier à charger sur le site." +#: views/create.py:49 +msgid "Upload XML file" +msgstr "Importer un fichier XML" + +#: views/create.py:50 +msgid "Upload a previously exported XML file from your computer" +msgstr "Télécharger un fichier précédemment exporté XML à partir de votre ordinateur" + +#: views/create.py:65 +msgid "The imported file should be an XML file generated by co-ment when exporting a text and comments." +msgstr "Le fichier importé doit être un fichier XML généré par co-ment lors de l'exportation d'un texte et des commentaires." + +#: views/create.py:71 +msgid "No co_ment_text node found in XML." +msgstr "Impossible de trouver un noeud co_ment_text dans le XML." + +#: views/create.py:76 +msgid "No %(tag)s node found in XML." +msgstr "Impossible de trouver un noeud %(tag)s dans le XML." + #: views/create.py:46 msgid "The title of your text" msgstr "Le titre de votre texte" @@ -1755,6 +1793,10 @@ msgid "Text \"%(text_title)s\" has been created" msgstr "Le texte \"%(text_title)s\" a été créé" +#: views/create.py:244 +msgid "Text \"%(text_title)s\" has been imported" +msgstr "Le texte \"%(text_title)s\" a été importé" + #: views/feeds.py:25 #, python-format msgid "%(workspace_name)s's public feed" diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/no/LC_MESSAGES/django.mo Binary file src/cm/locale/no/LC_MESSAGES/django.mo has changed diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/no/LC_MESSAGES/django.po --- a/src/cm/locale/no/LC_MESSAGES/django.po Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/locale/no/LC_MESSAGES/django.po Fri Aug 10 16:12:29 2012 +0200 @@ -153,6 +153,10 @@ msgid "Text %(link_to_text)s added by %(creator)s" msgstr "Tekst %(link_to_text)s lagt til av %(creator)s" +#: models.py:763 +msgid "Text %(link_to_text)s imported by %(creator)s" +msgstr "Tekst %(link_to_text)s importert av %(creator)s" + #: models.py:759 #, python-format msgid "Text %(link_to_text)s removed" @@ -440,6 +444,20 @@ "Microsoft Word)" #: templates/site/dashboard.html:50 +#: templates/site/text_create_import.html:4 +#: templates/site/text_create_import.html:30 +#: templates/site/text_create_content.html:32 +#: templates/site/text_create_upload.html:30 +#: templates/site/text_list.html:44 +#: templates/site/layout/header.html:12 +msgid "Import a co-mented text" +msgstr "Importere en co-mentert tekst" + +#: templates/site/dashboard.html:50 +msgid "Import a text, possibly with comments and attachments, which has been previously exported in XML format from co-ment interface" +msgstr "Importere en tekst, eventuelt med kommentarer og vedlegg, som tidligere har vært eksportert i XML-format fra co-ment grensesnitt" + +#: templates/site/dashboard.html:50 msgid "Invite user" msgstr "Inviter bruker" @@ -1626,6 +1644,26 @@ msgid "You should specify a file to upload." msgstr "Du må angi en fil til å laste opp" +#: views/create.py:49 +msgid "Upload XML file" +msgstr "Last opp XML-fil" + +#: views/create.py:50 +msgid "Upload a previously exported XML file from your computer" +msgstr "Last opp en tidligere eksportert XML-fil fra din datamaskin" + +#: views/create.py:65 +msgid "The imported file should be an XML file generated by co-ment when exporting a text and comments." +msgstr "Den importerte filen bør være en XML-fil generert av co-ment når du eksporterer en tekst og kommentarer." + +#: views/create.py:71 +msgid "No co_ment_text node found in XML." +msgstr "Ingen co_ment_text node funnet i XML." + +#: views/create.py:76 +msgid "No %(tag)s node found in XML." +msgstr "Ingen %(tag)s node funnet i XML." + #: views/create.py:46 msgid "The title of your text" msgstr "Overskriften for din tekst" @@ -1635,6 +1673,10 @@ msgid "Text \"%(text_title)s\" has been created" msgstr "Teksten %(text_title)s har blitt opprettet" +#: views/create.py:244 +msgid "Text \"%(text_title)s\" has been imported" +msgstr "Teksten %(text_title)s har blitt importert" + #: views/feeds.py:25 #, python-format msgid "%(workspace_name)s's public feed" diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/pt_BR/LC_MESSAGES/django.mo Binary file src/cm/locale/pt_BR/LC_MESSAGES/django.mo has changed diff -r a69421197502 -r 2fdb7d095d5c src/cm/locale/pt_BR/LC_MESSAGES/django.po --- a/src/cm/locale/pt_BR/LC_MESSAGES/django.po Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/locale/pt_BR/LC_MESSAGES/django.po Fri Aug 10 16:12:29 2012 +0200 @@ -147,6 +147,10 @@ msgid "Text %(link_to_text)s added by %(creator)s" msgstr "Texto %(link_to_text)s adicionado" +#: models.py:763 +msgid "Text %(link_to_text)s imported by %(creator)s" +msgstr "Texto %(link_to_text)s importados por %(creator)s" + #: models.py:759 #, python-format msgid "Text %(link_to_text)s removed" @@ -424,6 +428,20 @@ msgid "Upload a text" msgstr "Carregar um texto" +#: templates/site/dashboard.html:50 +#: templates/site/text_create_import.html:4 +#: templates/site/text_create_import.html:30 +#: templates/site/text_create_content.html:32 +#: templates/site/text_create_upload.html:30 +#: templates/site/text_list.html:44 +#: templates/site/layout/header.html:12 +msgid "Import a co-mented text" +msgstr "Importar um texto co-mentado" + +#: templates/site/dashboard.html:50 +msgid "Import a text, possibly with comments and attachments, which has been previously exported in XML format from co-ment interface" +msgstr "Importar um texto, possivelmente com comentários e anexos, que tenha sido previamente exportados em formato XML a partir da interface de co-ment" + #: templates/site/dashboard.html:49 msgid "" "Upload a document from your computer (Text document, Open Format document, " @@ -1641,6 +1659,26 @@ msgid "You should specify a file to upload." msgstr "Favor especificar o arquivo a ser carregado." +#: views/create.py:49 +msgid "Upload XML file" +msgstr "Carregar de arquivo XML" + +#: views/create.py:50 +msgid "Upload a previously exported XML file from your computer" +msgstr "Carregar um arquivo XML exportado anteriormente de seu computador" + +#: views/create.py:65 +msgid "The imported file should be an XML file generated by co-ment when exporting a text and comments." +msgstr "O arquivo importado deve ser um arquivo XML gerado pelo co-ment ao exportar um texto e comentários." + +#: views/create.py:71 +msgid "No co_ment_text node found in XML." +msgstr "Nenhum nó co_ment_text encontrada no XML." + +#: views/create.py:76 +msgid "No %(tag)s node found in XML." +msgstr "Nenhum nó %(tag)s encontrada no XML." + #: views/create.py:46 msgid "The title of your text" msgstr "O título do seu texto" @@ -1650,6 +1688,10 @@ msgid "Text \"%(text_title)s\" has been created" msgstr "O texto \"%(text_title)s\" foi criado" +#: views/create.py:244 +msgid "Text \"%(text_title)s\" has been imported" +msgstr "O texto \"%(text_title)s\" foi importado" + #: views/feeds.py:25 #, python-format msgid "%(workspace_name)s's public feed" diff -r a69421197502 -r 2fdb7d095d5c src/cm/media/img/sop_import.png Binary file src/cm/media/img/sop_import.png has changed diff -r a69421197502 -r 2fdb7d095d5c src/cm/media/img/sop_import_small.png Binary file src/cm/media/img/sop_import_small.png has changed diff -r a69421197502 -r 2fdb7d095d5c src/cm/models.py --- a/src/cm/models.py Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/models.py Fri Aug 10 16:12:29 2012 +0200 @@ -735,12 +735,13 @@ VIEWABLE_ACTIVITIES = { 'view_comments' : ['comment_created', 'comment_removed'], 'view_users' : ['user_created', 'user_activated', 'user_refused', 'user_enabled', 'user_approved', 'user_suspended'], - 'view_texts' : ['text_created', 'text_removed', 'text_edited', 'text_edited_new_version'], + 'view_texts' : ['text_created', 'text_imported', 'text_removed', 'text_edited', 'text_edited_new_version'], } ACTIVITIES_TYPES = reduce(list.__add__, VIEWABLE_ACTIVITIES.values()) IMGS = { 'text_created' : u'page_add_small.png', + 'text_imported' : u'sop_import_small.png', 'text_removed' : u'page_delete_small.png', 'text_edited' : u'page_save_small.png', 'text_edited_new_version' : u'page_save_small.png', @@ -759,6 +760,7 @@ 'text_edited' : ugettext_lazy(u'Text %(link_to_text)s edited by %(creator)s'), 'text_edited_new_version' : ugettext_lazy(u'Text %(link_to_text)s edited (new version created) by %(creator)s'), 'text_created' : ugettext_lazy(u'Text %(link_to_text)s added by %(creator)s'), + 'text_imported' : ugettext_lazy(u'Text %(link_to_text)s imported by %(creator)s'), 'text_removed' : ugettext_lazy(u'Text %(link_to_text)s removed'), 'comment_created' : ugettext_lazy(u'Comment %(link_to_comment)s added on text %(link_to_text)s by %(creator)s'), 'comment_removed' : ugettext_lazy(u'Comment %(link_to_comment)s removed from text %(link_to_text)s'), diff -r a69421197502 -r 2fdb7d095d5c src/cm/templates/site/dashboard.html --- a/src/cm/templates/site/dashboard.html Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/templates/site/dashboard.html Fri Aug 10 16:12:29 2012 +0200 @@ -47,6 +47,7 @@ {% if can_create_text %}
 {% blocktrans %}Create a text{% endblocktrans %} 
{% endif %} {% if can_create_text %}
 {% blocktrans %}Upload a text{% endblocktrans %} 
{% endif %} + {% if can_create_text %}
 {% blocktrans %}Import a co-mented text{% endblocktrans %} 
{% endif %} {% if can_manage_workspace %}
 {% blocktrans %}Invite user{% endblocktrans %}
{% endif %}
 {% blocktrans %}Edit your profile{% endblocktrans %}
 {% blocktrans %}View text list{% endblocktrans %}
@@ -322,4 +323,4 @@
-{% endblock %} \ No newline at end of file +{% endblock %} diff -r a69421197502 -r 2fdb7d095d5c src/cm/templates/site/export.xml --- a/src/cm/templates/site/export.xml Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/templates/site/export.xml Fri Aug 10 16:12:29 2012 +0200 @@ -3,7 +3,8 @@ {{ title }} - {{ date|date:"c" }}+{{ tz|leading_zeros:"2" }} + {{ created|date:"c" }}+{{ tz|leading_zeros:"2" }} + {{ modified|date:"c" }}+{{ tz|leading_zeros:"2" }} {{ name }} {{ email }} {{ format }} @@ -20,11 +21,15 @@ {{ c.reply_to_id }} {% endif %} {{ c.title }} - {{ c.modified|date:"c" }}+{{ tz|leading_zeros:"2" }} + {{ c.state }} + {{ c.deleted }} + {{ c.created|date:"c" }}+{{ tz|leading_zeros:"2" }} + {{ c.modified|date:"c" }}+{{ tz|leading_zeros:"2" }} {{ c.name }} {{ c.email }} {{ c.format }} - {{ c.content }} + + {% if c.tags %} {{ c.tags }} {% endif %} diff -r a69421197502 -r 2fdb7d095d5c src/cm/templates/site/layout/header.html --- a/src/cm/templates/site/layout/header.html Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/templates/site/layout/header.html Fri Aug 10 16:12:29 2012 +0200 @@ -9,6 +9,7 @@ {% if can_create_text %} · {% blocktrans %}Create a text{% endblocktrans %} · {% blocktrans %}Upload a text{% endblocktrans %} + · {% blocktrans %}Import a co-mented text{% endblocktrans %} {% endif %} {% if user.is_authenticated %} · {% blocktrans %}Profile{% endblocktrans %} @@ -17,4 +18,4 @@ · {% blocktrans %}Login{% endblocktrans %} {% if CONF.workspace_registration %} · {% blocktrans %}Register{% endblocktrans %}{% endif %} {% endif %} - \ No newline at end of file + diff -r a69421197502 -r 2fdb7d095d5c src/cm/templates/site/text_create_content.html --- a/src/cm/templates/site/text_create_content.html Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/templates/site/text_create_content.html Fri Aug 10 16:12:29 2012 +0200 @@ -28,6 +28,8 @@
  • {% blocktrans %}Create a text{% endblocktrans %}
  • /
  • {% blocktrans %}Upload a text{% endblocktrans %}
  • +
  • /
  • +
  • {% blocktrans %}Import a co-mented text{% endblocktrans %}
  • diff -r a69421197502 -r 2fdb7d095d5c src/cm/templates/site/text_create_import.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cm/templates/site/text_create_import.html Fri Aug 10 16:12:29 2012 +0200 @@ -0,0 +1,62 @@ +{% extends "site/layout/base_workspace.html" %} +{% load i18n %} + +{% block title %}{% blocktrans %}Import a co-mented text{% endblocktrans %}{% endblock %} + +{% block main %} + + + + +
    + + + +
    + + + {% with 'import_content' as form_type %} + {% include "site/macros/form_fields.html" %} + {% endwith %} + + + + + +
    + + + +   + + + +
    +
    +{% endblock %} diff -r a69421197502 -r 2fdb7d095d5c src/cm/templates/site/text_create_upload.html --- a/src/cm/templates/site/text_create_upload.html Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/templates/site/text_create_upload.html Fri Aug 10 16:12:29 2012 +0200 @@ -26,6 +26,8 @@
  • {% blocktrans %}Create a text{% endblocktrans %}
  • /
  • {% blocktrans %}Upload a text{% endblocktrans %}
  • +
  • /
  • +
  • {% blocktrans %}Import a co-mented text{% endblocktrans %}
  • diff -r a69421197502 -r 2fdb7d095d5c src/cm/templates/site/text_list.html --- a/src/cm/templates/site/text_list.html Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/templates/site/text_list.html Fri Aug 10 16:12:29 2012 +0200 @@ -40,6 +40,8 @@
  • {% blocktrans %}Create a text{% endblocktrans %}
  • /
  • {% blocktrans %}Upload a text{% endblocktrans %}
  • +
  • /
  • +
  • {% blocktrans %}Import a co-mented text{% endblocktrans %}
  • {% endif %} diff -r a69421197502 -r 2fdb7d095d5c src/cm/urls.py --- a/src/cm/urls.py Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/urls.py Fri Aug 10 16:12:29 2012 +0200 @@ -52,16 +52,14 @@ url(r'^text/(?P\w*)/share/$', text_share, name="text-share"), # text create + url(r'^create/content/$', text_create_content, name="text-create-content"), url(r'^create/upload/$', text_create_upload, name="text-create-upload"), - url(r'^create/content/$', text_create_content, name="text-create-content"), - + url(r'^create/import/$', text_create_import, name="text-create-import"), # text url(r'^text/(?P\w*)/view/$', text_view, name="text-view"), url(r'^text/(?P\w*)/view/\?comment_id_key=(?P\w*)$', text_view, name="text-view-show-comment"), -# url(r'^text/(?P\w*)/view/(?P\w*)/$', text_view, name="text-view-version"), - url(r'^text/(?P\w*)/edit/$', text_edit, name="text-edit"), url(r'^text/(?P\w*)/pre_edit/$', text_pre_edit, name="text-preedit"), url(r'^text/(?P\w*)/settings/$', text_settings, name="text-settings"), @@ -75,8 +73,6 @@ url(r'^text/(?P\w*)/(?P\w*)/delete/$', text_version_delete, name="text-version-delete"), url(r'^text/(?P\w*)/export/(?P\w*)/(?P\w*)/(?P\w*)/(?P\w*)/$', text_export, name="text-export"), url(r'^text/(?P\w*)/history/$', text_history, name="text-history"), - #url(r'^text/(?P\w*)/diff/(?P\w*)/(?P\w*)/$', text_diff, name="text-diff"), -# url(r'^text/(?P\w*)/version/(?P\w*)/$', text_version, name="text-version"), # detached attachements! (used for saving images when just converting to HTML, without creating a text) url(r'^attach/(?P\w*)/$', notext_attach, name="notext-attach"), diff -r a69421197502 -r 2fdb7d095d5c src/cm/views/create.py --- a/src/cm/views/create.py Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/views/create.py Fri Aug 10 16:12:29 2012 +0200 @@ -1,7 +1,7 @@ from cm.cm_settings import VALID_EMAIL_FOR_PUBLISH, SITE_NAME from cm.converters import convert_from_mimetype from cm.converters.pandoc_converters import pandoc_convert -from cm.models import Text, TextVersion, Attachment +from cm.models import Text, TextVersion, Comment, Attachment from cm.utils.files import remove_extension from cm.utils.mail import EmailMessage from cm.views import get_text_by_keys_or_404 @@ -16,10 +16,14 @@ from django.template import RequestContext from django.template.loader import render_to_string from django.utils.translation import ugettext as _, ugettext_lazy +from django.db import connection, transaction from mimetypes import guess_type from cm.activity import register_activity from cm.security import has_global_perm import os +from BeautifulSoup import BeautifulStoneSoup +import re +from base64 import b64decode class CreateTextUploadForm(ModelForm): file = forms.FileField(required=False, @@ -40,6 +44,41 @@ return cleaned_data +class CreateTextImportForm(ModelForm): + file = forms.FileField(required=True, + label=ugettext_lazy("Upload XML file"), + help_text=ugettext_lazy("Upload a previously exported XML file from your computer"),) + + class Meta: + model = TextVersion + fields = () + + def clean(self): + cleaned_data = self.cleaned_data + if not cleaned_data.get('file', None) : + msg = _("You should specify a file to upload.") + self._errors["file"] = ErrorList([msg]) + return cleaned_data + + uploaded_file = self.cleaned_data['file'] + if (uploaded_file.content_type != 'text/xml'): + msg = _("The imported file should be an XML file generated by co-ment when exporting a text and comments.") + self._errors["file"] = ErrorList([msg]) + return cleaned_data + + soup = BeautifulStoneSoup(uploaded_file) + if not soup.co_ment_text: + msg = _("No co_ment_text node found in XML.") + self._errors["file"] = ErrorList([msg]) + return cleaned_data + for mandatory_child in ['title', 'created', 'modified', 'name', 'email', 'format', 'content']: + if not getattr(soup.co_ment_text, mandatory_child): + msg = _('No %(tag)s node found in XML.' %{"tag":mandatory_child}) + self._errors["file"] = ErrorList([msg]) + return cleaned_data + cleaned_data['soup'] = soup + return cleaned_data + class CreateTextContentForm(ModelForm): title = forms.CharField(required=True, label=ugettext_lazy("Title"), @@ -59,7 +98,6 @@ return HttpResponseRedirect(reverse('text-view', args=[text.key])) def _text_create_content(request, createForm): -# CreateForm = CreateTextContentForm document = "" if request.method == 'POST': @@ -77,8 +115,6 @@ def _text_create_upload(request, createForm): -# CreateForm = CreateTextUploadForm if request.user.is_authenticated() else CreateTextUploadFormAnon - if request.method == 'POST': form = createForm(request.POST, request.FILES) if form.is_valid(): @@ -113,11 +149,115 @@ return None, render_to_response('site/text_create_upload.html', {'form' : form}, context_instance=RequestContext(request)) +def _text_create_import(request, createForm): + if request.method == 'POST': + form = createForm(request.POST, request.FILES) + if form.is_valid(): + soup = form.cleaned_data['soup'] + if not soup.co_ment_text: + raise Exception('Bad Soup') + + # Process attachments first to create new keys. + attachments_keys_map = {} + if soup.co_ment_text.attachments: + for imported_attachement in soup.co_ment_text.attachments.findAll('attachment'): + # Creates attachment object. + filename = 'imported_attachment' + attachment = Attachment.objects.create_attachment(filename=filename, data=b64decode(imported_attachement.data.renderContents()), text_version=None) + # Stores key mapping. + attachments_keys_map[imported_attachement.key.renderContents()] = attachment.key + + # Process text. + form.cleaned_data['title'] = soup.co_ment_text.title.renderContents() + form.cleaned_data['format'] = soup.co_ment_text.format.renderContents() + form.cleaned_data['content'] = re.sub(r'^$', '', soup.co_ment_text.content.renderContents()) + form.cleaned_data['name'] = soup.co_ment_text.find('name').renderContents() + form.cleaned_data['email'] = soup.co_ment_text.email.renderContents() + if soup.co_ment_text.tags: + form.cleaned_data['tags'] = soup.co_ment_text.tags.renderContents() + + # Replaces attachements keys in content. + for old_key in attachments_keys_map.keys(): + form.cleaned_data['content'] = re.sub(old_key, attachments_keys_map[old_key], form.cleaned_data['content']) + + # Creates text. + text = create_text(request.user, form.cleaned_data) + + # Brute updates of dates (cannot do it through django models since fields are set with auto_now or auto_now_add). + created = soup.co_ment_text.created.renderContents() + modified = soup.co_ment_text.modified.renderContents() + cursor = connection.cursor() + cursor.execute("UPDATE cm_textversion SET created = %s, modified = %s WHERE id = %s", [created, modified, text.last_text_version_id]) + cursor.execute("UPDATE cm_text SET created = %s, modified = %s WHERE id = %s", [created, modified, text.id]) + transaction.commit_unless_managed() + + # Process comments. + if soup.co_ment_text.comments: + comments_ids_map = {} + for imported_comment in soup.co_ment_text.comments.findAll('comment'): + # Creates each comment. + comment = Comment.objects.create( + text_version=text.get_latest_version(), + title=imported_comment.title.renderContents(), + state=imported_comment.state.renderContents(), + name=imported_comment.find('name').renderContents(), + email=imported_comment.email.renderContents(), + format=imported_comment.format.renderContents(), + content=re.sub(r'^$', '', imported_comment.content.renderContents()), + content_html=re.sub(r'^$', '', imported_comment.content_html.renderContents()), + ) + + # Stores id for reply_to mapping. + comments_ids_map[imported_comment.id.renderContents()] = comment + + # Process boolean and potentially null integer/foreign key attributes. + save = False + if imported_comment.deleted.renderContents() == 'True': + comment.deleted = True + save = True + if imported_comment.start_wrapper.renderContents() != 'None': + comment.start_wrapper = imported_comment.start_wrapper.renderContents() + save = True + if imported_comment.end_wrapper.renderContents() != 'None': + comment.end_wrapper = imported_comment.end_wrapper.renderContents() + save = True + if imported_comment.start_offset.renderContents() != 'None': + comment.start_offset = imported_comment.start_offset.renderContents() + save = True + if imported_comment.end_offset.renderContents() != 'None': + comment.end_offset = imported_comment.end_offset.renderContents() + save = True + if imported_comment.find('parent'): + comment.reply_to = comments_ids_map.get(imported_comment.find('parent').renderContents()) + save = True + if save: + comment.save() + + # Brute updates of dates (cannot do it through django models since fields are set with auto_now or auto_now_add). + created=imported_comment.created.renderContents(), + modified=imported_comment.modified.renderContents(), + cursor.execute("UPDATE cm_comment SET created = %s, modified = %s WHERE id = %s", [created, modified, comment.id]) + transaction.commit_unless_managed() + + # Logs on activity. + register_activity(request, "text_imported", text) + display_message(request, _(u'Text "%(text_title)s" has been imported')%{"text_title":text.get_latest_version().title}) + return None, HttpResponseRedirect(reverse('text-view', args=[text.key])) + else: + form = createForm() + + return None, render_to_response('site/text_create_import.html', {'form' : form}, context_instance=RequestContext(request)) + + @has_global_perm('can_create_text') def text_create_upload(request): text, rep = _text_create_upload(request, CreateTextUploadForm) return rep +def text_create_import(request): + text, rep = _text_create_import(request, CreateTextImportForm) + return rep + def create_text(user, data): text = Text.objects.create_text(title=data['title'], format=data['format'], @@ -142,4 +282,4 @@ # save updated (attach links) text content text_version.content = text_content text_version.save() - return text \ No newline at end of file + return text diff -r a69421197502 -r 2fdb7d095d5c src/cm/views/export.py --- a/src/cm/views/export.py Thu Aug 09 16:55:25 2012 +0200 +++ b/src/cm/views/export.py Fri Aug 10 16:12:29 2012 +0200 @@ -109,7 +109,7 @@ def xml_export(request, text_version, whichcomments): # Text version infos - template_dict = { 'title': text_version.title, 'date': text_version.modified, 'format': text_version.format, 'content': text_version.content, 'tags': text_version.tags, } + template_dict = { 'title': text_version.title, 'created': text_version.created, 'modified': text_version.modified, 'format': text_version.format, 'content': text_version.content, 'tags': text_version.tags, } # Comments comments = [] # whichcomments=="none"