Beispiel #1
0
    def save_with_revision(self, author=None):
        revision_context_manager.start()
        if author:
            revision_context_manager.set_user(author)

        self.save()
        try:
            add_to_revision(self)

            try:
                add_to_revision(self.submission)
            except ReportSubmission.DoesNotExist:
                """
                Saving for Interim Report
                """

            if self.have_conflict_income:
                for income in self.incomeconflict_set.all():
                    add_to_revision(income)
            if self.have_conflict_activities:
                for business in self.businessconflict_set.all():
                    add_to_revision(business)
                for consulting in self.consultingconflict_set.all():
                    add_to_revision(consulting)
                for travel in self.travelconflict_set.all():
                    add_to_revision(travel)
        except:
            revision_context_manager.invalidate()
            raise
        finally:
            revision_context_manager.end()
Beispiel #2
0
 def process_exception(self, request, exception):
     """Closes the revision."""
     try:
         raise
         revision_context_manager.invalidate()
         self._close_revision(request)
     except:
         pass
Beispiel #3
0
    def dispatch(self, request, *args, **kwargs):
        revision_context_manager.start()

        try:
            response = super().dispatch(request, *args, **kwargs)
        except Exception as e:
            revision_context_manager.invalidate()
            revision_context_manager.end()
            raise

        if self.request.user.is_authenticated():
            revision_context_manager.set_user(self.request.user)

        if response.status_code > 206:
            revision_context_manager.invalidate()

        revision_context_manager.end()
        return response
Beispiel #4
0
def annotation_import(request, source_id):
    """
    Upload images and import their annotations from a text file.
    Should be improved later to have AJAX uploading.
    """

    source = get_object_or_404(Source, id=source_id)

    uploadedImages = []

    if request.method == 'POST':
        annotationForm = AnnotationImportForm(request.POST, request.FILES)
        imageForm = ImageUploadForm(request.POST, request.FILES)
        imageOptionsForm = ImageUploadOptionsForm(request.POST, source=source)
        annotationOptionsForm = AnnotationImportOptionsForm(request.POST)

        # Need getlist instead of simply request.FILES, in order to handle
        # multiple files.
        imageFiles = request.FILES.getlist('files')

        # TODO: imageForm.is_valid() just validates the first image file.
        # Make sure all image files are checked to be valid images.
        if (annotationForm.is_valid() and
            imageForm.is_valid() and
            annotationOptionsForm.is_valid() and
            imageOptionsForm.is_valid() ):

            annoFile = request.FILES['annotations_file']

            resultDict = image_upload_process(
                imageFiles=imageFiles,
                imageOptionsForm=imageOptionsForm,
                annotationOptionsForm=annotationOptionsForm,
                source=source,
                currentUser=request.user,
                annoFile=annoFile
            )

            if resultDict['error']:
                messages.error(request, resultDict['message'])
                transaction.rollback()
                revision_context_manager.invalidate()
            else:
                uploadedImages = resultDict['uploadedImages']
                messages.success(request, resultDict['message'])

        else:
            messages.error(request, 'Please correct the errors below.')

    else:
        annotationForm = AnnotationImportForm()
        imageForm = ImageUploadForm()
        annotationOptionsForm = AnnotationImportOptionsForm()
        imageOptionsForm = ImageUploadOptionsForm(source=source)

    return render_to_response('images/image_and_annotation_upload.html', {
        'source': source,
        'annotationForm': annotationForm,
        'imageForm': imageForm,
        'annotationOptionsForm': annotationOptionsForm,
        'imageOptionsForm': imageOptionsForm,
        'uploadedImages': uploadedImages,
        },
        context_instance=RequestContext(request)
    )