Commit 63eeb611 authored by Sean Leavey's avatar Sean Leavey
Browse files

Add required methods for web server

parent 7f269f78
Pipeline #347973 passed with stages
in 2 minutes and 42 seconds
......@@ -5,11 +5,13 @@ from typing import List
from pathlib import Path
import shutil
from dataclasses import dataclass, field, asdict
from collections import defaultdict
from itertools import takewhile
from functools import total_ordering, wraps
import datetime
import tomli
import tomli_w
from html2text import html2text
from .sessions import DCCSession
from .parsers import DCCXMLRecordParser, DCCXMLUpdateParser
from .util import opened_file, remove_none
......@@ -72,6 +74,22 @@ class DCCArchive:
# Not a valid DCC number.
pass
@property
def documents_by_category(self):
"""The documents in the local archive, grouped by category.
Returns
-------
:class:`dict`
DCC numbers in each category in the local archive, keyed by category.
"""
cats = defaultdict(list)
for number in self.documents:
cats[number.category].append(number)
return cats
@property
def records(self):
"""Records in the local archive, including revisions.
......@@ -85,6 +103,22 @@ class DCCArchive:
path = self.document_dir(document)
yield from self.revisions(path.name)
@property
def records_by_category(self):
"""The records in the local archive, grouped by category.
Returns
-------
:class:`dict`
DCC records in each category in the local archive, keyed by category.
"""
cats = defaultdict(list)
for record in self.records:
cats[record.dcc_number.category].append(record)
return cats
@ensure_session
def fetch_record(
self,
......@@ -798,6 +832,16 @@ class DCCRecord:
self.referenced_by = list(takewhile(pred, self.referenced_by))
self.related_to = list(takewhile(pred, self.related_to))
@property
def text_abstract(self):
"""The abstract in text form."""
return html2text(self.abstract) if self.abstract else ""
@property
def text_note(self):
"""The note in text form."""
return html2text(self.note) if self.note else ""
@classmethod
@ensure_session
def fetch(cls, dcc_number, *, session):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment