示例#1
0
    def post(self, request):

         context = self.common(request)
         form = context['tempform']
         path = context['path']
         defaultrepository = context['defaultrepository']
         path_on_disk = context['path_on_disk']
         submission = context['dataset_submission']
         repo = get_object_or_404(Repository, id = submission.repository_id)
 
         try:
             opener = openers.get_opener(repo, request.user)
             # if this is a sword2 repository, hand off the management of that to 
             # the sword2 implementation

             if repo.type == "sword2":
               v_l.info("Using SWORDv2 depositor in post silos")
               s = Sword2()
               silos = s.get_silos(opener, repo)              
               print silos
               SILO_CHOICES = []
               for silo in silos:
                    SILO_CHOICES.append(silo.title)
               SILO_CHOICES.sort()
               form.instance.repository = repo
               form.instance.save()  # We have to save the form or the redirect will fail, FIXME: what are we saving here?

               if 'num' in request.REQUEST:
                  number = request.REQUEST.get('num')   
                  context ={ 'path': path,
                           'form': form,
                           'silos': SILO_CHOICES,
                           'path_on_disk': path_on_disk,
                           'dataset_submission': submission,
                           'num': number}
               else:
                  context ={'path': path,
                            'form': form,
                            'silos': SILO_CHOICES,
                            'path': path,
                            'path_on_disk': path_on_disk,
                            'defaultrepository':defaultrepository,
                            'dataset_submission': submission}    
               return self.render(request,context, 'dataset/submit')
         except SwordServiceError as e:
             raise
         except openers.SimpleCredentialsRequired:
                v_l.debug("Simple credentials required")
                print " Simple credentials required "
                form.instance.status = 'new'
                form.instance.save()  # We have to save the form or the redirect will fail, FIXME: what are we saving here?
                url = '%s?%s' % (
                            reverse('dataset:simple-credentials'),
                           urllib.urlencode({'next': '%s?%s' % (request.path, urllib.urlencode({'path': context['path'],
                                                                             'id': form.instance.id})),
                                   'repository': submission.repository_id}),
                )
                #return HttpResponseSeeOther(url)
                self.render(request,context, 'dataset/403')
示例#2
0
    def post(self, request):
        context = self.common(request)
        form = context["form"]

        if form.instance.status not in ("new", "submitted", "error"):
            return self.render(request, context, "dataset/submitted")

        if not form.is_valid():
            return self.render(request, context, "dataset/submit")

        form.save()
        dataset = form.instance.dataset

        cleaned_data = form.cleaned_data

        repository = cleaned_data["repository"]

        redirect_url = "/dataset/submission/%s?%s" % (form.instance.id, urllib.urlencode({"path": context["path"]}))

        # First thing is to try the preflight_submission

        if not context["num"]:
            try:
                opener = openers.get_opener(repository, request.user)
                form.instance.remote_url = dataset.preflight_submission(opener, repository)
            except openers.SimpleCredentialsRequired:
                # FIXME: If we get this error we HAVE to save the form, so we must
                # make sure that we undo any save operation if there is an error
                # later on...

                form.instance.status = "new"
                form.instance.save()  # We have to save the form or the redirect will fail, FIXME: what are we saving here?
                url = "%s?%s" % (
                    reverse("dataset:simple-credentials"),
                    urllib.urlencode(
                        {
                            "next": "%s?%s"
                            % (request.path, urllib.urlencode({"path": context["path"], "id": form.instance.id})),
                            "repository": repository.id,
                        }
                    ),
                )
                return HttpResponseSeeOther(url)
            except Dataset.DatasetIdentifierRejected, e:
                form.errors["identifier"] = ErrorList([unicode(e)])
                return self.render(request, context, "dataset/submit")
            except Exception as e:
                v_l.info("General failure during submission")
                form.errors["repository"] = ErrorList(
                    ["Failed to connect to repository for initial deposit; please try again later"]
                )
                return self.render(request, context, "dataset/submit")
示例#3
0
    def post(self, request):
        context = self.common(request)
        form = context['form']
        silo = context['reposilo']
        if form.instance.status not in ('new', 'submitted', 'error'):
            return self.render(request, context, 'dataset/submitted')

        if not form.is_valid():
            return self.render(request, context, 'dataset/submit')
        
        form.save()
        dataset = form.instance.dataset

        cleaned_data = form.cleaned_data

        repository = cleaned_data['repository']
        
        redirect_url = '/dataset/submission/%s?%s' % (form.instance.id, urllib.urlencode({'path': context['path']}))

        # First thing is to try the preflight_submission

        if not context['num']:
            v_l.info("Just before try in submit view")
            try:
                opener = openers.get_opener(repository, request.user)
                v_l.info("Just before preflight submission in submitview")
                form.instance.remote_url = dataset.preflight_submission(opener, repository, silo)
                v_l.info("Just after preflight submission in submitview")
                
            except openers.SimpleCredentialsRequired:
                # FIXME: If we get this error we HAVE to save the form, so we must
                # make sure that we undo any save operation if there is an error
                # later on...
                
                form.instance.status = 'new'
                form.instance.save()  # We have to save the form or the redirect will fail, FIXME: what are we saving here?
                url = '%s?%s' % (
                    reverse('dataset:simple-credentials'),
                    urllib.urlencode({'next': '%s?%s' % (request.path, urllib.urlencode({'path': context['path'],
                                                                                         'id': form.instance.id})),
                                      'repository': repository.id}),
                )
                return HttpResponseSeeOther(url)
            except Dataset.DatasetIdentifierRejected, e:
                form.errors['identifier'] = ErrorList([unicode(e)])
                return self.render(request, context, 'dataset/submit')
            except Exception as e:
                v_l.info("General failure during submission "+repr(e))
                form.errors['repository'] = ErrorList(["Failed to connect to repository for initial deposit; please try again later"])
                return self.render(request, context, 'dataset/submit')     
示例#4
0
    def post(self, request):
        context = self.common(request)
        form = context['form']
        dataset_submission = context['dataset_submission']
        if form.instance.status not in ('new', 'submitted', 'error'):
            return self.render(request, context, 'dataset/submitted')

        if not form.is_valid():
            return self.render(request, context, 'dataset/previous-submissions')
        
        form.save()
        dataset = form.instance.dataset

        cleaned_data = form.cleaned_data

        repository = cleaned_data['repository']
        
        redirect_url = '?%s' % urllib.urlencode({'path': context['path'],
                                                 'queued': 'true'})
        
        # First thing is to try the preflight_submission
                
        try:
            opener = openers.get_opener(repository, request.user)
            form.instance.remote_url = dataset.preflight_submission(opener, repository)
        except openers.SimpleCredentialsRequired:
        	# FIXME: If we get this error we HAVE to save the form, so we must
 	        # make sure that we undo any save operation if there is an error
            # later on...
                     
            form.instance.status = 'new'
            form.instance.save() # We have to save the form or the redirect will fail, FIXME: what are we saving here?
            url = '%s?%s' % (
                reverse('dataset:simple-credentials'),
                urllib.urlencode({'next': '%s?%s' % (request.path, urllib.urlencode({'path': context['path'],
                                                                                     'id': form.instance.id})),
                                  'repository': repository.id}),
            )
            return HttpResponseSeeOther(url)
        except Dataset.DatasetIdentifierRejected, e:
            form.errors['identifier'] = ErrorList([unicode(e)])
            return self.render(request, context, 'dataset/submit')
示例#5
0
    def process_item(self, client, pk):
        dataset_submission = DatasetSubmission.objects.get(pk=pk)
        
        logger.debug("Received submission request for %r to %r",
                    dataset_submission.identifier,
                    dataset_submission.remote_url)
                    #dataset_submission.repository.homepage)
        
        dataset = dataset_submission.dataset
        
        opener = openers.get_opener(dataset_submission.repository,
                                    dataset_submission.submitting_user)
        
        def update_status(status):
            logger.debug("Status updated to %r", status)
            dataset_submission.status = status
            dataset_submission.save()

        dataset.complete_submission(opener, dataset_submission, update_status)
        logger.info("Submission completed")
 def _check_dataset(self, dataset_submission):
     retry_counter = 0
     exception = None
     while retry_counter < SwordStatementCheckThread.retry_count:
         try:
            # logger.info("Checking state of dataset at " + dataset_submission.remote_url)
             
             opener = openers.get_opener(dataset_submission.repository,
                                     dataset_submission.submitting_user)
             conn = Connection(error_response_raises_exceptions=False, http_impl=UrlLib2Layer(opener))
             receipt = conn.get_deposit_receipt(dataset_submission.remote_url)
             statement = conn.get_ore_sword_statement(receipt.ore_statement_iri)
             for state_uri, state_desc in statement.states:
                 logger.info("Dataset has state URI: " + state_uri)
                 if state_uri in ERROR_STATES:
                     dataset_submission.status = 'error'
                     logger.info("URI: " + state_uri + " is an error state ... setting 'error' state on submission record")
                     break
             dataset_submission.last_accessed = datetime.datetime.now()
             dataset_submission.save()
             time.sleep(SwordStatementCheckThread.throttle)
     
         except urllib2.URLError as e:
             # if we get an exception, try again up to the limit
             logger.info("Got error connecting to the server ... retrying " + str(retry_counter + 1) + " of " + str(SwordStatementCheckThread.retry_count))
             retry_counter += 1
             exception = e
             time.sleep(SwordStatementCheckThread.retry_delay)
             continue
             
         else:
             # if we don't get an exception, we're done
             return
     
     # if we don't return from the else statement above, it means the retries
     # all failed, and we have a problem.  Raise the last thrown exception.
     raise exception
