예제 #1
0
파일: tests.py 프로젝트: ucldc/avram
 def testRepositoryModelExists(self):
     r = Repository()
     r.name = "test repo"
     r.save()
     self.assertTrue(hasattr(r, "slug"))
     self.assertTrue(hasattr(r, "ark"))
     self.assertTrue(hasattr(r, "google_analytics_tracking_code"))
예제 #2
0
파일: views.py 프로젝트: ucldc/avram
def edit_repositories(request, campus_slug=None, error=None):
    campus = None
    if campus_slug:
        campus = get_object_or_404(Campus, slug=campus_slug)
        repositoryObjs = Repository.objects.filter(campus=campus).order_by('name')
    else:
        repositoryObjs = Repository.objects.all().order_by('name')
        
    if (request.method == 'POST'):
        requestObj = request.POST
        if ('edit' in requestObj or error):
            context = {
                'campuses': campuses,
                'current_path': request.path,
                'editing': editing(request.path),
                'edit': 'true',
                'repositories': repositoryObjs
            }
            if error:
                context['error'] = error
                if 'campuses' in requestObj:
                    campus = []
                    for campus_id in requestObj.getlist('campuses'):
                        campus.append(Campus.objects.get(pk=campus_id))
                    context['campus_list'] = campus
                if 'name' in requestObj:
                    context['repository'] = {'name': requestObj['name']}
                
            return render(request,
                template_name='library_collection/repository_list.html',
                context=context
            )
        else: 
            try: 
                new_repository = Repository(name = requestObj['name'])
                validated = new_repository.full_clean()
            except ValidationError as e:
                return edit_repositories(request, error='Please enter a unit title')
            
            if len(requestObj.getlist('campuses')) < 1:
               return edit_repositories(request, error='Please enter at least one campus')
            
            new_repository.save()
            new_repository.campus.set(requestObj.getlist('campuses'))
            
            return render(request, template_name='library_collection/repository_list.html', 
                context={
                    'campus': campus,
                    'repositories': repositoryObjs,
                    'campuses': campuses,
                    'active_tab': active_tab(request),
                    'current_path': request.path,
                    'editing': editing(request.path),
                },
            )
    
    return repositories(request, campus_slug)
예제 #3
0
파일: tests.py 프로젝트: ucldc/avram
 def setUp(self):
     r = Repository()
     r.name = "TEST REPO"
     r.save()
     u = User.objects.create_user("test", "*****@*****.**", password="******")
     u.is_superuser = True
     u.is_active = True
     u.is_staff = True  # needs to be staff to access admin
     u.save()
예제 #4
0
파일: tests.py 프로젝트: ucldc/avram
 def testRepositoryNoDupArks(self):
     """Check that the Repostiories can't have duplicate arks.
     Again, since it is a char & we allow blank, can't use db unique
     check"""
     r = Repository()
     r.name = "test repo"
     r.ark = "fakeARK"
     r.save()
     r2 = Repository()
     r2.name = "test repo"
     r2.ark = "fakeARK"
     self.assertRaises(ValueError, r2.save)
     try:
         r2.save()
     except ValueError, e:
         self.assertEqual(e.args, ("Unit with ark fakeARK already exists",))
예제 #5
0
def main(url_oac_repo_list=URL_OAC_REPO_LIST ):
    '''Synchronize the OAC institutions and the registry repositories'''
    n = n_up = n_new = 0 

    # read the JSON from an API URL
    repo_list = json.loads(urllib.urlopen(url_oac_repo_list).read())

    for name, ark, parent_ark, parent_name in repo_list:

        # try/except idomatic python; but maybe refactor to use .exists()
        non_uc = not(Campus.objects.filter(ark=parent_ark).exists())

        if non_uc and parent_name:
            full_name = u', '.join([parent_name, name])
        else:
            full_name = name

        # see if repo exists, if not create it
        try:
            repo = Repository.objects.get(ark=ark)
            # udpate name?, only report update when this is true
            if repo.name != full_name:
                repo.name = full_name
                repo.save()
                n_up += 1
        except Repository.DoesNotExist:
            repo = Repository(name=full_name, ark=ark)
            repo.save()
            n_new += 1
            repo = Repository.objects.get(ark=ark)

        # add campus link (UC's)
        if parent_ark:
            try:
                campus = Campus.objects.get(ark=parent_ark)
                repo.campus.add(campus)
                repo.save()
            except Campus.DoesNotExist:
                pass

        n += 1
    # return for unit tests
    return n, n_up, n_new
예제 #6
0
def main(url_oac_repo_list=URL_OAC_REPO_LIST):
    '''Synchronize the OAC institutions and the registry repositories'''
    n = n_up = n_new = 0

    # read the JSON from an API URL
    repo_list = json.loads(urllib.urlopen(url_oac_repo_list).read())

    for name, ark, parent_ark, parent_name in repo_list:

        # try/except idomatic python; but maybe refactor to use .exists()
        non_uc = not (Campus.objects.filter(ark=parent_ark).exists())

        if non_uc and parent_name:
            full_name = u', '.join([parent_name, name])
        else:
            full_name = name

        # see if repo exists, if not create it
        try:
            repo = Repository.objects.get(ark=ark)
            # udpate name?, only report update when this is true
            if repo.name != full_name:
                repo.name = full_name
                repo.save()
                n_up += 1
        except Repository.DoesNotExist:
            repo = Repository(name=full_name, ark=ark)
            repo.save()
            n_new += 1
            repo = Repository.objects.get(ark=ark)

        # add campus link (UC's)
        if parent_ark:
            try:
                campus = Campus.objects.get(ark=parent_ark)
                repo.campus.add(campus)
                repo.save()
            except Campus.DoesNotExist:
                pass

        n += 1
    # return for unit tests
    return n, n_up, n_new
예제 #7
0
파일: views.py 프로젝트: ucldc/avram
def edit_repositories(request, campus_slug=None, error=None):
    campus = None
    if campus_slug:
        campus = get_object_or_404(Campus, slug=campus_slug)
        repositoryObjs = Repository.objects.filter(
            campus=campus).order_by('name')
    else:
        repositoryObjs = Repository.objects.all().order_by('name')

    if (request.method == 'POST'):
        requestObj = request.POST
        if ('edit' in requestObj or error):
            context = {
                'campuses': campuses,
                'current_path': request.path,
                'editing': editing(request.path),
                'edit': 'true',
                'repositories': repositoryObjs
            }
            if error:
                context['error'] = error
                if 'campuses' in requestObj:
                    campus = []
                    for campus_id in requestObj.getlist('campuses'):
                        campus.append(Campus.objects.get(pk=campus_id))
                    context['campus_list'] = campus
                if 'name' in requestObj:
                    context['repository'] = {'name': requestObj['name']}

            return render(
                request,
                template_name='library_collection/repository_list.html',
                context=context)
        else:
            try:
                new_repository = Repository(name=requestObj['name'])
                validated = new_repository.full_clean()
            except ValidationError as e:
                return edit_repositories(request,
                                         error='Please enter a unit title')

            if len(requestObj.getlist('campuses')) < 1:
                return edit_repositories(
                    request, error='Please enter at least one campus')

            new_repository.save()
            new_repository.campus.set(requestObj.getlist('campuses'))

            return render(
                request,
                template_name='library_collection/repository_list.html',
                context={
                    'campus': campus,
                    'repositories': repositoryObjs,
                    'campuses': campuses,
                    'current_path': request.path,
                    'editing': editing(request.path),
                },
            )

    return repositories(request, campus_slug)