Skip to content

Commit

Permalink
api: some linting
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Apr 6, 2024
1 parent d6edaa8 commit db46411
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions mpcontribs-api/mpcontribs/api/contributions/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def format_cell(cell):
q = truncate_digits(q)
try:
return str(q.nominal_value) if isnan(q.std_dev) else str(q)
except:
except Exception:
return cell


Expand Down Expand Up @@ -150,15 +150,15 @@ class Contributions(DynamicDocument):
)
needs_build = BooleanField(default=True, help_text="needs notebook build?")
data = DictField(
default=dict, validation=valid_dict, pullout_key="display",
default=dict,
validation=valid_dict,
pullout_key="display",
help_text="simple free-form data",
)
structures = ListField(
ReferenceField("Structures", null=True), default=list, max_length=10
)
tables = ListField(
ReferenceField("Tables", null=True), default=list, max_length=10
)
tables = ListField(ReferenceField("Tables", null=True), default=list, max_length=10)
attachments = ListField(
ReferenceField("Attachments", null=True), default=list, max_length=10
)
Expand All @@ -167,30 +167,42 @@ class Contributions(DynamicDocument):
meta = {
"collection": "contributions",
"indexes": [
"project", "identifier", "formula", "is_public", "last_modified",
"needs_build", "notebook", {"fields": [(r"data.$**", 1)]},
"project",
"identifier",
"formula",
"is_public",
"last_modified",
"needs_build",
"notebook",
{"fields": [(r"data.$**", 1)]},
# can only use wildcardProjection option with wildcard index on all document fields
{"fields": [(r"$**", 1)], "wildcardProjection" : {"project": 1}},
] + list(COMPONENTS.keys()),
{"fields": [(r"$**", 1)], "wildcardProjection": {"project": 1}},
]
+ list(COMPONENTS.keys()),
}

@queryset_manager
def objects(doc_cls, queryset):
return queryset.no_dereference().only(
"project", "identifier", "formula", "is_public", "last_modified", "needs_build"
"project",
"identifier",
"formula",
"is_public",
"last_modified",
"needs_build",
)

@classmethod
def atlas_filter(cls, term):
try:
comp = Composition(term)
except:
except Exception:
raise ValueError(f"{term} is not a valid composition")

try:
for element in comp.elements:
Element(element)
except:
except Exception:
raise ValueError(f"{element} not a valid element")

ind_str = []
Expand All @@ -200,14 +212,11 @@ def atlas_filter(cls, term):
ind_str.append(d[0] + str(int(d[1])) if d[1] != 1 else d[0])
else:
for i, j in comp.reduced_composition.items():
ind_str.append(
i.name + str(int(j)) if j != 1 else i.name
)
ind_str.append(i.name + str(int(j)) if j != 1 else i.name)

final_terms = ["".join(entry) for entry in permutations(ind_str)]
return AtlasQ(formula=final_terms[0]) # TODO formula__in=final_terms


@classmethod
def post_init(cls, sender, document, **kwargs):
# replace existing components with according ObjectIds
Expand Down

0 comments on commit db46411

Please sign in to comment.