示例#7
0
    def post(self, request):
        context = self.common(request)
        form = context['form']
        submission = context['dataset_submission']
        if 'num' in request.REQUEST : 
        	num = context['num']

        #if form.instance.status not in ('new', 'submitted', 'error'):
        #    return self.render(request, context, 'dataset/submitted')

        if not form.is_valid():
            return self.render(request, context, 'dataset/submit')
        
        form.save()
        dataset = form.instance.dataset

        cleaned_data = form.cleaned_data
        
        defaultrepository = get_object_or_404(Repository, id=DefaultRepository.objects.all()[0].repository_id)
        #repository = cleaned_data['repository']
        silo  =   context['silo']
        repository =  defaultrepository
        
        redirect_url = '/dataset/submission/%s?%s' % (form.instance.id, urllib.urlencode({'path': context['path']}))

        # First thing is to try the preflight_submission

        if 'num'  in request.REQUEST : 
            form.instance.status = 'queued'
            form.instance.remote_url = submission.remote_url
            form.instance.queued_at = datastage.util.datetime.now()
            form.instance.save() # FIXME: what are we saving here?
        else:    
            try:
                opener = openers.get_opener(repository, request.user)
                v_l.debug("Got the urllib opener " )
                if repository.type == "sword2":
	                  (form.instance.alternate_url,form.instance.remote_url) = dataset.preflight_submission(opener, repository, silo)
                else:
                    form.instance.remote_url = dataset.preflight_submission(opener, repository, silo)
                form.instance.silo = silo
            except openers.SimpleCredentialsRequired:
	            # FIXME: If we get this error we HAVE to save the form, so we must
 	            # make sure that we undo any save operation if there is an error
                # later on...
                
	            form.instance.status = 'new'
	            form.instance.save()  # We have to save the form or the redirect will fail, FIXME: what are we saving here?
	            url = '%s?%s' % (
	                reverse('dataset:simple-credentials'),
	                urllib.urlencode({'next': '%s?%s' % (request.path, urllib.urlencode({'path': context['path'],
	                                                                                     'id': form.instance.id})),
	                                  'repository': repository.id}),
	            )
	            return HttpResponseSeeOther(url)
            except Dataset.DatasetIdentifierRejected, e:
	            form.errors['identifier'] = ErrorList([unicode(e)])
	            #return self.render(request, context, 'dataset/submit')
	            return self.rendersubmissionform(request,context)
            except Exception, e:
	            v_l.info("General failure during submission " )
	            form.errors['identifier'] = ErrorList([unicode(e)])
	            #form.errors['identifier'] = ErrorList(["Failed to connect to repository for initial deposit; please try again later"])
	            return self.rendersubmissionform(request,context)
