Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Sean Leavey
dcc
Commits
63eeb611
Commit
63eeb611
authored
Jan 22, 2022
by
Sean Leavey
Browse files
Add required methods for web server
parent
7f269f78
Pipeline
#347973
passed with stages
in 2 minutes and 42 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
dcc/records.py
View file @
63eeb611
...
...
@@ -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
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment