示例#1
0
    def get_context_data(self, **kwargs):
        context = super(UploadInteractiveView, self).get_context_data(**kwargs)
        context['title'] = _('Upload a local document from source: %s') % self.source.title

        context.update(
            {
                'sidebar_subtemplates_list': [
                    {
                        'name': 'main/generic_subtemplate.html',
                        'context': {
                            'title': _('Current document type'),
                            'paragraphs': [self.document_type if self.document_type else _('None')],
                            'side_bar': True,
                        }
                    },
                    {
                        'name': 'main/generic_subtemplate.html',
                        'context': {
                            'title': _('Current metadata'),
                            'paragraphs': metadata_repr_as_list(decode_metadata_from_url(self.request.GET)),
                            'side_bar': True,
                        }
                    }
                ],
            }
        )
        return context
示例#2
0
    def get_context_data(self, **kwargs):
        context = super(UploadInteractiveView, self).get_context_data(**kwargs)
        context['title'] = _(
            'Upload a local document from source: %s') % self.source.title

        context.update({
            'sidebar_subtemplates_list': [{
                'name': 'main/generic_subtemplate.html',
                'context': {
                    'title':
                    _('Current document type'),
                    'paragraphs':
                    [self.document_type if self.document_type else _('None')],
                    'side_bar':
                    True,
                }
            }, {
                'name': 'main/generic_subtemplate.html',
                'context': {
                    'title':
                    _('Current metadata'),
                    'paragraphs':
                    metadata_repr_as_list(
                        decode_metadata_from_url(self.request.GET)),
                    'side_bar':
                    True,
                }
            }],
        })
        return context
示例#3
0
    def forms_valid(self, forms):
        if self.source.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
            expand = forms['source_form'].cleaned_data.get('expand')
        else:
            if self.source.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                expand = True
            else:
                expand = False

        uploaded_file = self.source.get_upload_file_object(
            forms['source_form'].cleaned_data
        )

        shared_uploaded_file = SharedUploadedFile.objects.create(
            file=uploaded_file.file
        )

        label = None

        if 'document_type_available_filenames' in forms['document_form'].cleaned_data:
            if forms['document_form'].cleaned_data['document_type_available_filenames']:
                label = forms['document_form'].cleaned_data['document_type_available_filenames'].filename

        if not self.request.user.is_anonymous():
            user_id = self.request.user.pk
        else:
            user_id = None

        try:
            self.source.clean_up_upload_file(uploaded_file)
        except Exception as exception:
            messages.error(self.request, exception)

        task_source_handle_upload.apply_async(kwargs=dict(
            description=forms['document_form'].cleaned_data.get('description'),
            document_type_id=self.document_type.pk,
            expand=expand,
            label=label,
            language=forms['document_form'].cleaned_data.get('language'),
            metadata_dict_list=decode_metadata_from_url(self.request.GET),
            shared_uploaded_file_id=shared_uploaded_file.pk,
            source_id=self.source.pk,
            tag_ids=self.request.GET.getlist('tags'),
            user_id=user_id,
        ))
        messages.success(
            self.request,
            _(
                'New document queued for uploaded and will be available '
                'shortly.'
            )
        )

        return HttpResponseRedirect(
            '{}?{}'.format(
                reverse(self.request.resolver_match.view_name),
                self.request.META['QUERY_STRING']
            ),
        )
示例#4
0
文件: views.py 项目: e6/mayan-edms
    def forms_valid(self, forms):
        if self.source.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
            expand = forms['source_form'].cleaned_data.get('expand')
        else:
            if self.source.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                expand = True
            else:
                expand = False

        uploaded_file = self.source.get_upload_file_object(
            forms['source_form'].cleaned_data
        )

        shared_uploaded_file = SharedUploadedFile.objects.create(
            file=uploaded_file.file
        )

        label = None

        if 'document_type_available_filenames' in forms['document_form'].cleaned_data:
            if forms['document_form'].cleaned_data['document_type_available_filenames']:
                label = forms['document_form'].cleaned_data['document_type_available_filenames'].filename

        if not self.request.user.is_anonymous():
            user_id = self.request.user.pk
        else:
            user_id = None

        try:
            self.source.clean_up_upload_file(uploaded_file)
        except Exception as exception:
            messages.error(self.request, exception)

        task_source_handle_upload.apply_async(kwargs=dict(
            description=forms['document_form'].cleaned_data.get('description'),
            document_type_id=self.document_type.pk,
            expand=expand,
            label=label,
            language=forms['document_form'].cleaned_data.get('language'),
            metadata_dict_list=decode_metadata_from_url(self.request.GET),
            shared_uploaded_file_id=shared_uploaded_file.pk,
            source_id=self.source.pk,
            user_id=user_id,
        ))
        messages.success(
            self.request,
            _(
                'New document queued for uploaded and will be available '
                'shortly.'
            )
        )
        return HttpResponseRedirect(self.request.get_full_path())