示例#8
0
    def rendersubmissionform(self, request, context):
         form = context['form']
         path = context['path']
         
         defaultrepository = context['defaultrepository']
         path_on_disk = context['path_on_disk']
         submission = context['dataset_submission']
         repo = get_object_or_404(Repository, id = submission.repository_id)
         SILO_CHOICES = []
         try:
             opener = openers.get_opener(repo, request.user)
             # if this is a sword2 repository, hand off the management of that to 
             # the sword2 implementation
             silos = None 
             if repo.type == "sword2":
                v_l.debug("Using SWORDv2 depositor")
                s = Sword2()
                silos = s.get_silos(opener, repo)    
                for silo in silos:
                  SILO_CHOICES.append(silo.title)              
             else:
                # Retrieve all the accessible silos in the respository
                silos_file = opener.open(repo.homepage + 'silos', method='GET', headers={'Accept': "application/JSON"}) 
                silos= silos_file.read()
                silos_file.close()
                SILO_CHOICES = json.loads(silos)
             v_l.debug( "SILOS RECEIVED = " + repr(silos))            
             SILO_CHOICES.sort()
             form.instance.repository = repo
             form.instance.save()  # We have to save the form or the redirect will fail, FIXME: what are we saving here?

             if 'num' in request.REQUEST:
                number = request.REQUEST.get('num')   
                context ={ 'path': path,
                         'form': form,
                         'silos': SILO_CHOICES,
                         'defaultrepository':repo,
                         'path_on_disk': path_on_disk,
                         'dataset_submission': submission,
                         'num': number}
             else:
                context ={'path': path,
                          'form': form,
                          'silos': SILO_CHOICES,
                          'path': path,
                          'path_on_disk': path_on_disk,
                          'defaultrepository':defaultrepository,
                          'dataset_submission': submission}
                      
             return self.render(request,context, 'dataset/submit')
         except SwordServiceError as e:
             raise
         except openers.SimpleCredentialsRequired:
                v_l.debug("Simple credentials required")
                form.instance.status = 'new'
                form.instance.save()  # We have to save the form or the redirect will fail, FIXME: what are we saving here?
                url = '%s?%s' % (
                            reverse('dataset:simple-credentials'),
                           urllib.urlencode({'next': '%s?%s' % (request.path, urllib.urlencode({'path': context['path'],
                                                                             'id': form.instance.id})),
                                   'repository': submission.repository_id}),
                )
                return HttpResponseSeeOther(url)  
示例#9
0
    def post(self, request):
         context = self.common(request)
         form = context['tempform']
         path = context['path']
         path_on_disk = context['path_on_disk']
         submission = context['dataset_submission']
         repo = form['repository']
         #repo = get_object_or_404(Repository, name=submission.repository.name) 
         #repo = form.repository
         #return HttpResponseSeeOther( repr(repo))
         try:
             f = open('/tmp/debug.log', 'w')
             f.write('Before repo')
             #f.write("%s, %s"%('in num, path_on_disk))
             #f.write("%s, %s"%(path_parts, path_on_disk))
             #f.write("%s, %s"%('username',  request.user.username))
             #f.write("%s, %s"%('form',  repr(form)))

             repo = get_object_or_404(Repository, id="2")
             f.write('Before get Opener')
             opener = openers.get_opener(repo, request.user)
             f.write('After get Opener')
             f.close()
             # if this is a sword2 repository, hand off the management of that to 
             # the sword2 implementation
             if repo.type == "sword2":
               v_l.info("Using SWORDv2 depositor")
               s = Sword2()
               silos = s.get_silos(opener, repo)
               v_l.info(repr(silos))
               SILO_CHOICES = []
               for silo in silos:
                    SILO_CHOICES.append(silo.title)
               SILO_CHOICES.sort()
       
               form.instance.repository = repo 
               form.instance.save()  # We have to save the form or the redirect will fail, FIXME: what are we saving here?
               if 'num' in request.REQUEST:
                  number = request.REQUEST.get('num')   
                  context ={ 'path': path,
                           'form': form,
                           'silos': SILO_CHOICES,
                           'path_on_disk': path_on_disk,
                           'dataset_submission': submission,
                           'num': number}
               else:
                  context ={'path': path,
                            'form': form,
                            'silos': SILO_CHOICES,
                            'path': path,
                            'path_on_disk': path_on_disk,
                            'dataset_submission': submission}
                        
               return self.render(request,context, 'dataset/submit')
         except SwordServiceError as e:
             raise
         except openers.SimpleCredentialsRequired:
            # FIXME: If we get this error we HAVE to save the form, so we must
            # make sure that we undo any save operation if there is an error
            # later on...
            return self.render(request,context, 'dataset/submit')
