Skip to content

Commit

Permalink
Refractor fund views
Browse files Browse the repository at this point in the history
  • Loading branch information
theskumar committed Dec 31, 2024
1 parent 0846f65 commit e02c5cf
Show file tree
Hide file tree
Showing 16 changed files with 1,951 additions and 1,830 deletions.
30 changes: 0 additions & 30 deletions hypha/apply/funds/services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from bs4 import element
from django.apps import apps
from django.conf import settings
from django.core.exceptions import PermissionDenied
Expand Down Expand Up @@ -261,32 +260,3 @@ def annotate_review_recommendation_and_count(submissions: QuerySet) -> QuerySet:
),
)
return submissions


def has_valid_str(tag: element.Tag) -> bool:
"""Checks that an Tag contains a valid text element and/or string.
Args:
tag: a `bs4.element.Tag`
Returns:
bool: True if has a valid string that isn't whitespace or `-`
"""
text_elem = tag.name in ["span", "p", "strong", "em", "td", "a"]

try:
# try block logic handles elements that have text directly in them
# ie. `<p>test</p>` or `<em>yeet!</em>` would return true as string values would be contained in tag.string
ret = bool(
text_elem
and tag.find(string=True, recursive=False)
and tag.string.strip(" -\n")
)
return ret
except AttributeError:
# except block logic handles embedded tag strings where tag.string == None but the specified tag DOES contain a string
# ie. `<p>Hypha is <strong>cool</strong></p>` contains the string "Hypha is" but due to the strong tag being mixed in will
# have None for the tag.string value.
# tags like `<p> <em>Hypha rocks</em> </p>` will return false as the <p> tag contains no valid strings, it's child does.
tag_contents = "".join(tag.find_all(string=True, recursive=False))
ret = bool(tag.text and tag.text.strip() and tag_contents.strip())
return ret
2 changes: 1 addition & 1 deletion hypha/apply/funds/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
SealedRoundFactory,
SealedSubmissionFactory,
)
from hypha.apply.funds.views.submission_detail import SubmissionDetailView
from hypha.apply.funds.workflow import INITIAL_STATE
from hypha.apply.projects.models import Project
from hypha.apply.projects.tests.factories import ProjectFactory
Expand All @@ -47,7 +48,6 @@
ReviewerSettings,
ScreeningStatus,
)
from ..views import SubmissionDetailView
from .factories import CustomFormFieldsFactory


Expand Down
49 changes: 24 additions & 25 deletions hypha/apply/funds/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,18 @@
from hypha.apply.projects import urls as projects_urls

from .views import (
CreateProjectView,
GroupingApplicationsListView,
ProgressSubmissionView,
ReminderCreateView,
ReminderDeleteView,
ReviewerLeaderboard,
ReviewerLeaderboardDetail,
RevisionCompareView,
RevisionListView,
RoundListView,
StaffAssignments,
SubmissionDeleteView,
SubmissionDetailPDFView,
SubmissionDetailView,
SubmissionEditView,
SubmissionPrivateMediaView,
SubmissionResultView,
SubmissionSealedView,
TranslateSubmissionView,
UpdateLeadView,
UpdateMetaTermsView,
UpdatePartnersView,
UpdateReviewersView,
htmx_archive_unarchive_submission,
reminder_list,
submission_success,
)
from .views_all import (
from .views.all import (
bulk_archive_submissions,
bulk_delete_submissions,
bulk_update_submissions_status,
submissions_all,
)
from .views_partials import (
from .views.partials import (
get_applications_status_counts,
partial_meta_terms_card,
partial_reviews_card,
Expand All @@ -47,7 +25,6 @@
partial_submission_activities,
partial_submission_answers,
partial_submission_lead,
partial_translate_answers,
sub_menu_bulk_update_lead,
sub_menu_bulk_update_reviewers,
sub_menu_category_options,
Expand All @@ -58,6 +35,28 @@
sub_menu_rounds,
sub_menu_update_status,
)
from .views.reminders import ReminderCreateView, ReminderDeleteView, reminder_list
from .views.results import SubmissionResultView
from .views.reviewer_leaderboard import ReviewerLeaderboard, ReviewerLeaderboardDetail
from .views.revisions import RevisionCompareView, RevisionListView
from .views.staff_assignments import StaffAssignments
from .views.submission_delete import SubmissionDeleteView
from .views.submission_detail import (
SubmissionDetailPDFView,
SubmissionDetailView,
SubmissionSealedView,
)
from .views.submission_edit import (
CreateProjectView,
ProgressSubmissionView,
SubmissionEditView,
UpdateLeadView,
UpdateMetaTermsView,
UpdatePartnersView,
UpdateReviewersView,
htmx_archive_unarchive_submission,
)
from .views.translate import TranslateSubmissionView, partial_translate_answers

revision_urls = (
[
Expand Down
Loading

0 comments on commit e02c5cf

Please sign in to comment.