How to use the capstone.capdb.models.CaseMetadata 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):
        # Ordinarily we would set slug here for new objects, but we can't because it's based on self.citations,
        # which is a many-to-many that can't exist until the object is saved.
        super(CaseMetadata, self).save(*args, **kwargs)
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
def create_or_update_metadata(self, update_existing=True, save_self=True):
        """
            creates or updates CaseMetadata object
            - if we want to skip over updating existing case metadata objects
            method returns out.
            - otherwise, create or overwrite properties on related metadata object
        """

        # get or create case.metadata
        if self.metadata_id:
            if not update_existing:
                return
            case_metadata = self.metadata
            metadata_created = False
        else:
            case_metadata = CaseMetadata()
            metadata_created = True

        # set up data
        data, parsed = get_case_metadata(force_str(self.orig_xml))
        duplicative_case = data['duplicative']
        volume_metadata = self.volume.metadata
        reporter = volume_metadata.reporter

        # set case_metadata attributes
        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.case_id = data["case_id"]
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
case.update_related_sums(self.short_id, self.get_md5(), str(self.get_size()))
                    case.save()
        super(PageXML, self).save(force_insert, force_update, *args, **kwargs)

    def __str__(self):
        return self.barcode

    @property
    def short_id(self):
        """ ID of this page as referred to by volume xml file. """
        return short_id_from_s3_key(self.s3_key)


class ExtractedCitation(models.Model):
    cite = models.CharField(max_length=10000)
    cited_by = models.ForeignKey(CaseMetadata, related_name='extractedcitations', on_delete=models.DO_NOTHING)
    reporter_name_original = models.CharField(max_length=200)
    volume_number_original = models.CharField(max_length=64, blank=True, null=True)
    page_number_original = models.CharField(max_length=64, null=True, blank=True)
    normalized_cite = models.SlugField(max_length=10000, null=True, db_index=True)

    def __str__(self):
        return self.cite

    def save(self, *args, **kwargs):
        self.normalized_cite = normalize_cite(self.cite)
        return super(ExtractedCitation, self).save(*args, **kwargs)


class DataMigration(models.Model):
    data_migration_timestamp = models.DateTimeField(auto_now_add=True)
    transaction_timestamp = models.DateTimeField()
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
"""
            Update this volume's reporter.
            Update volume.case_metadatas.reporter to match.
        """
        #TODO: PDF renaming functionality
        with transaction.atomic(using='capdb'):
            old_reporter = self.reporter
            self.reporter = reporter
            self.save()
            self.case_metadatas.update(reporter=reporter)
            if update_citations:
                Citation.replace_reporter(
                    Citation.objects.filter(case__volume=self, type="official"),
                    old_reporter.short_name,
                    self.reporter.short_name)
            CaseMetadata.reindex_cases(self.case_metadatas.for_indexing())
github harvard-lil / capstone / capstone / capdb / admin.py View on Github external
Admin will report 1000000 entries if the real number is not available.
    """
    def get_queryset(self, request):
        qs = super().get_queryset(request)
        qs.__class__ = CachedCountDefaultQuerySet
        return qs


### admin models ###

@admin.register(VolumeXML)
class VolumeXMLAdmin(SimpleHistoryAdmin):
    raw_id_fields = ['metadata']


@admin.register(CaseMetadata)
class CaseMetadataAdmin(CachedCountMixin, admin.ModelAdmin):
    list_display = ['name_abbreviation', 'decision_date', 'jurisdiction', 'court', 'reporter']
    list_select_related = ('jurisdiction', 'court', 'reporter')
    inlines = (
        new_class('CitationInline', ReadonlyInlineMixin, admin.TabularInline, model=Citation),
        new_class('CaseXMLInline', admin.StackedInline, model=CaseXML, raw_id_fields=['volume']),
    )
    fieldsets = (
        ('Flags', {
            'fields': ('duplicate', 'duplicate_of', 'no_index', 'no_index_notes',
                       'no_index_elided', 'no_index_redacted',
                       'robots_txt_until', 'withdrawn', 'replaced_by', 'in_scope', 'custom_footer_message'),
        }),
        ('Metadata', {
            'fields': ('docket_number', 'decision_date', 'decision_date_original', 'name_abbreviation', 'name',),
        }),
github harvard-lil / capstone / capstone / capdb / admin.py View on Github external
Admin will report 1000000 entries if the real number is not available.
    """
    def get_queryset(self, request):
        qs = super().get_queryset(request)
        qs.__class__ = CachedCountDefaultQuerySet
        return qs


### admin models ###

@admin.register(VolumeXML)
class VolumeXMLAdmin(SimpleHistoryAdmin):
    raw_id_fields = ['metadata']


@admin.register(CaseMetadata)
class CaseMetadataAdmin(CachedCountMixin, admin.ModelAdmin):
    list_display = ['name_abbreviation', 'decision_date', 'jurisdiction', 'court', 'reporter']
    list_select_related = ('jurisdiction', 'court', 'reporter')
    inlines = (
        new_class('CitationInline', ReadonlyInlineMixin, admin.TabularInline, model=Citation),
        new_class('CaseXMLInline', admin.StackedInline, model=CaseXML, raw_id_fields=['volume']),
    )
    fieldsets = (
        ('Flags', {
            'fields': ('duplicate', 'duplicate_of', 'no_index',  'no_index_notes', 'no_index_redacted', 'no_index_elided',
                       'withdrawn', 'replaced_by', 'in_scope', 'custom_footer_message',),
        }),
        ('', {
            'fields': ('frontend_url',)
        }),
        ('Ingest metadata', {
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
def reindex(self):
        CaseMetadata.reindex_cases([self])
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
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"]
        case_metadata.name_abbreviation = data["name_abbreviation"]

        # set slug to official citation, or first citation if there is no official
        citation_to_slugify = next((c for c in citations if c.type == 'official'), citations[0])
        case_metadata.slug = generate_unique_slug(case_metadata, citation_to_slugify.cite)

        # save here so we can add citation relationships before possibly returning
        case_metadata.save()
github harvard-lil / capstone / capstone / capdb / models.py View on Github external
class CaseInitialMetadata(models.Model):
    """
        Initial metadata for case, provided by Innodata.
    """
    case = models.OneToOneField(CaseMetadata, on_delete=models.DO_NOTHING, related_name='initial_metadata')
    metadata = JSONField()

    ingest_source = models.ForeignKey(TarFile, on_delete=models.DO_NOTHING)
    ingest_path = models.CharField(max_length=1000)


class CaseBodyCache(models.Model):
    """
    Renditions of a case.
    """
    metadata = models.OneToOneField(CaseMetadata, related_name='body_cache', on_delete=models.CASCADE)
    text = models.TextField(blank=True, null=True)
    html = models.TextField(blank=True, null=True)
    xml = models.TextField(blank=True, null=True)
    json = JSONField(blank=True, null=True)


class EditLog(models.Model):
    """
        Record a set of edits. Simple usage:

            with EditLog(description='message').record():
                volume.save()

        Advanced usage:

            with EditLog(description='message').record(auto_transaction=False) as edit: