Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2224] Community roles: change dates display [+ refactoring, bug fixing] #2230

25 changes: 3 additions & 22 deletions amy/autoemails/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from recruitment.models import InstructorRecruitment, InstructorRecruitmentSignup
from workshops.fields import TAG_SEPARATOR
from workshops.models import Event, Person, Task
from workshops.utils.dates import human_daterange
from workshops.utils.emails import match_notification_email
from workshops.utils.reports import reports_link

logger = logging.getLogger("amy.signals")
scheduler = django_rq.get_scheduler("default")
Expand Down Expand Up @@ -277,8 +280,6 @@ def check(task: Task): # type: ignore
)

def get_additional_context(self, objects, *args, **kwargs):
from workshops.util import human_daterange, match_notification_email

# refresh related event
event = objects["event"]
task = objects["task"]
Expand Down Expand Up @@ -359,8 +360,6 @@ def check(task: Task): # type: ignore
)

def get_additional_context(self, objects, *args, **kwargs):
from workshops.util import human_daterange, match_notification_email

# refresh related event
event = objects["event"]
task = objects["task"]
Expand Down Expand Up @@ -492,12 +491,6 @@ def check(event: Event): # type: ignore
)

def get_additional_context(self, objects, *args, **kwargs):
from workshops.util import (
human_daterange,
match_notification_email,
reports_link,
)

# refresh related event
event = objects["event"]
event.refresh_from_db()
Expand Down Expand Up @@ -627,8 +620,6 @@ def check(event: Event) -> bool:
return False

def get_additional_context(self, objects, *args, **kwargs):
from workshops.util import human_daterange, match_notification_email

# refresh related event and request
event = objects["event"]
event.refresh_from_db()
Expand Down Expand Up @@ -750,8 +741,6 @@ def check(event: Event): # type: ignore
)

def get_additional_context(self, objects, *args, **kwargs):
from workshops.util import human_daterange, match_notification_email

# refresh related event
event = objects["event"]
event.refresh_from_db()
Expand Down Expand Up @@ -904,8 +893,6 @@ def check(event: Event): # type: ignore
)

def get_additional_context(self, objects, *args, **kwargs):
from workshops.util import human_daterange, match_notification_email

# refresh related event
event = objects["event"]
event.refresh_from_db()
Expand Down Expand Up @@ -1038,8 +1025,6 @@ def check(event: Event): # type: ignore
)

def get_additional_context(self, objects, *args, **kwargs):
from workshops.util import human_daterange, match_notification_email

# refresh related event
event = objects["event"]
event.refresh_from_db()
Expand Down Expand Up @@ -1102,8 +1087,6 @@ def all_recipients(self) -> str:
return ""

def get_additional_context(self, objects, *args, **kwargs):
from workshops.util import human_daterange, match_notification_email

# prepare context
context = dict()

Expand Down Expand Up @@ -1351,8 +1334,6 @@ def check(signup: InstructorRecruitmentSignup) -> bool:
return signup.state == "d" and signup.recruitment.status == "c"

def get_additional_context(self, objects, *args, **kwargs) -> dict:
from workshops.util import human_daterange, match_notification_email

# refresh related recruitment, event and person
recruitment: InstructorRecruitment = objects["recruitment"]
recruitment.refresh_from_db()
Expand Down
2 changes: 1 addition & 1 deletion amy/autoemails/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from autoemails.job import Job
from autoemails.models import EmailTemplate, RQJob, Trigger
from autoemails.utils import check_status, scheduled_execution_time
from workshops.util import admin_required
from workshops.utils.access import admin_required

logger = logging.getLogger("amy.signals")
scheduler = django_rq.get_scheduler("default")
Expand Down
2 changes: 1 addition & 1 deletion amy/autoemails/tests/test_declinedinstructorsaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from autoemails.models import EmailTemplate, Trigger
from recruitment.models import InstructorRecruitment, InstructorRecruitmentSignup
from workshops.models import Event, Organization, Person, Tag
from workshops.util import human_daterange
from workshops.utils.dates import human_daterange


