コード例 #1
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()
コード例 #2
0
ファイル: tests.py プロジェクト: hydroshare/django-dublincore
 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
ファイル: tests.py プロジェクト: hydroshare/django-dublincore
 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)
コード例 #5
0
ファイル: views.py プロジェクト: cdlib/RecordExpress
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(),
                              )
コード例 #6
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(),
    )