示例#5
0
def upload_interactive(request, source_type=None, source_id=None, document_pk=None ):
    subtemplates_list = []

    if document_pk:
        document = get_object_or_404(Document, pk=document_pk)
        try:
            Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_NEW_VERSION])
        except PermissionDenied:
            AccessEntry.objects.check_access(PERMISSION_DOCUMENT_NEW_VERSION, request.user, document)

        results = get_active_tab_links(document)
    else:
        Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE])
        document = None
        results = get_active_tab_links()

    context = {}

    if results[SOURCE_CHOICE_WEB_FORM].count() == 0 and results[SOURCE_CHOICE_STAGING].count() == 0:
        source_setup_link = mark_safe('<a href="%s">%s</a>' % (reverse('setup_web_form_list'), ugettext(u'here')))
        subtemplates_list.append(
            {
                'name': 'generic_subtemplate.html',
                'context': {
                    'title': _(u'Upload sources'),
                    'paragraphs': [
                        _(u'No interactive document sources have been defined or none have been enabled.'),
                        _(u'Click %(setup_link)s to add or enable some document sources.') % {
                            'setup_link': source_setup_link
                        }
                    ],
                }
            })

    csv = request.GET.get('csv', False)

    document_type_id = request.GET.get('document_type_id', None)
    if document_type_id:
        document_type = get_object_or_404(DocumentType, pk=document_type_id)
    else:
        document_type = None

    if source_type is None and source_id is None:
        if results[SOURCE_CHOICE_WEB_FORM].count():
            source_type = results[SOURCE_CHOICE_WEB_FORM][0].source_type
            source_id = results[SOURCE_CHOICE_WEB_FORM][0].pk
        elif results[SOURCE_CHOICE_STAGING].count():
            source_type = results[SOURCE_CHOICE_STAGING][0].source_type
            source_id = results[SOURCE_CHOICE_STAGING][0].pk

    if source_type and source_id:
        if source_type == SOURCE_CHOICE_WEB_FORM:
            web_form = get_object_or_404(WebForm, pk=source_id)
            context['source'] = web_form
            if request.method == 'POST':
                form = WebFormForm(request.POST, request.FILES,
                    document_type=document_type,
                    show_expand=(web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document,
                    source=web_form,
                    instance=document
                )
                if form.is_valid():
                    try:
                        if document:
                            expand = False
                        else:
                            if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                                expand = form.cleaned_data.get('expand')
                            else:
                                if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                    expand = True
                                else:
                                    expand = False

                        new_filename = get_form_filename(form)
                        folder = None
                        if csv == 'True':
                            if request.POST.has_key('folder'):
                                folder_id = request.POST['folder']
                                folder = get_object_or_404(Folder, pk=folder_id)
                            result = web_form.upload_file_csv(folder,request.FILES['file'], request.FILES['csv_file'],
                                new_filename, use_file_name=form.cleaned_data.get('use_file_name', False),
                                document_type=document_type,
                                expand=True,
                                metadata_dict_list=decode_metadata_from_url(request.GET),
                                user=request.user,
                                document=document,
                                new_version_data=form.cleaned_data.get('new_version_data')
                            )
                        else:
                            if request.POST.has_key('folder'):
                                folder_id = request.POST['folder']
                                folder = get_object_or_404(Folder, pk=folder_id)
                            result = web_form.upload_file(folder,request.FILES['file'],
                                new_filename, use_file_name=form.cleaned_data.get('use_file_name', False),
                                document_type=document_type,
                                expand=expand,
                                metadata_dict_list=decode_metadata_from_url(request.GET),
                                user=request.user,
                                document=document,
                                new_version_data=form.cleaned_data.get('new_version_data')
                            )

                        if document:
                            messages.success(request, _(u'New document version uploaded successfully.'))
                            return HttpResponseRedirect(reverse('document_view_simple', args=[document.pk]))
                        else:
                            if result['is_compressed'] == None:
                                messages.success(request, _(u'File uploaded successfully.'))

                            if result['is_compressed'] == True:
                                messages.success(request, _(u'File uncompressed successfully and uploaded as individual files.'))

                            if result['is_compressed'] == False:
                                messages.warning(request, _(u'File was not a compressed file, uploaded as it was.'))

                            return HttpResponseRedirect(request.get_full_path())
                    except NewDocumentVersionNotAllowed:
                        messages.error(request, _(u'New version uploads are not allowed for this document.'))
                    except Exception, e:
                        if settings.DEBUG:
                            raise
                        messages.error(request, _(u'Unhandled exception: %s') % e)
                else:
                    print 'form.is_valid: False'
            else:
                if csv == 'True':
                    form = WebFormFormCustom(
                        document_type=document_type,
                        source=web_form,
                        instance=document,
                        user=request.user
                    )
                else:
                    form = WebFormForm(
                        show_expand=(web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document,
                        document_type=document_type,
                        source=web_form,
                        instance=document
                    )
            if document:
                title = _(u'upload a new version from source: %s') % web_form.title
            else:
                title = _(u'upload a local document from source: %s') % web_form.title

            subtemplates_list.append({
                'name': 'generic_form_subtemplate.html',
                'context': {
                    'form': form,
                    'title': title,
                },
            })
        elif source_type == SOURCE_CHOICE_STAGING:
            staging_folder = get_object_or_404(StagingFolder, pk=source_id)
            context['source'] = staging_folder
            StagingFile = create_staging_file_class(request, staging_folder.folder_path, source=staging_folder)
            if request.method == 'POST':
                form = StagingDocumentForm(request.POST, request.FILES,
                    cls=StagingFile, document_type=document_type,
                    show_expand=(staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document,
                    source=staging_folder,
                    instance=document
                )
                if form.is_valid():
                    try:
                        staging_file = StagingFile.get(form.cleaned_data['staging_file_id'])
                        if document:
                            expand = False
                        else:
                            if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                                expand = form.cleaned_data.get('expand')
                            else:
                                if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                    expand = True
                                else:
                                    expand = False

                        new_filename = get_form_filename(form)

                        result = staging_folder.upload_file(None, staging_file.upload(),
                            new_filename, use_file_name=form.cleaned_data.get('use_file_name', False),
                            document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(request.GET),
                            user=request.user,
                            document=document,
                            new_version_data=form.cleaned_data.get('new_version_data')
                        )
                        if document:
                            messages.success(request, _(u'Document version from staging file: %s, uploaded successfully.') % staging_file.filename)
                        else:
                            if result['is_compressed'] == None:
                                messages.success(request, _(u'Staging file: %s, uploaded successfully.') % staging_file.filename)

                        if result['is_compressed'] == True:
                            messages.success(request, _(u'Staging file: %s, uncompressed successfully and uploaded as individual files.') % staging_file.filename)

                        if result['is_compressed'] == False:
                            messages.warning(request, _(u'Staging file: %s, was not compressed, uploaded as a single file.') % staging_file.filename)

                        if staging_folder.delete_after_upload:
                            transformations, errors = staging_folder.get_transformation_list()
                            staging_file.delete(preview_size=staging_folder.get_preview_size(), transformations=transformations)
                            messages.success(request, _(u'Staging file: %s, deleted successfully.') % staging_file.filename)
                        if document:
                            return HttpResponseRedirect(reverse('document_view_simple', args=[document.pk]))
                        else:
                            return HttpResponseRedirect(request.get_full_path())
                    except NewDocumentVersionNotAllowed:
                        messages.error(request, _(u'New version uploads are not allowed for this document.'))
                    except Exception, e:
                        if settings.DEBUG:
                            raise
                        messages.error(request, _(u'Unhandled exception: %s') % e)
            else:
                if csv == 'True':
                    form = StagingDocumentFormCustom(cls=StagingFile,
                        document_type=document_type,
                        source=staging_folder,
                        instance=document
                    )
                else:
                    form = StagingDocumentForm(cls=StagingFile,
                        document_type=document_type,
                        show_expand=(staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document,
                        source=staging_folder,
                        instance=document
                    )
            try:
                staging_filelist = StagingFile.get_all()
            except Exception, e:
                messages.error(request, e)
                staging_filelist = []
示例#6
0
        context.update(
            {
                'sidebar_subtemplates_list': [
                    {
                        'name': 'generic_subtemplate.html',
                        'context': {
                            'title': _(u'Current document type'),
                            'paragraphs': [document_type if document_type else _(u'None')],
                            'side_bar': True,
                        }
                    },
                    {
                        'name': 'generic_subtemplate.html',
                        'context': {
                            'title': _(u'Current metadata'),
                            'paragraphs': metadata_repr_as_list(decode_metadata_from_url(request.GET)),
                            'side_bar': True,
                        }
                    }
                ],
            }
        )

    return render_to_response('generic_form.html', context,
        context_instance=RequestContext(request))


def get_form_filename(form):
    filename = None
    if form:
        if form.cleaned_data['new_filename']:
示例#7
0
文件: views.py 项目: AmiGanguli/mayan
def upload_interactive(request, source_type=None, source_id=None, document_pk=None):
    subtemplates_list = []

    if document_pk:
        document = get_object_or_404(Document, pk=document_pk)
        try:
            Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_NEW_VERSION])
        except PermissionDenied:
            AccessEntry.objects.check_access(PERMISSION_DOCUMENT_NEW_VERSION, request.user, document)

        results = get_active_tab_links(document)
    else:
        Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE])
        document = None
        results = get_active_tab_links()

    context = {}

    if results[SOURCE_CHOICE_WEB_FORM].count() == 0 and results[SOURCE_CHOICE_STAGING].count() == 0:
        source_setup_link = mark_safe('<a href="%s">%s</a>' % (reverse('setup_web_form_list'), ugettext(u'here')))
        subtemplates_list.append(
            {
                'name': 'generic_subtemplate.html',
                'context': {
                    'title': _(u'Upload sources'),
                    'paragraphs': [
                        _(u'No interactive document sources have been defined or none have been enabled.'),
                        _(u'Click %(setup_link)s to add or enable some document sources.') % {
                            'setup_link': source_setup_link
                        }
                    ],
                }
            })

    document_type_id = request.GET.get('document_type_id', None)
    if document_type_id:
        document_type = get_object_or_404(DocumentType, pk=document_type_id[0])
    else:
        document_type = None

    if source_type is None and source_id is None:
        if results[SOURCE_CHOICE_WEB_FORM].count():
            source_type = results[SOURCE_CHOICE_WEB_FORM][0].source_type
            source_id = results[SOURCE_CHOICE_WEB_FORM][0].pk
        elif results[SOURCE_CHOICE_STAGING].count():
            source_type = results[SOURCE_CHOICE_STAGING][0].source_type
            source_id = results[SOURCE_CHOICE_STAGING][0].pk

    if source_type and source_id:
        if source_type == SOURCE_CHOICE_WEB_FORM:
            web_form = get_object_or_404(WebForm, pk=source_id)
            context['source'] = web_form
            if request.method == 'POST':
                form = WebFormForm(request.POST, request.FILES,
                    document_type=document_type,
                    show_expand=(web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document,
                    source=web_form,
                    instance=document
                )
                if form.is_valid():
                    try:
                        if document:
                            expand = False
                        else:
                            if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                                expand = form.cleaned_data.get('expand')
                            else:
                                if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                    expand = True
                                else:
                                    expand = False

                        new_filename = get_form_filename(form)

                        result = web_form.upload_file(request.FILES['file'],
                            new_filename, use_file_name=form.cleaned_data.get('use_file_name', False),
                            document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(request.GET),
                            user=request.user,
                            document=document,
                            new_version_data=form.cleaned_data.get('new_version_data')
                        )
                        if document:
                            messages.success(request, _(u'New document version uploaded successfully.'))
                            return HttpResponseRedirect(reverse('document_view_simple', args=[document.pk]))
                        else:
                            if result['is_compressed'] == None:
                                messages.success(request, _(u'File uploaded successfully.'))

                            if result['is_compressed'] == True:
                                messages.success(request, _(u'File uncompressed successfully and uploaded as individual files.'))

                            if result['is_compressed'] == False:
                                messages.warning(request, _(u'File was not a compressed file, uploaded as it was.'))

                            return HttpResponseRedirect(request.get_full_path())
                    except NewDocumentVersionNotAllowed:
                        messages.error(request, _(u'New version uploads are not allowed for this document.'))
                    except Exception, e:
                        if settings.DEBUG:
                            raise
                        messages.error(request, _(u'Unhandled exception: %s') % e)
            else:
                form = WebFormForm(
                    show_expand=(web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document,
                    document_type=document_type,
                    source=web_form,
                    instance=document
                )
            if document:
                title = _(u'upload a new version from source: %s') % web_form.title
            else:
                title = _(u'upload a local document from source: %s') % web_form.title

            subtemplates_list.append({
                'name': 'generic_form_subtemplate.html',
                'context': {
                    'form': form,
                    'title': title,
                },
            })
        elif source_type == SOURCE_CHOICE_STAGING:
            staging_folder = get_object_or_404(StagingFolder, pk=source_id)
            context['source'] = staging_folder
            StagingFile = create_staging_file_class(request, staging_folder.folder_path, source=staging_folder)
            if request.method == 'POST':
                form = StagingDocumentForm(request.POST, request.FILES,
                    cls=StagingFile, document_type=document_type,
                    show_expand=(staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document,
                    source=staging_folder,
                    instance=document
                )
                if form.is_valid():
                    try:
                        staging_file = StagingFile.get(form.cleaned_data['staging_file_id'])
                        if document:
                            expand = False
                        else:
                            if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                                expand = form.cleaned_data.get('expand')
                            else:
                                if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                    expand = True
                                else:
                                    expand = False

                        new_filename = get_form_filename(form)

                        result = staging_folder.upload_file(staging_file.upload(),
                            new_filename, use_file_name=form.cleaned_data.get('use_file_name', False),
                            document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(request.GET),
                            user=request.user,
                            document=document,
                            new_version_data=form.cleaned_data.get('new_version_data')
                        )
                        if document:
                            messages.success(request, _(u'Document version from staging file: %s, uploaded successfully.') % staging_file.filename)
                        else:
                            if result['is_compressed'] == None:
                                messages.success(request, _(u'Staging file: %s, uploaded successfully.') % staging_file.filename)

                        if result['is_compressed'] == True:
                            messages.success(request, _(u'Staging file: %s, uncompressed successfully and uploaded as individual files.') % staging_file.filename)

                        if result['is_compressed'] == False:
                            messages.warning(request, _(u'Staging file: %s, was not compressed, uploaded as a single file.') % staging_file.filename)

                        if staging_folder.delete_after_upload:
                            transformations, errors = staging_folder.get_transformation_list()
                            staging_file.delete(preview_size=staging_folder.get_preview_size(), transformations=transformations)
                            messages.success(request, _(u'Staging file: %s, deleted successfully.') % staging_file.filename)
                        if document:
                            return HttpResponseRedirect(reverse('document_view_simple', args=[document.pk]))
                        else:
                            return HttpResponseRedirect(request.get_full_path())
                    except NewDocumentVersionNotAllowed:
                        messages.error(request, _(u'New version uploads are not allowed for this document.'))
                    except Exception, e:
                        if settings.DEBUG:
                            raise
                        messages.error(request, _(u'Unhandled exception: %s') % e)
            else:
                form = StagingDocumentForm(cls=StagingFile,
                    document_type=document_type,
                    show_expand=(staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document,
                    source=staging_folder,
                    instance=document
                )
            try:
                staging_filelist = StagingFile.get_all()
            except Exception, e:
                messages.error(request, e)
                staging_filelist = []
示例#8
0
文件: views.py 项目: AmiGanguli/mayan
        context.update(
            {
                'sidebar_subtemplates_list': [
                    {
                        'name': 'generic_subtemplate.html',
                        'context': {
                            'title': _(u'Current document type'),
                            'paragraphs': [document_type if document_type else _(u'None')],
                            'side_bar': True,
                        }
                    },
                    {
                        'name': 'generic_subtemplate.html',
                        'context': {
                            'title': _(u'Current metadata'),
                            'paragraphs': metadata_repr_as_list(decode_metadata_from_url(request.GET)),
                            'side_bar': True,
                        }
                    }
                ],
            }
        )

    return render_to_response('generic_form.html', context,
        context_instance=RequestContext(request))


def get_form_filename(form):
    filename = None
    if form:
        if form.cleaned_data['new_filename']:
示例#9
0
def upload_interactive(request,
                       source_type=None,
                       source_id=None,
                       document_pk=None):
    subtemplates_list = []

    if document_pk:
        document = get_object_or_404(Document, pk=document_pk)
        try:
            Permission.objects.check_permissions(
                request.user, [PERMISSION_DOCUMENT_NEW_VERSION])
        except PermissionDenied:
            AccessEntry.objects.check_access(PERMISSION_DOCUMENT_NEW_VERSION,
                                             request.user, document)

        results = get_active_tab_links(document)
    else:
        Permission.objects.check_permissions(request.user,
                                             [PERMISSION_DOCUMENT_CREATE])
        document = None
        results = get_active_tab_links()

    context = {}

    if results[SOURCE_CHOICE_WEB_FORM].count(
    ) == 0 and results[SOURCE_CHOICE_STAGING].count() == 0:
        source_setup_link = mark_safe(
            '<a href="%s">%s</a>' %
            (reverse('setup_web_form_list'), ugettext(u'here')))
        subtemplates_list.append({
            'name': 'generic_subtemplate.html',
            'context': {
                'title':
                _(u'Upload sources'),
                'paragraphs': [
                    _(u'No interactive document sources have been defined or none have been enabled.'
                      ),
                    _(u'Click %(setup_link)s to add or enable some document sources.'
                      ) % {
                          'setup_link': source_setup_link
                      }
                ],
            }
        })

    document_type_id = request.GET.get('document_type_id', None)
    if document_type_id:
        document_type = get_object_or_404(DocumentType, pk=document_type_id)
    else:
        document_type = None

    if source_type is None and source_id is None:
        if results[SOURCE_CHOICE_WEB_FORM].count():
            source_type = results[SOURCE_CHOICE_WEB_FORM][0].source_type
            source_id = results[SOURCE_CHOICE_WEB_FORM][0].pk
        elif results[SOURCE_CHOICE_STAGING].count():
            source_type = results[SOURCE_CHOICE_STAGING][0].source_type
            source_id = results[SOURCE_CHOICE_STAGING][0].pk

    if source_type and source_id:
        if source_type == SOURCE_CHOICE_WEB_FORM:
            web_form = get_object_or_404(WebForm, pk=source_id)
            context['source'] = web_form
            if request.method == 'POST':
                form = WebFormForm(
                    request.POST,
                    request.FILES,
                    document_type=document_type,
                    show_expand=(web_form.uncompress
                                 == SOURCE_UNCOMPRESS_CHOICE_ASK)
                    and not document,
                    source=web_form,
                    instance=document)
                if form.is_valid():
                    try:
                        if document:
                            expand = False
                        else:
                            if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                                expand = form.cleaned_data.get('expand')
                            else:
                                if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                    expand = True
                                else:
                                    expand = False

                        new_filename = get_form_filename(form)

                        result = web_form.upload_file(
                            request.FILES['file'],
                            new_filename,
                            use_file_name=form.cleaned_data.get(
                                'use_file_name', False),
                            document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(
                                request.GET),
                            user=request.user,
                            document=document,
                            new_version_data=form.cleaned_data.get(
                                'new_version_data'),
                            description=form.cleaned_data.get('description'))
                        if document:
                            messages.success(
                                request,
                                _(u'New document version uploaded successfully.'
                                  ))
                            return HttpResponseRedirect(
                                reverse('document_version_list',
                                        args=[document.pk]))
                        else:
                            if result['is_compressed'] is None:
                                messages.success(
                                    request, _(u'File uploaded successfully.'))

                            if result['is_compressed'] is True:
                                messages.success(
                                    request,
                                    _(u'File uncompressed successfully and uploaded as individual files.'
                                      ))

                            if result['is_compressed'] is False:
                                messages.warning(
                                    request,
                                    _(u'File was not a compressed file, uploaded as it was.'
                                      ))

                            return HttpResponseRedirect(
                                request.get_full_path())
                    except NewDocumentVersionNotAllowed:
                        messages.error(
                            request,
                            _(u'New version uploads are not allowed for this document.'
                              ))
                    except Exception as exception:
                        if settings.DEBUG:
                            raise
                        messages.error(
                            request,
                            _(u'Unhandled exception: %s') % exception)
            else:
                form = WebFormForm(
                    show_expand=(web_form.uncompress
                                 == SOURCE_UNCOMPRESS_CHOICE_ASK)
                    and not document,
                    document_type=document_type,
                    source=web_form,
                    instance=document)
            if document:
                title = _(
                    u'upload a new version from source: %s') % web_form.title
            else:
                title = _(u'upload a local document from source: %s'
                          ) % web_form.title

            subtemplates_list.append({
                'name': 'generic_form_subtemplate.html',
                'context': {
                    'form': form,
                    'title': title,
                },
            })
        elif source_type == SOURCE_CHOICE_STAGING:
            staging_folder = get_object_or_404(StagingFolder, pk=source_id)
            context['source'] = staging_folder

            if request.method == 'POST':
                form = StagingDocumentForm(
                    request.POST,
                    request.FILES,
                    document_type=document_type,
                    show_expand=(staging_folder.uncompress
                                 == SOURCE_UNCOMPRESS_CHOICE_ASK)
                    and not document,
                    source=staging_folder,
                    instance=document)
                if form.is_valid():
                    try:
                        staging_file = staging_folder.get_file(
                            encoded_filename=form.
                            cleaned_data['staging_file_id'])
                        if document:
                            expand = False
                        else:
                            if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                                expand = form.cleaned_data.get('expand')
                            else:
                                if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                    expand = True
                                else:
                                    expand = False

                        new_filename = get_form_filename(form)

                        result = staging_folder.upload_file(
                            staging_file.as_file(),
                            new_filename,
                            use_file_name=form.cleaned_data.get(
                                'use_file_name', False),
                            document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(
                                request.GET),
                            user=request.user,
                            document=document,
                            new_version_data=form.cleaned_data.get(
                                'new_version_data'),
                            description=form.cleaned_data.get('description'))
                        if document:
                            messages.success(
                                request,
                                _(u'Document version from staging file: %s, uploaded successfully.'
                                  ) % staging_file.filename)
                        else:
                            if result['is_compressed'] is None:
                                messages.success(
                                    request,
                                    _(u'Staging file: %s, uploaded successfully.'
                                      ) % staging_file.filename)

                        if result['is_compressed'] is True:
                            messages.success(
                                request,
                                _(u'Staging file: %s, uncompressed successfully and uploaded as individual files.'
                                  ) % staging_file.filename)

                        if result['is_compressed'] is False:
                            messages.warning(
                                request,
                                _(u'Staging file: %s, was not compressed, uploaded as a single file.'
                                  ) % staging_file.filename)

                        if staging_folder.delete_after_upload:
                            staging_file.delete()
                            messages.success(
                                request,
                                _(u'Staging file: %s, deleted successfully.') %
                                staging_file.filename)
                        if document:
                            return HttpResponseRedirect(
                                reverse('document_view_simple',
                                        args=[document.pk]))
                        else:
                            return HttpResponseRedirect(
                                request.get_full_path())
                    except NewDocumentVersionNotAllowed:
                        messages.error(
                            request,
                            _(u'New version uploads are not allowed for this document.'
                              ))
                    except Exception as exception:
                        if settings.DEBUG:
                            raise
                        messages.error(
                            request,
                            _(u'Unhandled exception: %s') % exception)
            else:
                form = StagingDocumentForm(
                    document_type=document_type,
                    show_expand=(staging_folder.uncompress
                                 == SOURCE_UNCOMPRESS_CHOICE_ASK)
                    and not document,
                    source=staging_folder,
                    instance=document)
            try:
                staging_filelist = list(staging_folder.get_files())
            except Exception as exception:
                messages.error(request, exception)
                staging_filelist = []
            finally:
                if document:
                    title = _(u'upload a new version from staging source: %s'
                              ) % staging_folder.title
                else:
                    title = _(u'upload a document from staging source: %s'
                              ) % staging_folder.title

                subtemplates_list = [
                    {
                        'name': 'generic_form_subtemplate.html',
                        'context': {
                            'form': form,
                            'title': title,
                        }
                    },
                    {
                        'name': 'generic_list_subtemplate.html',
                        'context': {
                            'title': _(u'files in staging path'),
                            'object_list': staging_filelist,
                            'hide_link': True,
                        }
                    },
                ]

    if document:
        context['object'] = document

    context.update({
        'document_type_id': document_type_id,
        'subtemplates_list': subtemplates_list,
        'temporary_navigation_links': {
            'form_header': {
                'upload_version': {
                    'links': results['tab_links']
                },
                'upload_interactive': {
                    'links': results['tab_links']
                }
            }
        },
    })

    if not document:
        context.update({
            'sidebar_subtemplates_list': [{
                'name': 'generic_subtemplate.html',
                'context': {
                    'title': _(u'Current document type'),
                    'paragraphs':
                    [document_type if document_type else _(u'None')],
                    'side_bar': True,
                }
            }, {
                'name': 'generic_subtemplate.html',
                'context': {
                    'title':
                    _(u'Current metadata'),
                    'paragraphs':
                    metadata_repr_as_list(decode_metadata_from_url(
                        request.GET)),
                    'side_bar':
                    True,
                }
            }],
        })

    return render_to_response('generic_form.html',
                              context,
                              context_instance=RequestContext(request))
示例#10
0
文件: views.py 项目: IHLeanne/mayan
def upload_interactive(request, source_type=None, source_id=None):
    check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE])

    subtemplates_list = []

    context = {}

    results = get_active_tab_links()

    if results[SOURCE_CHOICE_WEB_FORM].count() == 0 and results[SOURCE_CHOICE_STAGING].count() == 0:
        source_setup_link = mark_safe('<a href="%s">%s</a>' % (reverse('setup_web_form_list'), ugettext(u'here')))
        subtemplates_list.append(
            {
                'name': 'generic_subtemplate.html',
                'context': {
                    'title': _(u'Upload sources'),
                    'paragraphs': [
                        _(u'No interactive document sources have been defined or none have been enabled.'),
                        _(u'Click %(setup_link)s to add or enable some document sources.') % {
                            'setup_link': source_setup_link
                        }
                    ],
                }
            })

    document_type_id = request.GET.get('document_type_id', None)
    if document_type_id:
        document_type = get_object_or_404(DocumentType, pk=document_type_id[0])
    else:
        document_type = None

    if source_type is None and source_id is None:
        if results[SOURCE_CHOICE_WEB_FORM].count():
            source_type = results[SOURCE_CHOICE_WEB_FORM][0].source_type
            source_id = results[SOURCE_CHOICE_WEB_FORM][0].pk
        elif results[SOURCE_CHOICE_STAGING].count():
            source_type = results[SOURCE_CHOICE_STAGING][0].source_type
            source_id = results[SOURCE_CHOICE_STAGING][0].pk

    if source_type and source_id:
        if source_type == SOURCE_CHOICE_WEB_FORM:
            web_form = get_object_or_404(WebForm, pk=source_id)
            context['source'] = web_form
            if request.method == 'POST':
                form = WebFormForm(request.POST, request.FILES,
                    document_type=document_type,
                    show_expand=(web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK),
                    source=web_form
                )
                if form.is_valid():
                    try:
                        if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                            expand = form.cleaned_data['expand']
                        else:
                            if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                expand = True
                            else:
                                expand = False

                        new_filename = get_form_filename(form)
                        web_form.upload_file(request.FILES['file'],
                            new_filename, document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(request.GET),
                            user=request.user
                        )
                        messages.success(request, _(u'Document uploaded successfully.'))
                    except Exception, e:
                        messages.error(request, e)

                    return HttpResponseRedirect(request.get_full_path())
            else:
                form = WebFormForm(
                    show_expand=(web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK),
                    document_type=document_type,
                    source=web_form
                )

            subtemplates_list.append({
                'name': 'generic_form_subtemplate.html',
                'context': {
                    'form': form,
                    'title': _(u'upload a local document from source: %s') % web_form.title,
                },
            })
        elif source_type == SOURCE_CHOICE_STAGING:
            staging_folder = get_object_or_404(StagingFolder, pk=source_id)
            context['source'] = staging_folder
            StagingFile = create_staging_file_class(request, staging_folder.folder_path, source=staging_folder)
            if request.method == 'POST':
                form = StagingDocumentForm(request.POST, request.FILES,
                    cls=StagingFile, document_type=document_type,
                    show_expand=(staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK),
                    source=staging_folder
                )
                if form.is_valid():
                    try:
                        staging_file = StagingFile.get(form.cleaned_data['staging_file_id'])
                        if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                            expand = form.cleaned_data['expand']
                        else:
                            if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                expand = True
                            else:
                                expand = False
                        new_filename = get_form_filename(form)
                        staging_folder.upload_file(staging_file.upload(),
                            new_filename, document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(request.GET),
                            user=request.user
                        )
                        messages.success(request, _(u'Staging file: %s, uploaded successfully.') % staging_file.filename)

                        if staging_folder.delete_after_upload:
                            transformations, errors = staging_folder.get_transformation_list()
                            staging_file.delete(preview_size=staging_folder.get_preview_size(), transformations=transformations)
                            messages.success(request, _(u'Staging file: %s, deleted successfully.') % staging_file.filename)
                    except Exception, e:
                        messages.error(request, e)

                    return HttpResponseRedirect(request.get_full_path())
            else:
                form = StagingDocumentForm(cls=StagingFile,
                    document_type=document_type,
                    show_expand=(staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK),
                    source=staging_folder
                )
            try:
                staging_filelist = StagingFile.get_all()
            except Exception, e:
                messages.error(request, e)
                staging_filelist = []
示例#11
0
def upload_interactive(request,
                       source_type=None,
                       source_id=None,
                       document_pk=None):
    subtemplates_list = []

    if document_pk:
        document = get_object_or_404(Document, pk=document_pk)
        try:
            Permission.objects.check_permissions(
                request.user, [PERMISSION_DOCUMENT_NEW_VERSION])
        except PermissionDenied:
            AccessEntry.objects.check_access(PERMISSION_DOCUMENT_NEW_VERSION,
                                             request.user, document)

        results = get_active_tab_links(document)
    else:
        Permission.objects.check_permissions(request.user,
                                             [PERMISSION_DOCUMENT_CREATE])
        document = None
        results = get_active_tab_links()

    context = {}

    if results[SOURCE_CHOICE_WEB_FORM].count(
    ) == 0 and results[SOURCE_CHOICE_STAGING].count(
    ) == 0 and results[SOURCE_CHOICE_SCANWEB_FORM].count() == 0:
        source_setup_link = mark_safe(
            '<a href="%s">%s</a>' %
            (reverse('setup_web_form_list'), ugettext(u'here')))
        subtemplates_list.append({
            'name': 'generic_subtemplate.html',
            'context': {
                'title':
                _(u'Upload sources'),
                'paragraphs': [
                    _(u'No interactive document sources have been defined or none have been enabled.'
                      ),
                    _(u'Click %(setup_link)s to add or enable some document sources.'
                      ) % {
                          'setup_link': source_setup_link
                      }
                ],
            }
        })

    document_type_id = request.GET.get('document_type_id', None)
    if document_type_id:
        document_type = get_object_or_404(DocumentType, pk=document_type_id)
    else:
        document_type = None

    if source_type is None and source_id is None:
        if results[SOURCE_CHOICE_WEB_FORM].count():
            source_type = results[SOURCE_CHOICE_WEB_FORM][0].source_type
            source_id = results[SOURCE_CHOICE_WEB_FORM][0].pk
        elif results[SOURCE_CHOICE_STAGING].count():
            source_type = results[SOURCE_CHOICE_STAGING][0].source_type
            source_id = results[SOURCE_CHOICE_STAGING][0].pk
#************************************************************************
        elif results[SOURCE_CHOICE_SCANWEB_FORM].count():
            source_type = results[SOURCE_CHOICE_SCANWEB_FORM][0].source_type
            source_id = results[SOURCE_CHOICE_SCANWEB_FORM][0].pk
#************************************************************************

    if source_type and source_id:
        if source_type == SOURCE_CHOICE_WEB_FORM:
            web_form = get_object_or_404(WebForm, pk=source_id)
            context['source'] = web_form
            if request.method == 'POST':
                form = WebFormForm(
                    request.POST,
                    request.FILES,
                    document_type=document_type,
                    show_expand=(web_form.uncompress
                                 == SOURCE_UNCOMPRESS_CHOICE_ASK)
                    and not document,
                    source=web_form,
                    instance=document)
                if form.is_valid():
                    try:
                        if document:
                            expand = False
                        else:
                            if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                                expand = form.cleaned_data.get('expand')
                            else:
                                if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                    expand = True
                                else:
                                    expand = False

                        new_filename = get_form_filename(form)

                        result = web_form.upload_file(
                            request.FILES['file'],
                            new_filename,
                            use_file_name=form.cleaned_data.get(
                                'use_file_name', False),
                            document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(
                                request.GET),
                            user=request.user,
                            document=document,
                            new_version_data=form.cleaned_data.get(
                                'new_version_data'))
                        if document:
                            messages.success(
                                request,
                                _(u'New document version uploaded successfully.'
                                  ))
                            return HttpResponseRedirect(
                                reverse('document_view_simple',
                                        args=[document.pk]))
                        else:
                            if result['is_compressed'] == None:
                                messages.success(
                                    request, _(u'File uploaded successfully.'))

                            if result['is_compressed'] == True:
                                messages.success(
                                    request,
                                    _(u'File uncompressed successfully and uploaded as individual files.'
                                      ))

                            if result['is_compressed'] == False:
                                messages.warning(
                                    request,
                                    _(u'File was not a compressed file, uploaded as it was.'
                                      ))

                            return HttpResponseRedirect(
                                request.get_full_path())
                    except NewDocumentVersionNotAllowed:
                        messages.error(
                            request,
                            _(u'New version uploads are not allowed for this document.'
                              ))
                    except Exception, e:
                        if settings.DEBUG:
                            raise
                        messages.error(request,
                                       _(u'Unhandled exception: %s') % e)
            else:
                form = WebFormForm(
                    show_expand=(web_form.uncompress
                                 == SOURCE_UNCOMPRESS_CHOICE_ASK)
                    and not document,
                    document_type=document_type,
                    source=web_form,
                    instance=document)
            if document:
                title = _(
                    u'upload a new version from source: %s') % web_form.title
            else:
                title = _(u'upload a local document from source: %s'
                          ) % web_form.title

            subtemplates_list.append({
                'name': 'generic_form_subtemplate.html',
                'context': {
                    'form': form,
                    'title': title,
                },
            })

#*************************************** Scanner ********************************************************
        elif source_type == SOURCE_CHOICE_SCANWEB_FORM:
            scanweb_form = get_object_or_404(ScanWebForm, pk=source_id)
            context['source'] = scanweb_form

            if request.method == 'POST':
                #****************************your modifications*********************************************
                from django.core.files.uploadedfile import InMemoryUploadedFile
                import tempfile

                if 'file_base64' in request.POST:
                    if 'file' in request.POST:
                        request.POST.pop('file')

                    rawfile = request.POST['file_base64'].decode('base64')
                    tmpfile = tempfile.NamedTemporaryFile()
                    tmpfile.write(rawfile)

                    # This is for django 1.5:
                    inmemmory = InMemoryUploadedFile(
                        tmpfile, 'file', request.POST.get('new_filename', ''),
                        'image/jpeg', len(rawfile), None)
                    # when mayan gets upgraded to django 1.5 the
                    # InMemoryUploadedFile requires an extra argument
                    # which is also None
                    request.FILES['file'] = inmemmory

                form = ScanWebFormForm(request.POST,
                                       request.FILES,
                                       document_type=document_type,
                                       source=scanweb_form,
                                       instance=document)

                if form.is_valid():
                    try:
                        expand = False

                        new_filename = get_form_filename(form)

                        result = scanweb_form.upload_file(
                            request.FILES['file'],
                            new_filename,
                            use_file_name=form.cleaned_data.get(
                                'use_file_name', False),
                            document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(
                                request.GET),
                            user=request.user,
                            document=document,
                            new_version_data=form.cleaned_data.get(
                                'new_version_data'))
                        if document:
                            messages.success(
                                request,
                                _(u'New document version uploaded successfully.'
                                  ))
                            return HttpResponseRedirect(
                                reverse('document_view_simple',
                                        args=[document.pk]))
                        else:
                            messages.success(request,
                                             _(u'File uploaded successfully.'))
                            return HttpResponseRedirect(
                                request.get_full_path())
                    except NewDocumentVersionNotAllowed:
                        messages.error(
                            request,
                            _(u'New version uploads are not allowed for this document.'
                              ))
                    except Exception, e:
                        if settings.DEBUG:
                            raise
                        messages.error(request,
                                       _(u'Unhandled exception: %s') % e)
            else:
                form = ScanWebFormForm(document_type=document_type,
                                       source=scanweb_form,
                                       instance=document)
            if document:
                title = _(u'upload a new version from source: %s'
                          ) % scanweb_form.title
            else:
                title = _(u'upload a local document from source: %s'
                          ) % scanweb_form.title

            subtemplates_list.append({
                'name':
                'generic_scanform_subtemplate.html',  #generic_form_subtemplate.html',
                'context': {
                    'form': form,
                    'title': title,
                },
            })
示例#12
0
                            else:
                                if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                    expand = True
                                else:
                                    expand = False

                        new_filename = get_form_filename(form)

                        result = staging_folder.upload_file(
                            staging_file.upload(),
                            new_filename,
                            use_file_name=form.cleaned_data.get(
                                'use_file_name', False),
                            document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(
                                request.GET),
                            user=request.user,
                            document=document,
                            new_version_data=form.cleaned_data.get(
                                'new_version_data'))
                        if document:
                            messages.success(
                                request,
                                _(u'Document version from staging file: %s, uploaded successfully.'
                                  ) % staging_file.filename)
                        else:
                            if result['is_compressed'] == None:
                                messages.success(
                                    request,
                                    _(u'Staging file: %s, uploaded successfully.'
                                      ) % staging_file.filename)
示例#13
0
文件: views.py 项目: ntwarg/mayan
def upload_interactive(request, source_type=None, source_id=None, document_pk=None):
    subtemplates_list = []

    if document_pk:
        document = get_object_or_404(Document, pk=document_pk)
        try:
            Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_NEW_VERSION])
        except PermissionDenied:
            AccessEntry.objects.check_access(PERMISSION_DOCUMENT_NEW_VERSION, request.user, document)

        results = get_active_tab_links(document)
    else:
        Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE])
        document = None
        results = get_active_tab_links()

    context = {}

    if results[SOURCE_CHOICE_WEB_FORM].count() == 0 and results[SOURCE_CHOICE_STAGING].count() == 0 and results[SOURCE_CHOICE_SCANWEB_FORM].count() == 0:
        source_setup_link = mark_safe('<a href="%s">%s</a>' % (reverse('setup_web_form_list'), ugettext(u'here')))
        subtemplates_list.append(
            {
                'name': 'generic_subtemplate.html',
                'context': {
                    'title': _(u'Upload sources'),
                    'paragraphs': [
                        _(u'No interactive document sources have been defined or none have been enabled.'),
                        _(u'Click %(setup_link)s to add or enable some document sources.') % {
                            'setup_link': source_setup_link
                        }
                    ],
                }
            })

    document_type_id = request.GET.get('document_type_id', None)
    if document_type_id:
        document_type = get_object_or_404(DocumentType, pk=document_type_id)
    else:
        document_type = None

    if source_type is None and source_id is None:
        if results[SOURCE_CHOICE_WEB_FORM].count():
            source_type = results[SOURCE_CHOICE_WEB_FORM][0].source_type
            source_id = results[SOURCE_CHOICE_WEB_FORM][0].pk
        elif results[SOURCE_CHOICE_STAGING].count():
            source_type = results[SOURCE_CHOICE_STAGING][0].source_type
            source_id = results[SOURCE_CHOICE_STAGING][0].pk
#************************************************************************
        elif results[SOURCE_CHOICE_SCANWEB_FORM].count():
            source_type = results[SOURCE_CHOICE_SCANWEB_FORM][0].source_type
            source_id = results[SOURCE_CHOICE_SCANWEB_FORM][0].pk
#************************************************************************

    if source_type and source_id:
        if source_type == SOURCE_CHOICE_WEB_FORM:
            web_form = get_object_or_404(WebForm, pk=source_id)
            context['source'] = web_form
            if request.method == 'POST':
                form = WebFormForm(post, new_request.FILES,
                    document_type=document_type,
                    show_expand=(web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document,
                    source=web_form,
                    instance=document
                )
                if form.is_valid():
                    try:
                        if document:
                            expand = False
                        else:
                            if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK:
                                expand = form.cleaned_data.get('expand')
                            else:
                                if web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
                                    expand = True
                                else:
                                    expand = False

                        new_filename = get_form_filename(form)
                  
                        result = web_form.upload_file(request.FILES['file'],
                            new_filename, use_file_name=form.cleaned_data.get('use_file_name', False),
                            document_type=document_type,
                            expand=expand,
                            metadata_dict_list=decode_metadata_from_url(request.GET),
                            user=request.user,
                            document=document,
                            new_version_data=form.cleaned_data.get('new_version_data')
                        )
                        if document:
                            messages.success(request, _(u'New document version uploaded successfully.'))
                            return HttpResponseRedirect(reverse('document_view_simple', args=[document.pk]))
                        else:
                            if result['is_compressed'] == None:
                                messages.success(request, _(u'File uploaded successfully.'))

                            if result['is_compressed'] == True:
                                messages.success(request, _(u'File uncompressed successfully and uploaded as individual files.'))

                            if result['is_compressed'] == False:
                                messages.warning(request, _(u'File was not a compressed file, uploaded as it was.'))

                            return HttpResponseRedirect(request.get_full_path())
                    except NewDocumentVersionNotAllowed:
                        messages.error(request, _(u'New version uploads are not allowed for this document.'))
                    except Exception, e:
                        if settings.DEBUG:
                            raise
                        messages.error(request, _(u'Unhandled exception: %s') % e)
            else:
                form = WebFormForm(
                    show_expand=(web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK) and not document,
                    document_type=document_type,
                    source=web_form,
                    instance=document
                )
            if document:
                title = _(u'upload a new version from source: %s') % web_form.title
            else:
                title = _(u'upload a local document from source: %s') % web_form.title

            subtemplates_list.append({
                'name': 'generic_form_subtemplate.html',
                'context': {
                    'form': form,
                    'title': title,
                },
            })

#*************************************** Scanner ********************************************************
        elif source_type == SOURCE_CHOICE_SCANWEB_FORM:
            scanweb_form = get_object_or_404(ScanWebForm, pk=source_id)
            context['source'] = scanweb_form

            if request.method == 'POST':
            #****************************your modifications*********************************************
                from django.core.files.uploadedfile import InMemoryUploadedFile
                import tempfile

                if 'file_base64' in request.POST:
                    if 'file' in request.POST:
                        request.POST.pop('file')

                    rawfile = request.POST['file_base64'].decode('base64')
                    tmpfile = tempfile.NamedTemporaryFile()
                    tmpfile.write(rawfile)
                    
                    # This is for django 1.5:
                    inmemmory = InMemoryUploadedFile(tmpfile, 'file', request.POST.get('new_filename', ''), 'image/jpeg', len(rawfile), None)
                    # when mayan gets upgraded to django 1.5 the
                    # InMemoryUploadedFile requires an extra argument
                    # which is also None
                    request.FILES['file'] = inmemmory

                form = ScanWebFormForm(request.POST, request.FILES,
                    document_type=document_type,
                    source=scanweb_form,
                    instance=document
                )

                if form.is_valid():
                    try:
                        expand = False

                        new_filename = get_form_filename(form)
                        

                        result = scanweb_form.upload_file(request.FILES['file'],
                            new_filename, use_file_name=form.cleaned_data.get('use_file_name', False),
                            document_type=document_type,expand=expand,
                            metadata_dict_list=decode_metadata_from_url(request.GET),
                            user=request.user,
                            document=document,
                            new_version_data=form.cleaned_data.get('new_version_data')
                        )
                        if document:
                            messages.success(request, _(u'New document version uploaded successfully.'))
                            return HttpResponseRedirect(reverse('document_view_simple', args=[document.pk]))
                        else:
                            messages.success(request, _(u'File uploaded successfully.'))
                            return HttpResponseRedirect(request.get_full_path())
                    except NewDocumentVersionNotAllowed:
                        messages.error(request, _(u'New version uploads are not allowed for this document.'))
                    except Exception, e:
                        if settings.DEBUG:
                            raise
                        messages.error(request, _(u'Unhandled exception: %s') % e)
            else:
                form = ScanWebFormForm(
                    document_type=document_type,
                    source=scanweb_form,
                    instance=document
                )
            if document:
                title = _(u'upload a new version from source: %s') % scanweb_form.title
            else:
                title = _(u'upload a local document from source: %s') % scanweb_form.title

            subtemplates_list.append({
                'name': 'generic_scanform_subtemplate.html',#generic_form_subtemplate.html',
                'context': {
                    'form': form,
                    'title': title,
                },
            })