示例#10
0
    def post(self, request):
        context = self.common(request)
        form = context['form']
        submission = context['dataset_submission']
        if 'num' in request.REQUEST:
            num = context['num']

        #if form.instance.status not in ('new', 'submitted', 'error'):
        #    return self.render(request, context, 'dataset/submitted')

        if not form.is_valid():
            return self.render(request, context, 'dataset/submit')

        form.save()
        dataset = form.instance.dataset

        cleaned_data = form.cleaned_data

        defaultrepository = get_object_or_404(
            Repository, id=DefaultRepository.objects.all()[0].repository_id)
        #repository = cleaned_data['repository']
        silo = context['silo']
        repository = defaultrepository

        redirect_url = '/dataset/submission/%s?%s' % (
            form.instance.id, urllib.urlencode({'path': context['path']}))

        # First thing is to try the preflight_submission

        if 'num' in request.REQUEST:
            form.instance.status = 'queued'
            form.instance.remote_url = submission.remote_url
            form.instance.queued_at = datastage.util.datetime.now()
            form.instance.save()  # FIXME: what are we saving here?
        else:
            try:
                opener = openers.get_opener(repository, request.user)
                v_l.debug("Got the urllib opener ")
                if repository.type == "sword2":
                    (form.instance.alternate_url,
                     form.instance.remote_url) = dataset.preflight_submission(
                         opener, repository, silo)
                else:
                    form.instance.remote_url = dataset.preflight_submission(
                        opener, repository, silo)
                form.instance.silo = silo
            except openers.SimpleCredentialsRequired:
                # FIXME: If we get this error we HAVE to save the form, so we must
                # make sure that we undo any save operation if there is an error
                # later on...

                form.instance.status = 'new'
                form.instance.save(
                )  # We have to save the form or the redirect will fail, FIXME: what are we saving here?
                url = '%s?%s' % (
                    reverse('dataset:simple-credentials'),
                    urllib.urlencode({
                        'next':
                        '%s?%s' % (request.path,
                                   urllib.urlencode({
                                       'path': context['path'],
                                       'id': form.instance.id
                                   })),
                        'repository':
                        repository.id
                    }),
                )
                return HttpResponseSeeOther(url)
            except Dataset.DatasetIdentifierRejected, e:
                form.errors['identifier'] = ErrorList([unicode(e)])
                #return self.render(request, context, 'dataset/submit')
                return self.rendersubmissionform(request, context)
            except Exception, e:
                v_l.info("General failure during submission ")
                form.errors['identifier'] = ErrorList([unicode(e)])
                #form.errors['identifier'] = ErrorList(["Failed to connect to repository for initial deposit; please try again later"])
                return self.rendersubmissionform(request, context)
示例#11
0
    def rendersubmissionform(self, request, context):
        form = context['form']
        path = context['path']

        defaultrepository = context['defaultrepository']
        path_on_disk = context['path_on_disk']
        submission = context['dataset_submission']
        repo = get_object_or_404(Repository, id=submission.repository_id)
        SILO_CHOICES = []
        try:
            opener = openers.get_opener(repo, request.user)
            # if this is a sword2 repository, hand off the management of that to
            # the sword2 implementation
            silos = None
            if repo.type == "sword2":
                v_l.debug("Using SWORDv2 depositor")
                s = Sword2()
                silos = s.get_silos(opener, repo)
                for silo in silos:
                    SILO_CHOICES.append(silo.title)
            else:
                # Retrieve all the accessible silos in the respository
                silos_file = opener.open(
                    repo.homepage + 'silos',
                    method='GET',
                    headers={'Accept': "application/JSON"})
                silos = silos_file.read()
                silos_file.close()
                SILO_CHOICES = json.loads(silos)
            v_l.debug("SILOS RECEIVED = " + repr(silos))
            SILO_CHOICES.sort()
            form.instance.repository = repo
            form.instance.save(
            )  # We have to save the form or the redirect will fail, FIXME: what are we saving here?

            if 'num' in request.REQUEST:
                number = request.REQUEST.get('num')
                context = {
                    'path': path,
                    'form': form,
                    'silos': SILO_CHOICES,
                    'defaultrepository': repo,
                    'path_on_disk': path_on_disk,
                    'dataset_submission': submission,
                    'num': number
                }
            else:
                context = {
                    'path': path,
                    'form': form,
                    'silos': SILO_CHOICES,
                    'path': path,
                    'path_on_disk': path_on_disk,
                    'defaultrepository': defaultrepository,
                    'dataset_submission': submission
                }

            return self.render(request, context, 'dataset/submit')
        except SwordServiceError as e:
            raise
        except openers.SimpleCredentialsRequired:
            v_l.debug("Simple credentials required")
            form.instance.status = 'new'
            form.instance.save(
            )  # We have to save the form or the redirect will fail, FIXME: what are we saving here?
            url = '%s?%s' % (
                reverse('dataset:simple-credentials'),
                urllib.urlencode({
                    'next':
                    '%s?%s' % (request.path,
                               urllib.urlencode({
                                   'path': context['path'],
                                   'id': form.instance.id
                               })),
                    'repository':
                    submission.repository_id
                }),
            )
            return HttpResponseSeeOther(url)