How to use the capstone.capdb.models.Citation function in capstone

To help you get started, we’ve selected a few capstone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github harvard-lil / capstone / capstone / capdb / models.py View on Github external
def save(self, *args, **kwargs):
        if self.tracker.has_changed('cite'):
            self.normalized_cite = normalize_cite(self.cite)
        super(Citation, self).save(*args, **kwargs)
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
"citation_text": "{} {} {}".format(volume_metadata.volume_number, reporter.short_name,
                                                   data["first_page"]),
                "is_duplicative": True,
            }]
        else:
            citations = data['citations']

        # update or create each citation
        for citation in citations:
            if citation['citation_text'] in existing_cites:
                cite = existing_cites.pop(citation['citation_text'])
                cite.cite = citation['citation_text']
                cite.type = citation['citation_type']
                cite.duplicative = citation['is_duplicative']
            else:
                cite = Citation(
                    cite=citation['citation_text'],
                    type=citation['citation_type'],
                    duplicative=citation['is_duplicative'],
                    case=case_metadata,
                )
            if cite.tracker.changed():
                cite.save()

        # clean up unused existing cites
        Citation.objects.filter(pk__in=[cite.pk for cite in existing_cites.values()]).delete()

        # create link between casexml and metadata
        if metadata_created:
            self.metadata = case_metadata
            if save_self:
                self.save(update_fields=['metadata'])
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
def parsed(self):
        return Citation.parse_cite(self.cite)
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
def citations_by_type(self):
        return Citation.sorted_by_type(self.citations.all())
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
def save(self, *args, **kwargs):
        if not self.id and not self.slug:
            self.slug = generate_unique_slug(self, self.cite)
        super(Citation, self).save(*args, **kwargs)
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
volume_metadata = self.volume.volume_metadata
        reporter = volume_metadata.reporter

        # we have to create citations first because case slug field relies on citation
        citations = list()

        if not duplicative_case:
            for citation_type, citation_text in data['citations'].items():
                cite, created = Citation.objects.get_or_create(
                    cite=citation_text,
                    type=citation_type,
                    duplicative=False)
                citations.append(cite)
        else:
            cite, created = Citation.objects.get_or_create(
                cite="{} {} {}".format(volume_metadata.volume_number, reporter.short_name, data["first_page"]),
                type="official", duplicative=True)
            citations.append(cite)

        # avoid get_or_create because that's tricky to use while generating a unique slug
        try:
            case_metadata = CaseMetadata.objects.get(case_id=self.case_id)
        except CaseMetadata.DoesNotExist:
            case_metadata = CaseMetadata(case_id=self.case_id)

        case_metadata.reporter = reporter
        case_metadata.volume = volume_metadata
        case_metadata.duplicative = duplicative_case
        case_metadata.first_page = data["first_page"]
        case_metadata.last_page = data["last_page"]
        case_metadata.name = data["name"]
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
def set_duplicate(self, duplicate_of):
        """
            Update this volume to reflect that it is a duplicate of another volume.
            Update volume.case_metadatas.duplicate and .in_scope to match.
        """
        #TODO: PDF renaming/deleting functionality
        with transaction.atomic(using='capdb'):
            self.duplicate = True
            self.duplicate_of = duplicate_of
            self.save()
            self.case_metadatas.update(duplicate=True)
            self.case_metadatas.update_in_scope()
            CaseMetadata.update_frontend_urls(Citation.objects.filter(type='official', case__volume=self).values_list('cite', flat=True))
            CaseMetadata.reindex_cases(self.case_metadatas.for_indexing())
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
if first_page and first_page.label:
                citations = [{
                    'category': 'official',
                    'type': 'bluebook',
                    'text': "{} {} {}".format(self.volume.volume_number, self.reporter.short_name, first_page.label),
                    'duplicative': True,
                }]
            else:
                citations = []
        else:
            citations = data['citations']

        # create each citation
        self.citations.all().delete()
        if citations:
            Citation.objects.bulk_create(Citation(
                cite=citation['text'],
                normalized_cite=normalize_cite(citation['text']),
                type=citation['category'],
                category=citation['type'],
                duplicative=citation.get('duplicative', False),
                case=self,
            ) for citation in citations)