예제 #1
0
 def testQDublinCoreElementNewHistory(self):
     '''Create a QualifiedDublinCoreElement, save it. No history yet.
     '''
     dct = QualifiedDublinCoreElement()
     dct.content_object = User.objects.get(pk=1)
     dct.term = 'T'
     dct.content = 'X'
     dct.save()
     self.failUnless(len(dct.history.all()) == 0)
     dct.content = 'Y'
     dct.save()
     self.failUnless(len(dct.history.all()) == 1)
예제 #2
0
 def testQDCE_extended_term_save(self):
     '''Test the saving of an extended term from the DCTERMS'''
     q=QualifiedDublinCoreElement()
     q.term = 'RH'
     q.content = 'XXXXX  TEXT XXXXX'
     q.object_id = 9
     q.content_type = ContentType.objects.get(app_label='auth', model='user')
     self.assertRaises(ValueError, q.save)
     q.term = 'T'
     q.save()
예제 #3
0
 def testQDublinCoreElementNewHistory(self):
     '''Create a QualifiedDublinCoreElement, save it. No history yet.
     '''
     dct = QualifiedDublinCoreElement()
     dct.content_object = User.objects.get(pk=1)
     dct.term = 'T'
     dct.content = 'X'
     dct.save()
     self.failUnless(len(dct.history.all()) == 0)
     dct.content = 'Y'
     dct.save()
     self.failUnless(len(dct.history.all()) == 1)
예제 #4
0
 def testTermsGrouped(self):
     ''' Test that the DC for an object is grouped by the term type
     ie all subject terms come in a row, all titles, etc.
     '''
     qdc = QualifiedDublinCoreElement()
     qdc.term = 'SUB'
     qdc.content = 'TEST'
     dcterms = QualifiedDublinCoreElement.objects.all()
     seen = defaultdict(int)
     curterm = dcterms[0].term
     for qdct in dcterms:
         if curterm != qdct.term:
             #switched or revisited
             if seen[qdct.term] == 1:
                 self.fail('Out of order term:%s' % qdct)
         curterm = qdct.term
         seen[qdct.term] = 1
예제 #5
0
 def testQDCE_extended_term_save(self):
     '''Test the saving of an extended term from the DCTERMS'''
     q=QualifiedDublinCoreElement()
     q.term = 'RH'
     q.content = 'XXXXX  TEXT XXXXX'
     q.object_id = 9
     q.content_type = ContentType.objects.get(app_label='auth', model='user')
     self.assertRaises(ValueError, q.save)
     q.term = 'T'
     q.save()
예제 #6
0
    def testTermsGrouped(self):
        ''' Test that the DC for an object is grouped by the term type
        ie all subject terms come in a row, all titles, etc.
        '''
#        arkobject = ARKObject.objects.get(pk=1)
        qdc = QualifiedDublinCoreElement()
        qdc.term = 'SUB'
        qdc.content = 'TEST'
#        arkobject.QDCElements.add(qdc)
#        dcterms = arkobject.QDCElements.all()
        dcterms = QualifiedDublinCoreElement.objects.all()
        seen = defaultdict(int)
        curterm = dcterms[0].term
        for qdct in dcterms:
            if curterm != qdct.term:
                #switched or revisited
                if seen[qdct.term] == 1:
                    #print arkobject.QDCElements.all()
                    self.fail('Out of order term:%s' % qdct)
            curterm = qdct.term
            seen[qdct.term] = 1
예제 #7
0
def add_collection_record(request):
    '''Add a collection record. Must be a logged in user supplemental with a 
    publishing institution.
    '''
    choices_publishing_institution = [ (i.id, i.name) for i in get_publishing_institutions_for_user(request.user) ]
    if request.method == 'POST':
        form_main  = CollectionRecordAddForm(request.POST)
        form_main.fields['publishing_institution'].choices = choices_publishing_institution 
        formset_person = CreatorPersonFormset(request.POST, prefix='person')
        formset_family = CreatorFamilyFormset(request.POST, prefix='family')
        formset_organization = CreatorOrganizationFormset(request.POST, prefix='organization')
        formset_topic = SubjectTopicFormset(request.POST, prefix='topic')
        formset_subject_person_name = SubjectPersonNameFormset(request.POST,
                prefix='subject_person_name')
        formset_subject_family_name = SubjectFamilyNameFormset(request.POST,
                prefix='subject_family_name')
        formset_subject_organization_name = SubjectOrganizationNameFormset(request.POST, prefix='subject_organization_name')
        formset_geog = GeographicFormset(request.POST, prefix='geog')
        formset_genre = GenreFormset(request.POST, prefix='genre')
        formset_subject_title = SubjectTitleFormset(request.POST, prefix='subject_title')
        formset_subject_function = SubjectFunctionFormset(request.POST, prefix='subject_function')
        formset_subject_occupation = SubjectOccupationFormset(request.POST, prefix='subject_occupation')
        formset_list = [ formset_person, formset_family, formset_organization,
                formset_topic, formset_subject_person_name,
                formset_subject_family_name, formset_subject_organization_name,
                formset_geog, formset_genre, formset_subject_title,
                formset_subject_function, formset_subject_occupation
                ]
        valid_formsets = False not in [x.is_valid() for x in formset_list]  
        if form_main.is_valid() and valid_formsets:
            #save collection and send to view/edit page?
            #check value of ark field in form. If it is blank or is still
            #the intial value, get a new ark
            # else validate ark or reject...
            ark = form_main.cleaned_data['ark']
            if ark == '' or ark == form_main.fields['ark'].initial:
                #mint an ark
                if OAC:
                    ark = EZIDMinter(1)[0]
                else:
                    ark = ''
            collection_record = CollectionRecord()
            collection_record.ark = ark
            collection_record.title = form_main.cleaned_data['title']
            collection_record.title_filing = form_main.cleaned_data['title_filing']
            collection_record.publisher_id = form_main.cleaned_data['publishing_institution']
            collection_record.date_dacs = form_main.cleaned_data['date_dacs']
            collection_record.date_iso = form_main.cleaned_data['date_iso']
            collection_record.local_identifier = form_main.cleaned_data['local_identifier']
            collection_record.extent = form_main.cleaned_data['extent']
            collection_record.abstract = form_main.cleaned_data['abstract']
            collection_record.language = form_main.cleaned_data['language']
            collection_record.accessrestrict = form_main.cleaned_data['accessrestrict']
            collection_record.userestrict = form_main.cleaned_data['userestrict']
            collection_record.acqinfo = form_main.cleaned_data['acqinfo']
            collection_record.scopecontent = form_main.cleaned_data['scopecontent']
            collection_record.bioghist = form_main.cleaned_data['bioghist']
            collection_record.online_items_url = form_main.cleaned_data['online_items_url']
            collection_record.full_clean()
            collection_record.save()
            # Now handle the DC elements forms, we have a valid
            # collection record to associate the QDC with
            for formset in formset_list:
                for form in formset:
                    if form.is_valid():
                        try:
                            content = form.cleaned_data['content']
                            qdce = QualifiedDublinCoreElement(term=form.term, qualifier=form.qualifier, content=content, content_object=collection_record)
                            qdce.full_clean()
                            qdce.save()
                        except KeyError:
                            pass
            return redirect(collection_record)
    else:
        form_main  = CollectionRecordAddForm()
        form_main.fields['publishing_institution'].choices = choices_publishing_institution 
        formset_person = CreatorPersonFormset(prefix='person')
        formset_family = CreatorFamilyFormset(prefix='family')
        formset_organization =CreatorOrganizationFormset(prefix='organization')
        formset_topic = SubjectTopicFormset(prefix='topic')
        formset_subject_person_name = SubjectPersonNameFormset(prefix='subject_person_name')
        formset_subject_family_name = SubjectFamilyNameFormset(prefix='subject_family_name')
        formset_subject_organization_name = SubjectOrganizationNameFormset(prefix='subject_organization_name')
        formset_geog = GeographicFormset(prefix='geog')
        formset_genre = GenreFormset(prefix='genre')
        formset_subject_title = SubjectTitleFormset(prefix='subject_title')
        formset_subject_function = SubjectFunctionFormset(prefix='subject_function')
        formset_subject_occupation = SubjectOccupationFormset(prefix='subject_occupation')
    return render(request,'collection_record/collection_record/add.html',
                              locals(),
                              )
예제 #8
0
def add_collection_record(request):
    '''Add a collection record. Must be a logged in user supplemental with a 
    publishing institution.
    '''
    choices_publishing_institution = [
        (i.id, i.name)
        for i in get_publishing_institutions_for_user(request.user)
    ]
    if request.method == 'POST':
        form_main = CollectionRecordAddForm(request.POST)
        form_main.fields[
            'publishing_institution'].choices = choices_publishing_institution
        formset_person = CreatorPersonFormset(request.POST, prefix='person')
        formset_family = CreatorFamilyFormset(request.POST, prefix='family')
        formset_organization = CreatorOrganizationFormset(
            request.POST, prefix='organization')
        formset_topic = SubjectTopicFormset(request.POST, prefix='topic')
        formset_subject_person_name = SubjectPersonNameFormset(
            request.POST, prefix='subject_person_name')
        formset_subject_family_name = SubjectFamilyNameFormset(
            request.POST, prefix='subject_family_name')
        formset_subject_organization_name = SubjectOrganizationNameFormset(
            request.POST, prefix='subject_organization_name')
        formset_geog = GeographicFormset(request.POST, prefix='geog')
        formset_genre = GenreFormset(request.POST, prefix='genre')
        formset_subject_title = SubjectTitleFormset(request.POST,
                                                    prefix='subject_title')
        formset_subject_function = SubjectFunctionFormset(
            request.POST, prefix='subject_function')
        formset_subject_occupation = SubjectOccupationFormset(
            request.POST, prefix='subject_occupation')
        formset_list = [
            formset_person, formset_family, formset_organization,
            formset_topic, formset_subject_person_name,
            formset_subject_family_name, formset_subject_organization_name,
            formset_geog, formset_genre, formset_subject_title,
            formset_subject_function, formset_subject_occupation
        ]
        valid_formsets = False not in [x.is_valid() for x in formset_list]
        if form_main.is_valid() and valid_formsets:
            #save collection and send to view/edit page?
            #check value of ark field in form. If it is blank or is still
            #the intial value, get a new ark
            # else validate ark or reject...
            ark = form_main.cleaned_data['ark']
            if ark == '' or ark == form_main.fields['ark'].initial:
                #mint an ark
                if OAC:
                    ark = EZIDMinter(1)[0]
                else:
                    ark = ''
            collection_record = CollectionRecord()
            collection_record.ark = ark
            collection_record.title = form_main.cleaned_data['title']
            collection_record.title_filing = form_main.cleaned_data[
                'title_filing']
            collection_record.publisher_id = form_main.cleaned_data[
                'publishing_institution']
            collection_record.date_dacs = form_main.cleaned_data['date_dacs']
            collection_record.date_iso = form_main.cleaned_data['date_iso']
            collection_record.local_identifier = form_main.cleaned_data[
                'local_identifier']
            collection_record.extent = form_main.cleaned_data['extent']
            collection_record.abstract = form_main.cleaned_data['abstract']
            collection_record.language = form_main.cleaned_data['language']
            collection_record.accessrestrict = form_main.cleaned_data[
                'accessrestrict']
            collection_record.userestrict = form_main.cleaned_data[
                'userestrict']
            collection_record.acqinfo = form_main.cleaned_data['acqinfo']
            collection_record.scopecontent = form_main.cleaned_data[
                'scopecontent']
            collection_record.bioghist = form_main.cleaned_data['bioghist']
            collection_record.online_items_url = form_main.cleaned_data[
                'online_items_url']
            collection_record.full_clean()
            collection_record.save()
            # Now handle the DC elements forms, we have a valid
            # collection record to associate the QDC with
            for formset in formset_list:
                for form in formset:
                    if form.is_valid():
                        try:
                            content = form.cleaned_data['content']
                            qdce = QualifiedDublinCoreElement(
                                term=form.term,
                                qualifier=form.qualifier,
                                content=content,
                                content_object=collection_record)
                            qdce.full_clean()
                            qdce.save()
                        except KeyError:
                            pass
            return redirect(collection_record)
    else:
        form_main = CollectionRecordAddForm()
        form_main.fields[
            'publishing_institution'].choices = choices_publishing_institution
        formset_person = CreatorPersonFormset(prefix='person')
        formset_family = CreatorFamilyFormset(prefix='family')
        formset_organization = CreatorOrganizationFormset(
            prefix='organization')
        formset_topic = SubjectTopicFormset(prefix='topic')
        formset_subject_person_name = SubjectPersonNameFormset(
            prefix='subject_person_name')
        formset_subject_family_name = SubjectFamilyNameFormset(
            prefix='subject_family_name')
        formset_subject_organization_name = SubjectOrganizationNameFormset(
            prefix='subject_organization_name')
        formset_geog = GeographicFormset(prefix='geog')
        formset_genre = GenreFormset(prefix='genre')
        formset_subject_title = SubjectTitleFormset(prefix='subject_title')
        formset_subject_function = SubjectFunctionFormset(
            prefix='subject_function')
        formset_subject_occupation = SubjectOccupationFormset(
            prefix='subject_occupation')
    return render(
        request,
        'collection_record/collection_record/add.html',
        locals(),
    )