class TestDeclinedInstructorsAction(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion amy/autoemails/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import django_rq

from workshops.models import WorkshopRequest
from workshops.util import admin_required
from workshops.utils.access import admin_required

from .actions import GenericAction
from .forms import GenericEmailScheduleForm
Expand Down
9 changes: 9 additions & 0 deletions amy/communityroles/templatetags/communityroles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from communityroles.models import CommunityRole
from workshops.models import Person
from workshops.utils.dates import human_daterange

register = template.Library()

Expand All @@ -14,3 +15,11 @@ def get_community_role(person: Person, role_name: str) -> Optional[CommunityRole
return CommunityRole.objects.get(person=person, config__name=role_name)
except CommunityRole.DoesNotExist:
return None


@register.simple_tag
def community_role_human_dates(community_role: CommunityRole) -> str:
result = human_daterange(
community_role.start, community_role.end, no_date_right="present"
)
return result
35 changes: 33 additions & 2 deletions amy/communityroles/tests/test_templatetags.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from datetime import date

from django.test import TestCase

from communityroles.models import CommunityRole, CommunityRoleConfig
from communityroles.templatetags.communityroles import get_community_role
from communityroles.templatetags.communityroles import (
community_role_human_dates,
get_community_role,
)
from workshops.models import Person


class TestCommunityRolesTemplateTags(TestCase):
class TestCommunityRolesTemplateTag(TestCase):
def test_get_community_role(self):
# Arrange
person = Person.objects.create(
Expand Down Expand Up @@ -68,3 +73,29 @@ def test_get_community_role__person_not_found(self):
role_found = get_community_role(fake_person, role_name)
# Assert
self.assertEqual(role_found, None)


class TestCommunityRoleHumanDatesTemplateTag(TestCase):
def test_community_role_human_dates(self) -> None:
# Arrange
self.instructor_community_role_config = CommunityRoleConfig.objects.create(
name="instructor",
link_to_award=False,
link_to_membership=False,
additional_url=False,
)
person = Person.objects.create(
username="test1", personal="Test1", family="User", email="test1@example.org"
)
community_role = CommunityRole.objects.create(
config=self.instructor_community_role_config,
person=person,
start=date(2022, 9, 17),
end=None,
)

# Act
date_display = community_role_human_dates(community_role)

# Assert
self.assertEqual(date_display, "Sep 17, 2022 - present")
2 changes: 1 addition & 1 deletion amy/communityroles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
AMYUpdateView,
RedirectSupportMixin,
)
from workshops.util import OnlyForAdminsMixin
from workshops.utils.access import OnlyForAdminsMixin

from .forms import CommunityRoleForm, CommunityRoleUpdateForm
from .models import CommunityRole
Expand Down
2 changes: 1 addition & 1 deletion amy/consents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from consents.models import Consent
from consents.util import person_has_consented_to_required_terms
from workshops.base_views import AMYCreateView, RedirectSupportMixin
from workshops.util import login_required
from workshops.utils.access import login_required


class ConsentsUpdate(RedirectSupportMixin, AMYCreateView, LoginRequiredMixin):
Expand Down
2 changes: 1 addition & 1 deletion amy/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
TrainingRequest,
TrainingRequirement,
)
from workshops.util import admin_required, login_required
from workshops.utils.access import admin_required, login_required

# Terms shown on the instructor dashboard and can be updated by the user.
TERM_SLUGS = ["may-contact", "public-profile", "may-publish-name"]
Expand Down
3 changes: 2 additions & 1 deletion amy/extforms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from extrequests.models import SelfOrganisedSubmission, WorkshopInquiryRequest
from workshops.base_views import AMYCreateView, AutoresponderMixin, EmailSendMixin
from workshops.models import TrainingRequest, WorkshopRequest
from workshops.util import LoginNotRequiredMixin, match_notification_email
from workshops.utils.access import LoginNotRequiredMixin
from workshops.utils.emails import match_notification_email

# ------------------------------------------------------------
# TrainingRequest views
Expand Down
2 changes: 1 addition & 1 deletion amy/extrequests/tests/test_bulk_manual_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from extrequests.tests.test_training_request import create_training_request
from workshops.models import TrainingRequest
from workshops.tests.base import TestBase
from workshops.util import (
from workshops.utils.trainingrequest_upload import (
clean_upload_trainingrequest_manual_score,
update_manual_score,
upload_trainingrequest_manual_score_csv,
Expand Down
3 changes: 0 additions & 3 deletions amy/extrequests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
path('accept_event/', views.WorkshopRequestAcceptEvent.as_view(), name='workshoprequest_accept_event'),
path('edit/', views.WorkshopRequestChange.as_view(), name='workshoprequest_edit'),
path('assign/', views.WorkshopRequestAssign.as_view(), name='workshoprequest_assign'),
path('assign/<int:person_id>/', views.WorkshopRequestAssign.as_view(), name='workshoprequest_assign'),
])),

# workshop inquiries
Expand All @@ -32,7 +31,6 @@
path('accept_event/', views.WorkshopInquiryAcceptEvent.as_view(), name='workshopinquiry_accept_event'),
path('edit/', views.WorkshopInquiryChange.as_view(), name='workshopinquiry_edit'),
path('assign/', views.WorkshopInquiryAssign.as_view(), name='workshopinquiry_assign'),
path('assign/<int:person_id>/', views.WorkshopInquiryAssign.as_view(), name='workshopinquiry_assign'),
])),

# self-organized submissions
Expand All @@ -43,6 +41,5 @@
path('accept_event/', views.SelfOrganisedSubmissionAcceptEvent.as_view(), name='selforganisedsubmission_accept_event'),
path('edit/', views.SelfOrganisedSubmissionChange.as_view(), name='selforganisedsubmission_edit'),
path('assign/', views.SelfOrganisedSubmissionAssign.as_view(), name='selforganisedsubmission_assign'),
path('assign/<int:person_id>/', views.SelfOrganisedSubmissionAssign.as_view(), name='selforganisedsubmission_assign'),
])),
]
18 changes: 7 additions & 11 deletions amy/extrequests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
RedirectSupportMixin,
StateFilterMixin,
)
from workshops.exceptions import InternalError, WrongWorkshopURL
from workshops.forms import (
AdminLookupForm,
BootstrapHelper,
Expand All @@ -63,21 +64,16 @@
TrainingRequest,
WorkshopRequest,
)
from workshops.util import (
InternalError,
OnlyForAdminsMixin,
WrongWorkshopURL,
admin_required,
from workshops.utils.access import OnlyForAdminsMixin, admin_required
from workshops.utils.merge import merge_objects
from workshops.utils.metadata import fetch_workshop_metadata, parse_workshop_metadata
from workshops.utils.trainingrequest_upload import (
clean_upload_trainingrequest_manual_score,
create_username,
failed_to_delete,
fetch_workshop_metadata,
merge_objects,
parse_workshop_metadata,
redirect_with_next_support,
update_manual_score,
upload_trainingrequest_manual_score_csv,
)
from workshops.utils.usernames import create_username
from workshops.utils.views import failed_to_delete, redirect_with_next_support

logger = logging.getLogger("amy.signals")
scheduler = django_rq.get_scheduler("default")
Expand Down
2 changes: 1 addition & 1 deletion amy/fiscal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
RedirectSupportMixin,
)
from workshops.models import Award, Member, MemberRole, Membership, Organization, Task
from workshops.util import OnlyForAdminsMixin
from workshops.utils.access import OnlyForAdminsMixin

# ------------------------------------------------------------
# Organization related views
Expand Down
2 changes: 1 addition & 1 deletion amy/recruitment/tests/test_instructor_recruitment_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def test_context_data(self) -> None:
"title": "Begin Instructor Selection Process for test-event",
"event": event,
"event_dates": event.human_readable_date(
common_month_left=r"%B %d", range_char="-"
common_month_left=r"%B %d", separator="-"
),
"view": view,
"model": InstructorRecruitment,
Expand Down
4 changes: 2 additions & 2 deletions amy/recruitment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
RedirectSupportMixin,
)
from workshops.models import Event, Person, Role, Task
from workshops.util import OnlyForAdminsMixin
from workshops.utils.access import OnlyForAdminsMixin

from .models import InstructorRecruitment, InstructorRecruitmentSignup

Expand Down Expand Up @@ -205,7 +205,7 @@ def get_context_data(self, **kwargs):
context["title"] = f"Begin Instructor Selection Process for {self.event}"
context["event"] = self.event
context["event_dates"] = self.event.human_readable_date(
common_month_left=r"%B %d", range_char="-"
common_month_left=r"%B %d", separator="-"
)
context["priority"] = InstructorRecruitment.calculate_priority(self.event)
return context
Expand Down
3 changes: 2 additions & 1 deletion amy/reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
Task,
TrainingRequest,
)
from workshops.util import admin_required, get_pagination_items
from workshops.utils.access import admin_required
from workshops.utils.pagination import get_pagination_items


@admin_required
Expand Down
6 changes: 3 additions & 3 deletions amy/templates/communityroles/communityrole.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base_nav.html" %}
{% load links dates %}
{% load links dates communityroles %}


{% block content %}
Expand All @@ -24,8 +24,8 @@
<tr>
<th>Dates</th>
<td>
{% if role.start or role.end %}
{% human_daterange role.start role.end %}
{% if role.start %}
{% community_role_human_dates role %}
{% else %}
&mdash;
{% endif %}
Expand Down
19 changes: 14 additions & 5 deletions amy/templates/includes/assigned_to.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
{% load assignments %}
{% if object.slug %}{% assign object.slug as pk %}{% else %}{% assign object.pk as pk %}{% endif %}
<p>
<div>
<a href="#assignment_modal" id="change_assignment" data-toggle="modal" data-target="#assignment_modal"><i class="fas fa-user-cog"></i></a>
{% if object.assigned_to %}
Assigned to:
<a href="{{ object.assigned_to.get_absolute_url }}">{{ object.assigned_to.full_name }}</a> (<a href="{% url assign_url pk %}" id="clear-assignment">clear</a>).
<form method="POST" action="{% url assign_url pk %}" style="display: inline">
Assigned to:
<a href="{{ object.assigned_to.get_absolute_url }}">{{ object.assigned_to.full_name }}</a>
<input type="hidden" name="person" value="" />
{% csrf_token %}
(<input type="submit" class="btn btn-link border-0 p-0" id="clear-assignment" value="clear" style="margin-top: -4px" />).
</form>
{% else %}
Not assigned (<a href="{% url assign_url pk user.pk %}" id="assign-yourself">assign yourself</a>).
<form method="POST" action="{% url assign_url pk %}" style="display: inline">
<input type="hidden" name="person" value="{{ user.pk }}" />
{% csrf_token %}
Not assigned (<input type="submit" class="btn btn-link border-0 p-0" id="assign-yourself" value="assign yourself" style="margin-top: -4px" />).
</form>
{% endif %}
</p>
</div>
Loading