Skip to content

Commit

Permalink
refactor: minor hygiene
Browse files Browse the repository at this point in the history
- use f strings instead of format for simple interpolation
- adjust peer review success email, we really will get it done by Q2
  2024... really
- remove dead imports
  • Loading branch information
alee committed Oct 19, 2023
1 parent c231f24 commit a3990ca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
4 changes: 1 addition & 3 deletions django/library/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
PeerReviewerFeedback,
PeerReviewInvitation,
ReviewerRecommendation,
ReviewStatus,
)

logger = logging.getLogger(__name__)
Expand All @@ -20,8 +19,7 @@ class PeerReviewInvitationForm(forms.ModelForm):
"""

def save(self, commit=True):
invitation = super().save(commit)
return invitation
return super().save(commit)

class Meta:
model = PeerReviewInvitation
Expand Down
27 changes: 14 additions & 13 deletions django/library/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __bool__(self):
return len(self.msgs) > 0

def __repr__(self):
return "<MessageGroup {0}>".format(repr(self.msgs))
return f"<MessageGroup {repr(self.msgs)}>"

def append(self, msg: Optional):
if msg is not None and msg:
Expand Down Expand Up @@ -189,7 +189,7 @@ def __init__(
def validate_system_file(self, name, content) -> Optional[Message]:
# FIXME: do we expect validate_file being run on full paths?
if fs.has_system_files(name):
return self.error("Ignored system file '{}'".format(name))
return self.error(f"Ignored system file '{name}'")
return None

def validate_mimetype(self, name):
Expand All @@ -198,7 +198,7 @@ def validate_mimetype(self, name):
mimetype = mimetype if mimetype else "*/*"
if not mimetype_matcher.match(mimetype):
return create_fs_message(
"Ignored file '{}'. File type mismatch.".format(name),
f"Ignored file '{name}': invalid filetype {mimetype}",
self.stage,
self.mimetype_mismatch_message_level,
)
Expand Down Expand Up @@ -438,7 +438,7 @@ def get_stage_storage(self, stage: StagingDirectories):
elif stage == StagingDirectories.aip:
return self.get_aip_storage()
else:
raise ValueError("StageDirectories values {} not valid".format(stage))
raise ValueError(f"StageDirectories values {stage} not valid")

def get_sip_list_url(self, category: FileCategoryDirectories):
return reverse(
Expand Down Expand Up @@ -603,7 +603,7 @@ def delete(self, category: FileCategoryDirectories, relpath: Path):
if not originals_storage.exists(str(relpath)):
logs.append(
create_fs_message(
"No file at path {} to delete".format(str(relpath)),
f"No file at path {relpath} to delete",
StagingDirectories.originals,
MessageLevels.error,
)
Expand All @@ -623,14 +623,14 @@ def _add_to_sip(self, name, content, category: FileCategoryDirectories):
return sip_storage.log_save(name=name, content=content)

def add_category(self, category: FileCategoryDirectories, src):
logger.info("adding category {}".format(category.name))
logger.info("adding category %s", category.name)
originals_storage = self.get_originals_storage()
msgs = self._create_msg_group()
for dirpath, dirnames, filenames in os.walk(src):
for filename in filenames:
filename = os.path.join(dirpath, filename)
name = os.path.join(category.name, str(Path(filename).relative_to(src)))
logger.debug("adding file {}".format(name))
logger.debug("adding file %s", name)
with open(filename, "rb") as content:
msgs.append(originals_storage.log_save(name, content))
return msgs
Expand All @@ -655,7 +655,7 @@ def add(self, category: FileCategoryDirectories, content, name=None):
def copy_originals(self, source_release):
"""copy all original files from a source CodebaseRelease to the calling release"""
logger.info(
"copying files from version %s to version %s for codebase %s",
"copying files from source version %s to version %s for codebase %s",
source_release.version_number,
self.version_number,
self.identifier,
Expand Down Expand Up @@ -687,7 +687,7 @@ def build_sip(self, originals_dir: Optional[str] = None):
msgs = self._create_msg_group()
for name in originals_storage.list():
path = self.originals_dir.joinpath(name)
logger.debug("adding file: {}".format(path.relative_to(self.originals_dir)))
logger.debug("adding file: %s", path.relative_to(self.originals_dir))
category = get_category(Path(name).parts[0])
with File(path.open("rb")) as f:
msgs.append(
Expand Down Expand Up @@ -756,7 +756,7 @@ def extractall(self, unpack_destination, filename):
r.extractall(path=unpack_destination)

else:
return Message("Archive {} is unsupported".format(filename))
return Message(f"Archive {filename} is unsupported")

def find_root_directory(self, basedir):
for dirpath, dirnames, filenames in os.walk(basedir):
Expand Down Expand Up @@ -806,11 +806,12 @@ def process(self, category: FileCategoryDirectories, filename: str):
return msgs


def import_archive(codebase_release, nestedcode_folder_name, fs_api=None):
def import_archive(codebase_release, nested_code_folder_name, fs_api=None):
"""currently only used for tests"""
if fs_api is None:
fs_api = codebase_release.get_fs_api()
archive_name = "{}.zip".format(nestedcode_folder_name)
shutil.make_archive(nestedcode_folder_name, "zip", nestedcode_folder_name)
archive_name = f"{nested_code_folder_name}.zip"
shutil.make_archive(nested_code_folder_name, "zip", nested_code_folder_name)
with open(archive_name, "rb") as f:
msgs = fs_api.add(
FileCategoryDirectories.code, content=f, name="nestedcode.zip"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Dear {{ review.submitter.name }},

Congratulations! The peer review of your model [{{ release.title }}]({{ release_url }}) is now complete and your release has been marked as peer reviewed. Your release will remain private until you [publish it yourself]({{release_publish_url}}). An automatic DOI registration workflow that automatically assigns a DOI to all peer reviewed models is under development but if you need a DOI immediately please feel free to [contact us]({{ build_absolute_uri(slugurl('contact')) }}).
Congratulations! The peer review of your model [{{ release.title }}]({{ release_url }}) is now complete and your release has been marked as peer reviewed. Your release will remain private until you [publish it yourself]({{release_publish_url}}). An automatic DOI registration workflow that automatically assigns a DOI to all peer reviewed models is slated for development by Q2 2024. If you need a DOI immediately please feel free to [contact us]({{ build_absolute_uri(slugurl('contact')) }}).

Thank you for submitting your computational model for review to CoMSES Net! We hope you will be willing to serve as a reviewer of model code as well in future model peer reviews.

Expand Down
4 changes: 1 addition & 3 deletions django/library/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import logging
import pathlib
from datetime import datetime, timedelta

from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.exceptions import PermissionDenied
from django.db import transaction
from django.db.models import Count, Q, Prefetch, Max
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect
from django.urls import resolve
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.views import View
from django.views.generic.base import RedirectView
Expand Down Expand Up @@ -329,6 +326,7 @@ class PeerReviewEditorFeedbackUpdateView(UpdateView):

def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
# set editor to the currently signed in user initiating this action
kwargs["editor"] = self.request.user.member_profile
return kwargs

Expand Down

0 comments on commit a3990ca

Please sign in to comment.