src/cm/views/create.py
changeset 175 4f072edc51a1
parent 106 36165e7cd1f0
child 216 6f635c8e98c3
equal deleted inserted replaced
174:805b9195c511 175:4f072edc51a1
   115 @has_global_perm('can_create_text')
   115 @has_global_perm('can_create_text')
   116 def text_create_upload(request):
   116 def text_create_upload(request):
   117     return _text_create_upload(request, CreateTextUploadForm)
   117     return _text_create_upload(request, CreateTextUploadForm)
   118 
   118 
   119 def create_text(user, data):
   119 def create_text(user, data):
   120     text_content = data['content']
       
   121     text = Text.objects.create_text(title=data['title'],
   120     text = Text.objects.create_text(title=data['title'],
   122                                     format=data['format'],
   121                                     format=data['format'],
   123                                     content=text_content,
   122                                     content=data['content'],
   124                                     note=data.get('note', None),
   123                                     note=data.get('note', None),
   125                                     name=data.get('name', None),
   124                                     name=data.get('name', None),
   126                                     email=data.get('email', None),
   125                                     email=data.get('email', None),
   127                                     tags=data.get('tags', None),
   126                                     tags=data.get('tags', None),
   128                                     user=user
   127                                     user=user
   129                                     )
   128                                     )
   130     text.update_denorm_fields()
   129     text.update_denorm_fields()
   131     text_version = text.get_latest_version()
   130     text_version = text.get_latest_version()
       
   131     text_content = text_version.content
   132 
   132 
   133     for attach_file in data.get('attachs',  []):
   133     for attach_file in data.get('attachs',  []):
   134         attach_data = file(attach_file, 'rb').read()
   134         attach_data = file(attach_file, 'rb').read()
   135         filename = os.path.basename(attach_file)
   135         filename = os.path.basename(attach_file)
   136         attachment = Attachment.objects.create_attachment(filename=filename, data=attach_data, text_version=text_version)
   136         attachment = Attachment.objects.create_attachment(filename=filename, data=attach_data, text_version=text_version)