src/cm/views/create.py
changeset 463 9c7de6dd1723
parent 460 2fdb7d095d5c
child 499 805e08ea57b1
equal deleted inserted replaced
462:189be4b3d712 463:9c7de6dd1723
    59           msg = _("You should specify a file to upload.")
    59           msg = _("You should specify a file to upload.")
    60           self._errors["file"] = ErrorList([msg])
    60           self._errors["file"] = ErrorList([msg])
    61           return cleaned_data
    61           return cleaned_data
    62 
    62 
    63         uploaded_file = self.cleaned_data['file']
    63         uploaded_file = self.cleaned_data['file']
    64         if (uploaded_file.content_type != 'text/xml'):
    64         if (uploaded_file.content_type != 'text/xml' and (uploaded_file.content_type != 'application/octet-stream' or cleaned_data.get('mime', 'application/xml') != 'application/xml')):
    65           msg = _("The imported file should be an XML file generated by co-ment when exporting a text and comments.")
    65           msg = _("The imported file should be an XML file generated by co-ment when exporting a text and comments.")
    66           self._errors["file"] = ErrorList([msg])
    66           self._errors["file"] = ErrorList([msg])
    67           return cleaned_data
    67           return cleaned_data
    68 
    68 
    69         soup = BeautifulStoneSoup(uploaded_file)
    69         soup = BeautifulStoneSoup(uploaded_file)
   177         form.cleaned_data['tags'] = soup.co_ment_text.tags.renderContents()
   177         form.cleaned_data['tags'] = soup.co_ment_text.tags.renderContents()
   178 
   178 
   179       # Replaces attachements keys in content.
   179       # Replaces attachements keys in content.
   180       for old_key in attachments_keys_map.keys():
   180       for old_key in attachments_keys_map.keys():
   181         form.cleaned_data['content'] = re.sub(old_key, attachments_keys_map[old_key], form.cleaned_data['content'])
   181         form.cleaned_data['content'] = re.sub(old_key, attachments_keys_map[old_key], form.cleaned_data['content'])
       
   182       form.cleaned_data['content'] = re.sub(r'src="/attach/', 'src="' + settings.SITE_URL + '/attach/', form.cleaned_data['content'])
   182 
   183 
   183       # Creates text.
   184       # Creates text.
   184       text = create_text(request.user, form.cleaned_data)
   185       text = create_text(request.user, form.cleaned_data)
   185 
   186 
   186       # Brute updates of dates (cannot do it through django models since fields are set with auto_now or auto_now_add).
   187       # Brute updates of dates (cannot do it through django models since fields are set with auto_now or auto_now_add).
   240           transaction.commit_unless_managed()
   241           transaction.commit_unless_managed()
   241 
   242 
   242       # Logs on activity.
   243       # Logs on activity.
   243       register_activity(request, "text_imported", text)
   244       register_activity(request, "text_imported", text)
   244       display_message(request, _(u'Text "%(text_title)s" has been imported')%{"text_title":text.get_latest_version().title})
   245       display_message(request, _(u'Text "%(text_title)s" has been imported')%{"text_title":text.get_latest_version().title})
   245       return None, HttpResponseRedirect(reverse('text-view', args=[text.key]))
   246       return text, HttpResponseRedirect(reverse('text-view', args=[text.key]))
   246   else:
   247   else:
   247     form = createForm()
   248     form = createForm()
   248 
   249 
   249   return None, render_to_response('site/text_create_import.html', {'form' : form}, context_instance=RequestContext(request))
   250   return None, render_to_response('site/text_create_import.html', {'form' : form}, context_instance=RequestContext(request))
   250 
   251