Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coderdojochi/models/session.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,6 +277,9 @@ def get_absolute_url(self) -> str:
def get_sign_up_url(self):
return reverse("session-sign-up", args=[str(self.id)])

def get_cancel_url(self):
return reverse("session-cancel", args=[str(self.id)])

def get_calendar_url(self):
return reverse("session-calendar", args=[str(self.id)])

Expand Down
33 changes: 33 additions & 0 deletions coderdojochi/templates/guardian/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Sign Up | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light"><strong>{{ student.full_name }}</strong> can no longer make it to the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Enroll <strong>{{ student.full_name }}</strong> for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
21 changes: 21 additions & 0 deletions coderdojochi/templates/mentor/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Cancel | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion coderdojochi/templates/mentor/session_detail.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ <h3 class="title text-primary">Class Details & Enrollment</h3>
{% else %}
{% if mentor_signed_up %}
<p>You are signed up to mentor this class.</p>
<p><a href="{{ session.get_sign_up_url }}" class="button large tertiary">I can't make it...</a></p>
<p><a href="{{ session.get_cancel_url }}" class="button large tertiary">I can't make it...</a></p>
{% else %}
{% if spots_remaining %}
<p><a href="{{ session.get_sign_up_url }}" class="button large secondary">Sign up now!</a></p>
Expand Down
24 changes: 6 additions & 18 deletions coderdojochi/templates/mentor/session_sign_up.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,26 +8,14 @@

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>
<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>
<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions coderdojochi/urls.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
SessionCalendarView,
SessionDetailView,
SessionSignUpView,
SessionCancelView,
WelcomeView,
meeting_announce,
meeting_sign_up,
Expand DownExpand Up@@ -156,6 +157,12 @@
path("<int:pk>/sign-up/", SessionSignUpView.as_view(), name="session-sign-up"),
# /classes/ID/sign-up/STUDENT-ID/
path("<int:pk>/sign-up/<int:student_id>/", SessionSignUpView.as_view(), name="session-sign-up"),

# Cancel session
# /classes/ID/cancel/
path("<int:pk>/cancel/", SessionCancelView.as_view(), name="session-cancel"),
# /classes/ID/cancel/STUDENT-ID/
path("<int:pk>/cancel/<int:student_id>/", SessionCancelView.as_view(), name="session-cancel"),
]
),
),
Expand Down
3 changes: 3 additions & 0 deletions coderdojochi/views/guardian/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,3 +19,6 @@ def get_context_data(self, **kwargs):
)

return context

class SessionCancelView(DetailView):
pass
52 changes: 49 additions & 3 deletions coderdojochi/views/mentor/sessions.py
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
from django.shortcuts import get_object_or_404
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404, redirect
from django.views.generic import DetailView

from ...models import Mentor, MentorOrder, Session
Expand All@@ -14,12 +15,11 @@ def get_context_data(self, **kwargs):

session_orders = MentorOrder.objects.filter(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
context["mentor_signed_up"] = session_orders.exists()
context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
context["spots_remaining"] = session.mentor_capacity - session_orders.count()
context["account"] = mentor

Expand All@@ -31,3 +31,49 @@ def get_context_data(self, **kwargs):
)

return context


class SessionCancelView(DetailView):
model = Session
template_name = "mentor/session_cancel.html"

# redirect if order not found
def get(self, request, *args, **kwargs):
try:
self.object = self.get_object()
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)
mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
except ObjectDoesNotExist:
return redirect(session.get_absolute_url())


def get_context_data(self, **kwargs):
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)

mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
# context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
# context["spots_remaining"] = session.mentor_capacity - session_orders.count()
# context["account"] = mentor

# context["active_mentors"] = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(
# session=self.object,
# is_active=True,
# ).values("mentor__id")
# )

return context
133 changes: 30 additions & 103 deletions coderdojochi/views/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,109 +136,6 @@ def validate_partner_session_access(self, request, pk):
return False


# class SessionDetailView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
# template_name = "session_detail.html"

# def dispatch(self, request, *args, **kwargs):
# session_obj = get_object_or_404(Session, id=kwargs["pk"])

# if request.method == "GET":
# if session_obj.password and not self.validate_partner_session_access(self.request, kwargs["pk"]):
# return redirect(reverse("session-password", kwargs=kwargs))

# if request.user.is_authenticated and request.user.role:
# if "enroll" in request.GET or "enroll" in kwargs:
# return self.enroll_redirect(request, session_obj)

# # kwargs["session_obj"] = session_obj
# return super(SessionDetailView, self).dispatch(request, *args, **kwargs)

# def enroll_redirect(self, request, session_obj):
# if request.user.role == "mentor":
# return redirect("session-sign-up", pk=session_obj.id)

# guardian = get_object_or_404(Guardian, user=request.user)
# student = get_object_or_404(Student, guardian=guardian, id=(int(request.GET["student"])))

# if student:
# return redirect("session-sign-up", pk=session_obj.id, student_id=student.id)

# return redirect(f"{reverse('welcome')}?next={session_obj.get_absolute_url()}&enroll=True")

# def validate_partner_session_access(self, request, pk):
# authed_sessions = request.session.get("authed_partner_sessions")

# if authed_sessions and pk in authed_sessions:
# if request.user.is_authenticated:
# PartnerPasswordAccess.objects.get_or_create(session_id=pk, user=request.user)
# return True

# if request.user.is_authenticated:
# try:
# PartnerPasswordAccess.objects.get(session_id=pk, user_id=request.user.id)
# except PartnerPasswordAccess.DoesNotExist:
# return False
# else:
# return True

# else:
# return False

# def get_context_data(self, **kwargs):
# print(kwargs["session_obj"].__dict__)
# context = super(SessionDetailView, self).get_context_data(**kwargs)
# session_obj = kwargs["session_obj"]
# context["session"] = session_obj

# upcoming_classes = Session.objects.filter(is_active=True, start_date__gte=timezone.now()).order_by("start_date")
# context["upcoming_classes"] = upcoming_classes

# active_mentors = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(session=session_obj, is_active=True).values("mentor__id")
# )
# context["active_mentors"] = active_mentors

# if self.request.user.is_authenticated:
# if self.request.user.role == "mentor":
# account = get_object_or_404(Mentor, user=self.request.user)
# session_orders = MentorOrder.objects.filter(session=session_obj, is_active=True,)
# context["mentor_signed_up"] = session_orders.filter(mentor=account).exists()

# context["spots_remaining"] = session_obj.get_mentor_capacity() - session_orders.count()
# else:
# account = get_object_or_404(Guardian, user=self.request.user)
# context["students"] = account.get_students()
# context["spots_remaining"] = session_obj.capacity - session_obj.get_active_student_count()
# context["account"] = account
# else:
# context["upcoming_classes"] = upcoming_classes.filter(is_public=True)
# context["spots_remaining"] = session_obj.capacity - session_obj.objects.get_active_student_count()

# return context

# def post(self, request, *args, **kwargs):
# session_obj = kwargs["session_obj"]
# if "waitlist" not in request.POST:
# messages.error(request, "Invalid request, please try again.")
# return redirect(session_obj.get_absolute_url())

# if request.POST["waitlist"] == "student":
# account = Student.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_students"
# else:
# account = Guardian.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_guardians"

# if request.POST["remove"] == "true":
# getattr(session_obj, waitlist_attr).remove(account)
# session_obj.save()
# messages.success(request, "You have been removed from the waitlist. Thanks for letting us know.")
# else:
# getattr(session_obj, waitlist_attr).add(account)
# session_obj.save()
# messages.success(request, "Added to waitlist successfully.")
# return redirect(session_obj.get_absolute_url())


class SessionSignUpView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
template_name = "session_sign_up.html"
Expand All@@ -254,6 +151,8 @@ def dispatch(self, request, *args, **kwargs):
kwargs["mentor"] = get_object_or_404(Mentor, user=request.user)
kwargs["user_signed_up"] = session_orders.filter(mentor=kwargs["mentor"]).exists()

kwargs["spots_remaining"] = session_obj.mentor_capacity - session_orders.count()

elif request.user.role == "guardian":
kwargs["guardian"] = get_object_or_404(Guardian, user=request.user)
kwargs["student"] = get_object_or_404(Student, id=kwargs["student_id"])
Expand DownExpand Up@@ -286,6 +185,15 @@ def check_access(self, request, *args, **kwargs):
),
"redirect": request.META.get("HTTP_REFERER", "/dojo"),
}

# Check to make sure there is a spot open to sign up
if kwargs["spots_remaining"] <= 0:
access_dict = {
"message": (
"There are no slots open to mentor. Please check another class."
),
"redirect": request.META.get("HTTP_REFERER", kwargs["session_obj"].get_absolute_url()),
}

if kwargs.get("student"):
limits = self.student_limitations(kwargs["student"], kwargs["session_obj"], kwargs["user_signed_up"])
Expand DownExpand Up@@ -365,6 +273,25 @@ def post(self, request, *args, **kwargs):

return redirect(session_obj.get_absolute_url())

class SessionCancelView(View):
def get(self, request, *args, **kwargs):
pk = kwargs["pk"]
session = get_object_or_404(Session, id=pk)

# TODO: Do we need to check for this?
# if session.password and not self.validate_partner_session_access(request, pk):
# return redirect(reverse("session-password", kwargs=kwargs))

if request.user.is_authenticated:
if request.user.role == "mentor":
return mentor.SessionCancelView.as_view()(request, *args, **kwargs)
else:
return guardian.SessionCancelView.as_view()(request, *args, **kwargs)

return redirect(session.get_absolute_url())




class PasswordSessionView(TemplateView):
template_name = "session_partner_password.html"
Expand Down
12 changes: 6 additions & 6 deletions fixtures/12-coderdojochi.mentor.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,16 +29,16 @@
"user": 3,
"bio": "",
"is_active": true,
"background_check": false,
"is_public": false,
"background_check": true,
"is_public": true,
"avatar": "",
"avatar_approved": false,
"birthday": null,
"gender": null,
"avatar_approved": true,
"birthday": "1988-01-01",
"gender": "male",
"work_place": null,
"phone": null,
"home_address": null,
"race_ethnicity": []
"race_ethnicity": [2]
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion fixtures/14-coderdojochi.session.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
"start_date": "2022-01-01T16:00:00Z",
"location": 3,
"capacity": 20,
"mentor_capacity": 10,
"mentor_capacity": 1,
"instructor": 1,
"cost": "0.00",
"minimum_cost": null,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coderdojochi/models/session.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,6 +277,9 @@ def get_absolute_url(self) -> str:
def get_sign_up_url(self):
return reverse("session-sign-up", args=[str(self.id)])

def get_cancel_url(self):
return reverse("session-cancel", args=[str(self.id)])

def get_calendar_url(self):
return reverse("session-calendar", args=[str(self.id)])

Expand Down
33 changes: 33 additions & 0 deletions coderdojochi/templates/guardian/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Sign Up | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light"><strong>{{ student.full_name }}</strong> can no longer make it to the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Enroll <strong>{{ student.full_name }}</strong> for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
21 changes: 21 additions & 0 deletions coderdojochi/templates/mentor/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Cancel | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion coderdojochi/templates/mentor/session_detail.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ <h3 class="title text-primary">Class Details & Enrollment</h3>
{% else %}
{% if mentor_signed_up %}
<p>You are signed up to mentor this class.</p>
<p><a href="{{ session.get_sign_up_url }}" class="button large tertiary">I can't make it...</a></p>
<p><a href="{{ session.get_cancel_url }}" class="button large tertiary">I can't make it...</a></p>
{% else %}
{% if spots_remaining %}
<p><a href="{{ session.get_sign_up_url }}" class="button large secondary">Sign up now!</a></p>
Expand Down
24 changes: 6 additions & 18 deletions coderdojochi/templates/mentor/session_sign_up.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,26 +8,14 @@

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>
<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>
<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions coderdojochi/urls.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
SessionCalendarView,
SessionDetailView,
SessionSignUpView,
SessionCancelView,
WelcomeView,
meeting_announce,
meeting_sign_up,
Expand DownExpand Up@@ -156,6 +157,12 @@
path("<int:pk>/sign-up/", SessionSignUpView.as_view(), name="session-sign-up"),
# /classes/ID/sign-up/STUDENT-ID/
path("<int:pk>/sign-up/<int:student_id>/", SessionSignUpView.as_view(), name="session-sign-up"),

# Cancel session
# /classes/ID/cancel/
path("<int:pk>/cancel/", SessionCancelView.as_view(), name="session-cancel"),
# /classes/ID/cancel/STUDENT-ID/
path("<int:pk>/cancel/<int:student_id>/", SessionCancelView.as_view(), name="session-cancel"),
]
),
),
Expand Down
3 changes: 3 additions & 0 deletions coderdojochi/views/guardian/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,3 +19,6 @@ def get_context_data(self, **kwargs):
)

return context

class SessionCancelView(DetailView):
pass
52 changes: 49 additions & 3 deletions coderdojochi/views/mentor/sessions.py
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
from django.shortcuts import get_object_or_404
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404, redirect
from django.views.generic import DetailView

from ...models import Mentor, MentorOrder, Session
Expand All@@ -14,12 +15,11 @@ def get_context_data(self, **kwargs):

session_orders = MentorOrder.objects.filter(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
context["mentor_signed_up"] = session_orders.exists()
context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
context["spots_remaining"] = session.mentor_capacity - session_orders.count()
context["account"] = mentor

Expand All@@ -31,3 +31,49 @@ def get_context_data(self, **kwargs):
)

return context


class SessionCancelView(DetailView):
model = Session
template_name = "mentor/session_cancel.html"

# redirect if order not found
def get(self, request, *args, **kwargs):
try:
self.object = self.get_object()
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)
mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
except ObjectDoesNotExist:
return redirect(session.get_absolute_url())


def get_context_data(self, **kwargs):
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)

mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
# context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
# context["spots_remaining"] = session.mentor_capacity - session_orders.count()
# context["account"] = mentor

# context["active_mentors"] = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(
# session=self.object,
# is_active=True,
# ).values("mentor__id")
# )

return context
133 changes: 30 additions & 103 deletions coderdojochi/views/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,109 +136,6 @@ def validate_partner_session_access(self, request, pk):
return False


# class SessionDetailView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
# template_name = "session_detail.html"

# def dispatch(self, request, *args, **kwargs):
# session_obj = get_object_or_404(Session, id=kwargs["pk"])

# if request.method == "GET":
# if session_obj.password and not self.validate_partner_session_access(self.request, kwargs["pk"]):
# return redirect(reverse("session-password", kwargs=kwargs))

# if request.user.is_authenticated and request.user.role:
# if "enroll" in request.GET or "enroll" in kwargs:
# return self.enroll_redirect(request, session_obj)

# # kwargs["session_obj"] = session_obj
# return super(SessionDetailView, self).dispatch(request, *args, **kwargs)

# def enroll_redirect(self, request, session_obj):
# if request.user.role == "mentor":
# return redirect("session-sign-up", pk=session_obj.id)

# guardian = get_object_or_404(Guardian, user=request.user)
# student = get_object_or_404(Student, guardian=guardian, id=(int(request.GET["student"])))

# if student:
# return redirect("session-sign-up", pk=session_obj.id, student_id=student.id)

# return redirect(f"{reverse('welcome')}?next={session_obj.get_absolute_url()}&enroll=True")

# def validate_partner_session_access(self, request, pk):
# authed_sessions = request.session.get("authed_partner_sessions")

# if authed_sessions and pk in authed_sessions:
# if request.user.is_authenticated:
# PartnerPasswordAccess.objects.get_or_create(session_id=pk, user=request.user)
# return True

# if request.user.is_authenticated:
# try:
# PartnerPasswordAccess.objects.get(session_id=pk, user_id=request.user.id)
# except PartnerPasswordAccess.DoesNotExist:
# return False
# else:
# return True

# else:
# return False

# def get_context_data(self, **kwargs):
# print(kwargs["session_obj"].__dict__)
# context = super(SessionDetailView, self).get_context_data(**kwargs)
# session_obj = kwargs["session_obj"]
# context["session"] = session_obj

# upcoming_classes = Session.objects.filter(is_active=True, start_date__gte=timezone.now()).order_by("start_date")
# context["upcoming_classes"] = upcoming_classes

# active_mentors = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(session=session_obj, is_active=True).values("mentor__id")
# )
# context["active_mentors"] = active_mentors

# if self.request.user.is_authenticated:
# if self.request.user.role == "mentor":
# account = get_object_or_404(Mentor, user=self.request.user)
# session_orders = MentorOrder.objects.filter(session=session_obj, is_active=True,)
# context["mentor_signed_up"] = session_orders.filter(mentor=account).exists()

# context["spots_remaining"] = session_obj.get_mentor_capacity() - session_orders.count()
# else:
# account = get_object_or_404(Guardian, user=self.request.user)
# context["students"] = account.get_students()
# context["spots_remaining"] = session_obj.capacity - session_obj.get_active_student_count()
# context["account"] = account
# else:
# context["upcoming_classes"] = upcoming_classes.filter(is_public=True)
# context["spots_remaining"] = session_obj.capacity - session_obj.objects.get_active_student_count()

# return context

# def post(self, request, *args, **kwargs):
# session_obj = kwargs["session_obj"]
# if "waitlist" not in request.POST:
# messages.error(request, "Invalid request, please try again.")
# return redirect(session_obj.get_absolute_url())

# if request.POST["waitlist"] == "student":
# account = Student.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_students"
# else:
# account = Guardian.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_guardians"

# if request.POST["remove"] == "true":
# getattr(session_obj, waitlist_attr).remove(account)
# session_obj.save()
# messages.success(request, "You have been removed from the waitlist. Thanks for letting us know.")
# else:
# getattr(session_obj, waitlist_attr).add(account)
# session_obj.save()
# messages.success(request, "Added to waitlist successfully.")
# return redirect(session_obj.get_absolute_url())


class SessionSignUpView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
template_name = "session_sign_up.html"
Expand All@@ -254,6 +151,8 @@ def dispatch(self, request, *args, **kwargs):
kwargs["mentor"] = get_object_or_404(Mentor, user=request.user)
kwargs["user_signed_up"] = session_orders.filter(mentor=kwargs["mentor"]).exists()

kwargs["spots_remaining"] = session_obj.mentor_capacity - session_orders.count()

elif request.user.role == "guardian":
kwargs["guardian"] = get_object_or_404(Guardian, user=request.user)
kwargs["student"] = get_object_or_404(Student, id=kwargs["student_id"])
Expand DownExpand Up@@ -286,6 +185,15 @@ def check_access(self, request, *args, **kwargs):
),
"redirect": request.META.get("HTTP_REFERER", "/dojo"),
}

# Check to make sure there is a spot open to sign up
if kwargs["spots_remaining"] <= 0:
access_dict = {
"message": (
"There are no slots open to mentor. Please check another class."
),
"redirect": request.META.get("HTTP_REFERER", kwargs["session_obj"].get_absolute_url()),
}

if kwargs.get("student"):
limits = self.student_limitations(kwargs["student"], kwargs["session_obj"], kwargs["user_signed_up"])
Expand DownExpand Up@@ -365,6 +273,25 @@ def post(self, request, *args, **kwargs):

return redirect(session_obj.get_absolute_url())

class SessionCancelView(View):
def get(self, request, *args, **kwargs):
pk = kwargs["pk"]
session = get_object_or_404(Session, id=pk)

# TODO: Do we need to check for this?
# if session.password and not self.validate_partner_session_access(request, pk):
# return redirect(reverse("session-password", kwargs=kwargs))

if request.user.is_authenticated:
if request.user.role == "mentor":
return mentor.SessionCancelView.as_view()(request, *args, **kwargs)
else:
return guardian.SessionCancelView.as_view()(request, *args, **kwargs)

return redirect(session.get_absolute_url())




class PasswordSessionView(TemplateView):
template_name = "session_partner_password.html"
Expand Down
12 changes: 6 additions & 6 deletions fixtures/12-coderdojochi.mentor.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,16 +29,16 @@
"user": 3,
"bio": "",
"is_active": true,
"background_check": false,
"is_public": false,
"background_check": true,
"is_public": true,
"avatar": "",
"avatar_approved": false,
"birthday": null,
"gender": null,
"avatar_approved": true,
"birthday": "1988-01-01",
"gender": "male",
"work_place": null,
"phone": null,
"home_address": null,
"race_ethnicity": []
"race_ethnicity": [2]
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion fixtures/14-coderdojochi.session.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
"start_date": "2022-01-01T16:00:00Z",
"location": 3,
"capacity": 20,
"mentor_capacity": 10,
"mentor_capacity": 1,
"instructor": 1,
"cost": "0.00",
"minimum_cost": null,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coderdojochi/models/session.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,6 +277,9 @@ def get_absolute_url(self) -> str:
def get_sign_up_url(self):
return reverse("session-sign-up", args=[str(self.id)])

def get_cancel_url(self):
return reverse("session-cancel", args=[str(self.id)])

def get_calendar_url(self):
return reverse("session-calendar", args=[str(self.id)])

Expand Down
33 changes: 33 additions & 0 deletions coderdojochi/templates/guardian/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Sign Up | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light"><strong>{{ student.full_name }}</strong> can no longer make it to the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Enroll <strong>{{ student.full_name }}</strong> for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
21 changes: 21 additions & 0 deletions coderdojochi/templates/mentor/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Cancel | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion coderdojochi/templates/mentor/session_detail.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ <h3 class="title text-primary">Class Details & Enrollment</h3>
{% else %}
{% if mentor_signed_up %}
<p>You are signed up to mentor this class.</p>
<p><a href="{{ session.get_sign_up_url }}" class="button large tertiary">I can't make it...</a></p>
<p><a href="{{ session.get_cancel_url }}" class="button large tertiary">I can't make it...</a></p>
{% else %}
{% if spots_remaining %}
<p><a href="{{ session.get_sign_up_url }}" class="button large secondary">Sign up now!</a></p>
Expand Down
24 changes: 6 additions & 18 deletions coderdojochi/templates/mentor/session_sign_up.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,26 +8,14 @@

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>
<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>
<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions coderdojochi/urls.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
SessionCalendarView,
SessionDetailView,
SessionSignUpView,
SessionCancelView,
WelcomeView,
meeting_announce,
meeting_sign_up,
Expand DownExpand Up@@ -156,6 +157,12 @@
path("<int:pk>/sign-up/", SessionSignUpView.as_view(), name="session-sign-up"),
# /classes/ID/sign-up/STUDENT-ID/
path("<int:pk>/sign-up/<int:student_id>/", SessionSignUpView.as_view(), name="session-sign-up"),

# Cancel session
# /classes/ID/cancel/
path("<int:pk>/cancel/", SessionCancelView.as_view(), name="session-cancel"),
# /classes/ID/cancel/STUDENT-ID/
path("<int:pk>/cancel/<int:student_id>/", SessionCancelView.as_view(), name="session-cancel"),
]
),
),
Expand Down
3 changes: 3 additions & 0 deletions coderdojochi/views/guardian/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,3 +19,6 @@ def get_context_data(self, **kwargs):
)

return context

class SessionCancelView(DetailView):
pass
52 changes: 49 additions & 3 deletions coderdojochi/views/mentor/sessions.py
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
from django.shortcuts import get_object_or_404
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404, redirect
from django.views.generic import DetailView

from ...models import Mentor, MentorOrder, Session
Expand All@@ -14,12 +15,11 @@ def get_context_data(self, **kwargs):

session_orders = MentorOrder.objects.filter(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
context["mentor_signed_up"] = session_orders.exists()
context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
context["spots_remaining"] = session.mentor_capacity - session_orders.count()
context["account"] = mentor

Expand All@@ -31,3 +31,49 @@ def get_context_data(self, **kwargs):
)

return context


class SessionCancelView(DetailView):
model = Session
template_name = "mentor/session_cancel.html"

# redirect if order not found
def get(self, request, *args, **kwargs):
try:
self.object = self.get_object()
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)
mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
except ObjectDoesNotExist:
return redirect(session.get_absolute_url())


def get_context_data(self, **kwargs):
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)

mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
# context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
# context["spots_remaining"] = session.mentor_capacity - session_orders.count()
# context["account"] = mentor

# context["active_mentors"] = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(
# session=self.object,
# is_active=True,
# ).values("mentor__id")
# )

return context
133 changes: 30 additions & 103 deletions coderdojochi/views/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,109 +136,6 @@ def validate_partner_session_access(self, request, pk):
return False


# class SessionDetailView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
# template_name = "session_detail.html"

# def dispatch(self, request, *args, **kwargs):
# session_obj = get_object_or_404(Session, id=kwargs["pk"])

# if request.method == "GET":
# if session_obj.password and not self.validate_partner_session_access(self.request, kwargs["pk"]):
# return redirect(reverse("session-password", kwargs=kwargs))

# if request.user.is_authenticated and request.user.role:
# if "enroll" in request.GET or "enroll" in kwargs:
# return self.enroll_redirect(request, session_obj)

# # kwargs["session_obj"] = session_obj
# return super(SessionDetailView, self).dispatch(request, *args, **kwargs)

# def enroll_redirect(self, request, session_obj):
# if request.user.role == "mentor":
# return redirect("session-sign-up", pk=session_obj.id)

# guardian = get_object_or_404(Guardian, user=request.user)
# student = get_object_or_404(Student, guardian=guardian, id=(int(request.GET["student"])))

# if student:
# return redirect("session-sign-up", pk=session_obj.id, student_id=student.id)

# return redirect(f"{reverse('welcome')}?next={session_obj.get_absolute_url()}&enroll=True")

# def validate_partner_session_access(self, request, pk):
# authed_sessions = request.session.get("authed_partner_sessions")

# if authed_sessions and pk in authed_sessions:
# if request.user.is_authenticated:
# PartnerPasswordAccess.objects.get_or_create(session_id=pk, user=request.user)
# return True

# if request.user.is_authenticated:
# try:
# PartnerPasswordAccess.objects.get(session_id=pk, user_id=request.user.id)
# except PartnerPasswordAccess.DoesNotExist:
# return False
# else:
# return True

# else:
# return False

# def get_context_data(self, **kwargs):
# print(kwargs["session_obj"].__dict__)
# context = super(SessionDetailView, self).get_context_data(**kwargs)
# session_obj = kwargs["session_obj"]
# context["session"] = session_obj

# upcoming_classes = Session.objects.filter(is_active=True, start_date__gte=timezone.now()).order_by("start_date")
# context["upcoming_classes"] = upcoming_classes

# active_mentors = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(session=session_obj, is_active=True).values("mentor__id")
# )
# context["active_mentors"] = active_mentors

# if self.request.user.is_authenticated:
# if self.request.user.role == "mentor":
# account = get_object_or_404(Mentor, user=self.request.user)
# session_orders = MentorOrder.objects.filter(session=session_obj, is_active=True,)
# context["mentor_signed_up"] = session_orders.filter(mentor=account).exists()

# context["spots_remaining"] = session_obj.get_mentor_capacity() - session_orders.count()
# else:
# account = get_object_or_404(Guardian, user=self.request.user)
# context["students"] = account.get_students()
# context["spots_remaining"] = session_obj.capacity - session_obj.get_active_student_count()
# context["account"] = account
# else:
# context["upcoming_classes"] = upcoming_classes.filter(is_public=True)
# context["spots_remaining"] = session_obj.capacity - session_obj.objects.get_active_student_count()

# return context

# def post(self, request, *args, **kwargs):
# session_obj = kwargs["session_obj"]
# if "waitlist" not in request.POST:
# messages.error(request, "Invalid request, please try again.")
# return redirect(session_obj.get_absolute_url())

# if request.POST["waitlist"] == "student":
# account = Student.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_students"
# else:
# account = Guardian.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_guardians"

# if request.POST["remove"] == "true":
# getattr(session_obj, waitlist_attr).remove(account)
# session_obj.save()
# messages.success(request, "You have been removed from the waitlist. Thanks for letting us know.")
# else:
# getattr(session_obj, waitlist_attr).add(account)
# session_obj.save()
# messages.success(request, "Added to waitlist successfully.")
# return redirect(session_obj.get_absolute_url())


class SessionSignUpView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
template_name = "session_sign_up.html"
Expand All@@ -254,6 +151,8 @@ def dispatch(self, request, *args, **kwargs):
kwargs["mentor"] = get_object_or_404(Mentor, user=request.user)
kwargs["user_signed_up"] = session_orders.filter(mentor=kwargs["mentor"]).exists()

kwargs["spots_remaining"] = session_obj.mentor_capacity - session_orders.count()

elif request.user.role == "guardian":
kwargs["guardian"] = get_object_or_404(Guardian, user=request.user)
kwargs["student"] = get_object_or_404(Student, id=kwargs["student_id"])
Expand DownExpand Up@@ -286,6 +185,15 @@ def check_access(self, request, *args, **kwargs):
),
"redirect": request.META.get("HTTP_REFERER", "/dojo"),
}

# Check to make sure there is a spot open to sign up
if kwargs["spots_remaining"] <= 0:
access_dict = {
"message": (
"There are no slots open to mentor. Please check another class."
),
"redirect": request.META.get("HTTP_REFERER", kwargs["session_obj"].get_absolute_url()),
}

if kwargs.get("student"):
limits = self.student_limitations(kwargs["student"], kwargs["session_obj"], kwargs["user_signed_up"])
Expand DownExpand Up@@ -365,6 +273,25 @@ def post(self, request, *args, **kwargs):

return redirect(session_obj.get_absolute_url())

class SessionCancelView(View):
def get(self, request, *args, **kwargs):
pk = kwargs["pk"]
session = get_object_or_404(Session, id=pk)

# TODO: Do we need to check for this?
# if session.password and not self.validate_partner_session_access(request, pk):
# return redirect(reverse("session-password", kwargs=kwargs))

if request.user.is_authenticated:
if request.user.role == "mentor":
return mentor.SessionCancelView.as_view()(request, *args, **kwargs)
else:
return guardian.SessionCancelView.as_view()(request, *args, **kwargs)

return redirect(session.get_absolute_url())




class PasswordSessionView(TemplateView):
template_name = "session_partner_password.html"
Expand Down
12 changes: 6 additions & 6 deletions fixtures/12-coderdojochi.mentor.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,16 +29,16 @@
"user": 3,
"bio": "",
"is_active": true,
"background_check": false,
"is_public": false,
"background_check": true,
"is_public": true,
"avatar": "",
"avatar_approved": false,
"birthday": null,
"gender": null,
"avatar_approved": true,
"birthday": "1988-01-01",
"gender": "male",
"work_place": null,
"phone": null,
"home_address": null,
"race_ethnicity": []
"race_ethnicity": [2]
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion fixtures/14-coderdojochi.session.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
"start_date": "2022-01-01T16:00:00Z",
"location": 3,
"capacity": 20,
"mentor_capacity": 10,
"mentor_capacity": 1,
"instructor": 1,
"cost": "0.00",
"minimum_cost": null,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coderdojochi/models/session.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,6 +277,9 @@ def get_absolute_url(self) -> str:
def get_sign_up_url(self):
return reverse("session-sign-up", args=[str(self.id)])

def get_cancel_url(self):
return reverse("session-cancel", args=[str(self.id)])

def get_calendar_url(self):
return reverse("session-calendar", args=[str(self.id)])

Expand Down
33 changes: 33 additions & 0 deletions coderdojochi/templates/guardian/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Sign Up | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light"><strong>{{ student.full_name }}</strong> can no longer make it to the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Enroll <strong>{{ student.full_name }}</strong> for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
21 changes: 21 additions & 0 deletions coderdojochi/templates/mentor/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Cancel | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion coderdojochi/templates/mentor/session_detail.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ <h3 class="title text-primary">Class Details & Enrollment</h3>
{% else %}
{% if mentor_signed_up %}
<p>You are signed up to mentor this class.</p>
<p><a href="{{ session.get_sign_up_url }}" class="button large tertiary">I can't make it...</a></p>
<p><a href="{{ session.get_cancel_url }}" class="button large tertiary">I can't make it...</a></p>
{% else %}
{% if spots_remaining %}
<p><a href="{{ session.get_sign_up_url }}" class="button large secondary">Sign up now!</a></p>
Expand Down
24 changes: 6 additions & 18 deletions coderdojochi/templates/mentor/session_sign_up.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,26 +8,14 @@

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>
<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>
<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions coderdojochi/urls.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
SessionCalendarView,
SessionDetailView,
SessionSignUpView,
SessionCancelView,
WelcomeView,
meeting_announce,
meeting_sign_up,
Expand DownExpand Up@@ -156,6 +157,12 @@
path("<int:pk>/sign-up/", SessionSignUpView.as_view(), name="session-sign-up"),
# /classes/ID/sign-up/STUDENT-ID/
path("<int:pk>/sign-up/<int:student_id>/", SessionSignUpView.as_view(), name="session-sign-up"),

# Cancel session
# /classes/ID/cancel/
path("<int:pk>/cancel/", SessionCancelView.as_view(), name="session-cancel"),
# /classes/ID/cancel/STUDENT-ID/
path("<int:pk>/cancel/<int:student_id>/", SessionCancelView.as_view(), name="session-cancel"),
]
),
),
Expand Down
3 changes: 3 additions & 0 deletions coderdojochi/views/guardian/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,3 +19,6 @@ def get_context_data(self, **kwargs):
)

return context

class SessionCancelView(DetailView):
pass
52 changes: 49 additions & 3 deletions coderdojochi/views/mentor/sessions.py
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
from django.shortcuts import get_object_or_404
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404, redirect
from django.views.generic import DetailView

from ...models import Mentor, MentorOrder, Session
Expand All@@ -14,12 +15,11 @@ def get_context_data(self, **kwargs):

session_orders = MentorOrder.objects.filter(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
context["mentor_signed_up"] = session_orders.exists()
context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
context["spots_remaining"] = session.mentor_capacity - session_orders.count()
context["account"] = mentor

Expand All@@ -31,3 +31,49 @@ def get_context_data(self, **kwargs):
)

return context


class SessionCancelView(DetailView):
model = Session
template_name = "mentor/session_cancel.html"

# redirect if order not found
def get(self, request, *args, **kwargs):
try:
self.object = self.get_object()
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)
mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
except ObjectDoesNotExist:
return redirect(session.get_absolute_url())


def get_context_data(self, **kwargs):
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)

mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
# context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
# context["spots_remaining"] = session.mentor_capacity - session_orders.count()
# context["account"] = mentor

# context["active_mentors"] = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(
# session=self.object,
# is_active=True,
# ).values("mentor__id")
# )

return context
133 changes: 30 additions & 103 deletions coderdojochi/views/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,109 +136,6 @@ def validate_partner_session_access(self, request, pk):
return False


# class SessionDetailView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
# template_name = "session_detail.html"

# def dispatch(self, request, *args, **kwargs):
# session_obj = get_object_or_404(Session, id=kwargs["pk"])

# if request.method == "GET":
# if session_obj.password and not self.validate_partner_session_access(self.request, kwargs["pk"]):
# return redirect(reverse("session-password", kwargs=kwargs))

# if request.user.is_authenticated and request.user.role:
# if "enroll" in request.GET or "enroll" in kwargs:
# return self.enroll_redirect(request, session_obj)

# # kwargs["session_obj"] = session_obj
# return super(SessionDetailView, self).dispatch(request, *args, **kwargs)

# def enroll_redirect(self, request, session_obj):
# if request.user.role == "mentor":
# return redirect("session-sign-up", pk=session_obj.id)

# guardian = get_object_or_404(Guardian, user=request.user)
# student = get_object_or_404(Student, guardian=guardian, id=(int(request.GET["student"])))

# if student:
# return redirect("session-sign-up", pk=session_obj.id, student_id=student.id)

# return redirect(f"{reverse('welcome')}?next={session_obj.get_absolute_url()}&enroll=True")

# def validate_partner_session_access(self, request, pk):
# authed_sessions = request.session.get("authed_partner_sessions")

# if authed_sessions and pk in authed_sessions:
# if request.user.is_authenticated:
# PartnerPasswordAccess.objects.get_or_create(session_id=pk, user=request.user)
# return True

# if request.user.is_authenticated:
# try:
# PartnerPasswordAccess.objects.get(session_id=pk, user_id=request.user.id)
# except PartnerPasswordAccess.DoesNotExist:
# return False
# else:
# return True

# else:
# return False

# def get_context_data(self, **kwargs):
# print(kwargs["session_obj"].__dict__)
# context = super(SessionDetailView, self).get_context_data(**kwargs)
# session_obj = kwargs["session_obj"]
# context["session"] = session_obj

# upcoming_classes = Session.objects.filter(is_active=True, start_date__gte=timezone.now()).order_by("start_date")
# context["upcoming_classes"] = upcoming_classes

# active_mentors = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(session=session_obj, is_active=True).values("mentor__id")
# )
# context["active_mentors"] = active_mentors

# if self.request.user.is_authenticated:
# if self.request.user.role == "mentor":
# account = get_object_or_404(Mentor, user=self.request.user)
# session_orders = MentorOrder.objects.filter(session=session_obj, is_active=True,)
# context["mentor_signed_up"] = session_orders.filter(mentor=account).exists()

# context["spots_remaining"] = session_obj.get_mentor_capacity() - session_orders.count()
# else:
# account = get_object_or_404(Guardian, user=self.request.user)
# context["students"] = account.get_students()
# context["spots_remaining"] = session_obj.capacity - session_obj.get_active_student_count()
# context["account"] = account
# else:
# context["upcoming_classes"] = upcoming_classes.filter(is_public=True)
# context["spots_remaining"] = session_obj.capacity - session_obj.objects.get_active_student_count()

# return context

# def post(self, request, *args, **kwargs):
# session_obj = kwargs["session_obj"]
# if "waitlist" not in request.POST:
# messages.error(request, "Invalid request, please try again.")
# return redirect(session_obj.get_absolute_url())

# if request.POST["waitlist"] == "student":
# account = Student.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_students"
# else:
# account = Guardian.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_guardians"

# if request.POST["remove"] == "true":
# getattr(session_obj, waitlist_attr).remove(account)
# session_obj.save()
# messages.success(request, "You have been removed from the waitlist. Thanks for letting us know.")
# else:
# getattr(session_obj, waitlist_attr).add(account)
# session_obj.save()
# messages.success(request, "Added to waitlist successfully.")
# return redirect(session_obj.get_absolute_url())


class SessionSignUpView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
template_name = "session_sign_up.html"
Expand All@@ -254,6 +151,8 @@ def dispatch(self, request, *args, **kwargs):
kwargs["mentor"] = get_object_or_404(Mentor, user=request.user)
kwargs["user_signed_up"] = session_orders.filter(mentor=kwargs["mentor"]).exists()

kwargs["spots_remaining"] = session_obj.mentor_capacity - session_orders.count()

elif request.user.role == "guardian":
kwargs["guardian"] = get_object_or_404(Guardian, user=request.user)
kwargs["student"] = get_object_or_404(Student, id=kwargs["student_id"])
Expand DownExpand Up@@ -286,6 +185,15 @@ def check_access(self, request, *args, **kwargs):
),
"redirect": request.META.get("HTTP_REFERER", "/dojo"),
}

# Check to make sure there is a spot open to sign up
if kwargs["spots_remaining"] <= 0:
access_dict = {
"message": (
"There are no slots open to mentor. Please check another class."
),
"redirect": request.META.get("HTTP_REFERER", kwargs["session_obj"].get_absolute_url()),
}

if kwargs.get("student"):
limits = self.student_limitations(kwargs["student"], kwargs["session_obj"], kwargs["user_signed_up"])
Expand DownExpand Up@@ -365,6 +273,25 @@ def post(self, request, *args, **kwargs):

return redirect(session_obj.get_absolute_url())

class SessionCancelView(View):
def get(self, request, *args, **kwargs):
pk = kwargs["pk"]
session = get_object_or_404(Session, id=pk)

# TODO: Do we need to check for this?
# if session.password and not self.validate_partner_session_access(request, pk):
# return redirect(reverse("session-password", kwargs=kwargs))

if request.user.is_authenticated:
if request.user.role == "mentor":
return mentor.SessionCancelView.as_view()(request, *args, **kwargs)
else:
return guardian.SessionCancelView.as_view()(request, *args, **kwargs)

return redirect(session.get_absolute_url())




class PasswordSessionView(TemplateView):
template_name = "session_partner_password.html"
Expand Down
12 changes: 6 additions & 6 deletions fixtures/12-coderdojochi.mentor.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,16 +29,16 @@
"user": 3,
"bio": "",
"is_active": true,
"background_check": false,
"is_public": false,
"background_check": true,
"is_public": true,
"avatar": "",
"avatar_approved": false,
"birthday": null,
"gender": null,
"avatar_approved": true,
"birthday": "1988-01-01",
"gender": "male",
"work_place": null,
"phone": null,
"home_address": null,
"race_ethnicity": []
"race_ethnicity": [2]
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion fixtures/14-coderdojochi.session.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
"start_date": "2022-01-01T16:00:00Z",
"location": 3,
"capacity": 20,
"mentor_capacity": 10,
"mentor_capacity": 1,
"instructor": 1,
"cost": "0.00",
"minimum_cost": null,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coderdojochi/models/session.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,6 +277,9 @@ def get_absolute_url(self) -> str:
def get_sign_up_url(self):
return reverse("session-sign-up", args=[str(self.id)])

def get_cancel_url(self):
return reverse("session-cancel", args=[str(self.id)])

def get_calendar_url(self):
return reverse("session-calendar", args=[str(self.id)])

Expand Down
33 changes: 33 additions & 0 deletions coderdojochi/templates/guardian/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Sign Up | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light"><strong>{{ student.full_name }}</strong> can no longer make it to the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Enroll <strong>{{ student.full_name }}</strong> for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
21 changes: 21 additions & 0 deletions coderdojochi/templates/mentor/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Cancel | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion coderdojochi/templates/mentor/session_detail.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ <h3 class="title text-primary">Class Details & Enrollment</h3>
{% else %}
{% if mentor_signed_up %}
<p>You are signed up to mentor this class.</p>
<p><a href="{{ session.get_sign_up_url }}" class="button large tertiary">I can't make it...</a></p>
<p><a href="{{ session.get_cancel_url }}" class="button large tertiary">I can't make it...</a></p>
{% else %}
{% if spots_remaining %}
<p><a href="{{ session.get_sign_up_url }}" class="button large secondary">Sign up now!</a></p>
Expand Down
24 changes: 6 additions & 18 deletions coderdojochi/templates/mentor/session_sign_up.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,26 +8,14 @@

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>
<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>
<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions coderdojochi/urls.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
SessionCalendarView,
SessionDetailView,
SessionSignUpView,
SessionCancelView,
WelcomeView,
meeting_announce,
meeting_sign_up,
Expand DownExpand Up@@ -156,6 +157,12 @@
path("<int:pk>/sign-up/", SessionSignUpView.as_view(), name="session-sign-up"),
# /classes/ID/sign-up/STUDENT-ID/
path("<int:pk>/sign-up/<int:student_id>/", SessionSignUpView.as_view(), name="session-sign-up"),

# Cancel session
# /classes/ID/cancel/
path("<int:pk>/cancel/", SessionCancelView.as_view(), name="session-cancel"),
# /classes/ID/cancel/STUDENT-ID/
path("<int:pk>/cancel/<int:student_id>/", SessionCancelView.as_view(), name="session-cancel"),
]
),
),
Expand Down
3 changes: 3 additions & 0 deletions coderdojochi/views/guardian/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,3 +19,6 @@ def get_context_data(self, **kwargs):
)

return context

class SessionCancelView(DetailView):
pass
52 changes: 49 additions & 3 deletions coderdojochi/views/mentor/sessions.py
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
from django.shortcuts import get_object_or_404
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404, redirect
from django.views.generic import DetailView

from ...models import Mentor, MentorOrder, Session
Expand All@@ -14,12 +15,11 @@ def get_context_data(self, **kwargs):

session_orders = MentorOrder.objects.filter(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
context["mentor_signed_up"] = session_orders.exists()
context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
context["spots_remaining"] = session.mentor_capacity - session_orders.count()
context["account"] = mentor

Expand All@@ -31,3 +31,49 @@ def get_context_data(self, **kwargs):
)

return context


class SessionCancelView(DetailView):
model = Session
template_name = "mentor/session_cancel.html"

# redirect if order not found
def get(self, request, *args, **kwargs):
try:
self.object = self.get_object()
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)
mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
except ObjectDoesNotExist:
return redirect(session.get_absolute_url())


def get_context_data(self, **kwargs):
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)

mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
# context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
# context["spots_remaining"] = session.mentor_capacity - session_orders.count()
# context["account"] = mentor

# context["active_mentors"] = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(
# session=self.object,
# is_active=True,
# ).values("mentor__id")
# )

return context
133 changes: 30 additions & 103 deletions coderdojochi/views/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,109 +136,6 @@ def validate_partner_session_access(self, request, pk):
return False


# class SessionDetailView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
# template_name = "session_detail.html"

# def dispatch(self, request, *args, **kwargs):
# session_obj = get_object_or_404(Session, id=kwargs["pk"])

# if request.method == "GET":
# if session_obj.password and not self.validate_partner_session_access(self.request, kwargs["pk"]):
# return redirect(reverse("session-password", kwargs=kwargs))

# if request.user.is_authenticated and request.user.role:
# if "enroll" in request.GET or "enroll" in kwargs:
# return self.enroll_redirect(request, session_obj)

# # kwargs["session_obj"] = session_obj
# return super(SessionDetailView, self).dispatch(request, *args, **kwargs)

# def enroll_redirect(self, request, session_obj):
# if request.user.role == "mentor":
# return redirect("session-sign-up", pk=session_obj.id)

# guardian = get_object_or_404(Guardian, user=request.user)
# student = get_object_or_404(Student, guardian=guardian, id=(int(request.GET["student"])))

# if student:
# return redirect("session-sign-up", pk=session_obj.id, student_id=student.id)

# return redirect(f"{reverse('welcome')}?next={session_obj.get_absolute_url()}&enroll=True")

# def validate_partner_session_access(self, request, pk):
# authed_sessions = request.session.get("authed_partner_sessions")

# if authed_sessions and pk in authed_sessions:
# if request.user.is_authenticated:
# PartnerPasswordAccess.objects.get_or_create(session_id=pk, user=request.user)
# return True

# if request.user.is_authenticated:
# try:
# PartnerPasswordAccess.objects.get(session_id=pk, user_id=request.user.id)
# except PartnerPasswordAccess.DoesNotExist:
# return False
# else:
# return True

# else:
# return False

# def get_context_data(self, **kwargs):
# print(kwargs["session_obj"].__dict__)
# context = super(SessionDetailView, self).get_context_data(**kwargs)
# session_obj = kwargs["session_obj"]
# context["session"] = session_obj

# upcoming_classes = Session.objects.filter(is_active=True, start_date__gte=timezone.now()).order_by("start_date")
# context["upcoming_classes"] = upcoming_classes

# active_mentors = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(session=session_obj, is_active=True).values("mentor__id")
# )
# context["active_mentors"] = active_mentors

# if self.request.user.is_authenticated:
# if self.request.user.role == "mentor":
# account = get_object_or_404(Mentor, user=self.request.user)
# session_orders = MentorOrder.objects.filter(session=session_obj, is_active=True,)
# context["mentor_signed_up"] = session_orders.filter(mentor=account).exists()

# context["spots_remaining"] = session_obj.get_mentor_capacity() - session_orders.count()
# else:
# account = get_object_or_404(Guardian, user=self.request.user)
# context["students"] = account.get_students()
# context["spots_remaining"] = session_obj.capacity - session_obj.get_active_student_count()
# context["account"] = account
# else:
# context["upcoming_classes"] = upcoming_classes.filter(is_public=True)
# context["spots_remaining"] = session_obj.capacity - session_obj.objects.get_active_student_count()

# return context

# def post(self, request, *args, **kwargs):
# session_obj = kwargs["session_obj"]
# if "waitlist" not in request.POST:
# messages.error(request, "Invalid request, please try again.")
# return redirect(session_obj.get_absolute_url())

# if request.POST["waitlist"] == "student":
# account = Student.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_students"
# else:
# account = Guardian.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_guardians"

# if request.POST["remove"] == "true":
# getattr(session_obj, waitlist_attr).remove(account)
# session_obj.save()
# messages.success(request, "You have been removed from the waitlist. Thanks for letting us know.")
# else:
# getattr(session_obj, waitlist_attr).add(account)
# session_obj.save()
# messages.success(request, "Added to waitlist successfully.")
# return redirect(session_obj.get_absolute_url())


class SessionSignUpView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
template_name = "session_sign_up.html"
Expand All@@ -254,6 +151,8 @@ def dispatch(self, request, *args, **kwargs):
kwargs["mentor"] = get_object_or_404(Mentor, user=request.user)
kwargs["user_signed_up"] = session_orders.filter(mentor=kwargs["mentor"]).exists()

kwargs["spots_remaining"] = session_obj.mentor_capacity - session_orders.count()

elif request.user.role == "guardian":
kwargs["guardian"] = get_object_or_404(Guardian, user=request.user)
kwargs["student"] = get_object_or_404(Student, id=kwargs["student_id"])
Expand DownExpand Up@@ -286,6 +185,15 @@ def check_access(self, request, *args, **kwargs):
),
"redirect": request.META.get("HTTP_REFERER", "/dojo"),
}

# Check to make sure there is a spot open to sign up
if kwargs["spots_remaining"] <= 0:
access_dict = {
"message": (
"There are no slots open to mentor. Please check another class."
),
"redirect": request.META.get("HTTP_REFERER", kwargs["session_obj"].get_absolute_url()),
}

if kwargs.get("student"):
limits = self.student_limitations(kwargs["student"], kwargs["session_obj"], kwargs["user_signed_up"])
Expand DownExpand Up@@ -365,6 +273,25 @@ def post(self, request, *args, **kwargs):

return redirect(session_obj.get_absolute_url())

class SessionCancelView(View):
def get(self, request, *args, **kwargs):
pk = kwargs["pk"]
session = get_object_or_404(Session, id=pk)

# TODO: Do we need to check for this?
# if session.password and not self.validate_partner_session_access(request, pk):
# return redirect(reverse("session-password", kwargs=kwargs))

if request.user.is_authenticated:
if request.user.role == "mentor":
return mentor.SessionCancelView.as_view()(request, *args, **kwargs)
else:
return guardian.SessionCancelView.as_view()(request, *args, **kwargs)

return redirect(session.get_absolute_url())




class PasswordSessionView(TemplateView):
template_name = "session_partner_password.html"
Expand Down
12 changes: 6 additions & 6 deletions fixtures/12-coderdojochi.mentor.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,16 +29,16 @@
"user": 3,
"bio": "",
"is_active": true,
"background_check": false,
"is_public": false,
"background_check": true,
"is_public": true,
"avatar": "",
"avatar_approved": false,
"birthday": null,
"gender": null,
"avatar_approved": true,
"birthday": "1988-01-01",
"gender": "male",
"work_place": null,
"phone": null,
"home_address": null,
"race_ethnicity": []
"race_ethnicity": [2]
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion fixtures/14-coderdojochi.session.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
"start_date": "2022-01-01T16:00:00Z",
"location": 3,
"capacity": 20,
"mentor_capacity": 10,
"mentor_capacity": 1,
"instructor": 1,
"cost": "0.00",
"minimum_cost": null,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coderdojochi/models/session.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,6 +277,9 @@ def get_absolute_url(self) -> str:
def get_sign_up_url(self):
return reverse("session-sign-up", args=[str(self.id)])

def get_cancel_url(self):
return reverse("session-cancel", args=[str(self.id)])

def get_calendar_url(self):
return reverse("session-calendar", args=[str(self.id)])

Expand Down
33 changes: 33 additions & 0 deletions coderdojochi/templates/guardian/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Sign Up | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light"><strong>{{ student.full_name }}</strong> can no longer make it to the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Enroll <strong>{{ student.full_name }}</strong> for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
21 changes: 21 additions & 0 deletions coderdojochi/templates/mentor/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Cancel | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion coderdojochi/templates/mentor/session_detail.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ <h3 class="title text-primary">Class Details & Enrollment</h3>
{% else %}
{% if mentor_signed_up %}
<p>You are signed up to mentor this class.</p>
<p><a href="{{ session.get_sign_up_url }}" class="button large tertiary">I can't make it...</a></p>
<p><a href="{{ session.get_cancel_url }}" class="button large tertiary">I can't make it...</a></p>
{% else %}
{% if spots_remaining %}
<p><a href="{{ session.get_sign_up_url }}" class="button large secondary">Sign up now!</a></p>
Expand Down
24 changes: 6 additions & 18 deletions coderdojochi/templates/mentor/session_sign_up.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,26 +8,14 @@

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>
<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>
<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions coderdojochi/urls.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
SessionCalendarView,
SessionDetailView,
SessionSignUpView,
SessionCancelView,
WelcomeView,
meeting_announce,
meeting_sign_up,
Expand DownExpand Up@@ -156,6 +157,12 @@
path("<int:pk>/sign-up/", SessionSignUpView.as_view(), name="session-sign-up"),
# /classes/ID/sign-up/STUDENT-ID/
path("<int:pk>/sign-up/<int:student_id>/", SessionSignUpView.as_view(), name="session-sign-up"),

# Cancel session
# /classes/ID/cancel/
path("<int:pk>/cancel/", SessionCancelView.as_view(), name="session-cancel"),
# /classes/ID/cancel/STUDENT-ID/
path("<int:pk>/cancel/<int:student_id>/", SessionCancelView.as_view(), name="session-cancel"),
]
),
),
Expand Down
3 changes: 3 additions & 0 deletions coderdojochi/views/guardian/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,3 +19,6 @@ def get_context_data(self, **kwargs):
)

return context

class SessionCancelView(DetailView):
pass
52 changes: 49 additions & 3 deletions coderdojochi/views/mentor/sessions.py
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
from django.shortcuts import get_object_or_404
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404, redirect
from django.views.generic import DetailView

from ...models import Mentor, MentorOrder, Session
Expand All@@ -14,12 +15,11 @@ def get_context_data(self, **kwargs):

session_orders = MentorOrder.objects.filter(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
context["mentor_signed_up"] = session_orders.exists()
context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
context["spots_remaining"] = session.mentor_capacity - session_orders.count()
context["account"] = mentor

Expand All@@ -31,3 +31,49 @@ def get_context_data(self, **kwargs):
)

return context


class SessionCancelView(DetailView):
model = Session
template_name = "mentor/session_cancel.html"

# redirect if order not found
def get(self, request, *args, **kwargs):
try:
self.object = self.get_object()
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)
mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
except ObjectDoesNotExist:
return redirect(session.get_absolute_url())


def get_context_data(self, **kwargs):
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)

mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
# context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
# context["spots_remaining"] = session.mentor_capacity - session_orders.count()
# context["account"] = mentor

# context["active_mentors"] = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(
# session=self.object,
# is_active=True,
# ).values("mentor__id")
# )

return context
133 changes: 30 additions & 103 deletions coderdojochi/views/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,109 +136,6 @@ def validate_partner_session_access(self, request, pk):
return False


# class SessionDetailView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
# template_name = "session_detail.html"

# def dispatch(self, request, *args, **kwargs):
# session_obj = get_object_or_404(Session, id=kwargs["pk"])

# if request.method == "GET":
# if session_obj.password and not self.validate_partner_session_access(self.request, kwargs["pk"]):
# return redirect(reverse("session-password", kwargs=kwargs))

# if request.user.is_authenticated and request.user.role:
# if "enroll" in request.GET or "enroll" in kwargs:
# return self.enroll_redirect(request, session_obj)

# # kwargs["session_obj"] = session_obj
# return super(SessionDetailView, self).dispatch(request, *args, **kwargs)

# def enroll_redirect(self, request, session_obj):
# if request.user.role == "mentor":
# return redirect("session-sign-up", pk=session_obj.id)

# guardian = get_object_or_404(Guardian, user=request.user)
# student = get_object_or_404(Student, guardian=guardian, id=(int(request.GET["student"])))

# if student:
# return redirect("session-sign-up", pk=session_obj.id, student_id=student.id)

# return redirect(f"{reverse('welcome')}?next={session_obj.get_absolute_url()}&enroll=True")

# def validate_partner_session_access(self, request, pk):
# authed_sessions = request.session.get("authed_partner_sessions")

# if authed_sessions and pk in authed_sessions:
# if request.user.is_authenticated:
# PartnerPasswordAccess.objects.get_or_create(session_id=pk, user=request.user)
# return True

# if request.user.is_authenticated:
# try:
# PartnerPasswordAccess.objects.get(session_id=pk, user_id=request.user.id)
# except PartnerPasswordAccess.DoesNotExist:
# return False
# else:
# return True

# else:
# return False

# def get_context_data(self, **kwargs):
# print(kwargs["session_obj"].__dict__)
# context = super(SessionDetailView, self).get_context_data(**kwargs)
# session_obj = kwargs["session_obj"]
# context["session"] = session_obj

# upcoming_classes = Session.objects.filter(is_active=True, start_date__gte=timezone.now()).order_by("start_date")
# context["upcoming_classes"] = upcoming_classes

# active_mentors = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(session=session_obj, is_active=True).values("mentor__id")
# )
# context["active_mentors"] = active_mentors

# if self.request.user.is_authenticated:
# if self.request.user.role == "mentor":
# account = get_object_or_404(Mentor, user=self.request.user)
# session_orders = MentorOrder.objects.filter(session=session_obj, is_active=True,)
# context["mentor_signed_up"] = session_orders.filter(mentor=account).exists()

# context["spots_remaining"] = session_obj.get_mentor_capacity() - session_orders.count()
# else:
# account = get_object_or_404(Guardian, user=self.request.user)
# context["students"] = account.get_students()
# context["spots_remaining"] = session_obj.capacity - session_obj.get_active_student_count()
# context["account"] = account
# else:
# context["upcoming_classes"] = upcoming_classes.filter(is_public=True)
# context["spots_remaining"] = session_obj.capacity - session_obj.objects.get_active_student_count()

# return context

# def post(self, request, *args, **kwargs):
# session_obj = kwargs["session_obj"]
# if "waitlist" not in request.POST:
# messages.error(request, "Invalid request, please try again.")
# return redirect(session_obj.get_absolute_url())

# if request.POST["waitlist"] == "student":
# account = Student.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_students"
# else:
# account = Guardian.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_guardians"

# if request.POST["remove"] == "true":
# getattr(session_obj, waitlist_attr).remove(account)
# session_obj.save()
# messages.success(request, "You have been removed from the waitlist. Thanks for letting us know.")
# else:
# getattr(session_obj, waitlist_attr).add(account)
# session_obj.save()
# messages.success(request, "Added to waitlist successfully.")
# return redirect(session_obj.get_absolute_url())


class SessionSignUpView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
template_name = "session_sign_up.html"
Expand All@@ -254,6 +151,8 @@ def dispatch(self, request, *args, **kwargs):
kwargs["mentor"] = get_object_or_404(Mentor, user=request.user)
kwargs["user_signed_up"] = session_orders.filter(mentor=kwargs["mentor"]).exists()

kwargs["spots_remaining"] = session_obj.mentor_capacity - session_orders.count()

elif request.user.role == "guardian":
kwargs["guardian"] = get_object_or_404(Guardian, user=request.user)
kwargs["student"] = get_object_or_404(Student, id=kwargs["student_id"])
Expand DownExpand Up@@ -286,6 +185,15 @@ def check_access(self, request, *args, **kwargs):
),
"redirect": request.META.get("HTTP_REFERER", "/dojo"),
}

# Check to make sure there is a spot open to sign up
if kwargs["spots_remaining"] <= 0:
access_dict = {
"message": (
"There are no slots open to mentor. Please check another class."
),
"redirect": request.META.get("HTTP_REFERER", kwargs["session_obj"].get_absolute_url()),
}

if kwargs.get("student"):
limits = self.student_limitations(kwargs["student"], kwargs["session_obj"], kwargs["user_signed_up"])
Expand DownExpand Up@@ -365,6 +273,25 @@ def post(self, request, *args, **kwargs):

return redirect(session_obj.get_absolute_url())

class SessionCancelView(View):
def get(self, request, *args, **kwargs):
pk = kwargs["pk"]
session = get_object_or_404(Session, id=pk)

# TODO: Do we need to check for this?
# if session.password and not self.validate_partner_session_access(request, pk):
# return redirect(reverse("session-password", kwargs=kwargs))

if request.user.is_authenticated:
if request.user.role == "mentor":
return mentor.SessionCancelView.as_view()(request, *args, **kwargs)
else:
return guardian.SessionCancelView.as_view()(request, *args, **kwargs)

return redirect(session.get_absolute_url())




class PasswordSessionView(TemplateView):
template_name = "session_partner_password.html"
Expand Down
12 changes: 6 additions & 6 deletions fixtures/12-coderdojochi.mentor.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,16 +29,16 @@
"user": 3,
"bio": "",
"is_active": true,
"background_check": false,
"is_public": false,
"background_check": true,
"is_public": true,
"avatar": "",
"avatar_approved": false,
"birthday": null,
"gender": null,
"avatar_approved": true,
"birthday": "1988-01-01",
"gender": "male",
"work_place": null,
"phone": null,
"home_address": null,
"race_ethnicity": []
"race_ethnicity": [2]
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion fixtures/14-coderdojochi.session.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
"start_date": "2022-01-01T16:00:00Z",
"location": 3,
"capacity": 20,
"mentor_capacity": 10,
"mentor_capacity": 1,
"instructor": 1,
"cost": "0.00",
"minimum_cost": null,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coderdojochi/models/session.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,6 +277,9 @@ def get_absolute_url(self) -> str:
def get_sign_up_url(self):
return reverse("session-sign-up", args=[str(self.id)])

def get_cancel_url(self):
return reverse("session-cancel", args=[str(self.id)])

def get_calendar_url(self):
return reverse("session-calendar", args=[str(self.id)])

Expand Down
33 changes: 33 additions & 0 deletions coderdojochi/templates/guardian/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Sign Up | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light"><strong>{{ student.full_name }}</strong> can no longer make it to the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Enroll <strong>{{ student.full_name }}</strong> for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
21 changes: 21 additions & 0 deletions coderdojochi/templates/mentor/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Cancel | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion coderdojochi/templates/mentor/session_detail.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ <h3 class="title text-primary">Class Details & Enrollment</h3>
{% else %}
{% if mentor_signed_up %}
<p>You are signed up to mentor this class.</p>
<p><a href="{{ session.get_sign_up_url }}" class="button large tertiary">I can't make it...</a></p>
<p><a href="{{ session.get_cancel_url }}" class="button large tertiary">I can't make it...</a></p>
{% else %}
{% if spots_remaining %}
<p><a href="{{ session.get_sign_up_url }}" class="button large secondary">Sign up now!</a></p>
Expand Down
24 changes: 6 additions & 18 deletions coderdojochi/templates/mentor/session_sign_up.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,26 +8,14 @@

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>
<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>
<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions coderdojochi/urls.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
SessionCalendarView,
SessionDetailView,
SessionSignUpView,
SessionCancelView,
WelcomeView,
meeting_announce,
meeting_sign_up,
Expand DownExpand Up@@ -156,6 +157,12 @@
path("<int:pk>/sign-up/", SessionSignUpView.as_view(), name="session-sign-up"),
# /classes/ID/sign-up/STUDENT-ID/
path("<int:pk>/sign-up/<int:student_id>/", SessionSignUpView.as_view(), name="session-sign-up"),

# Cancel session
# /classes/ID/cancel/
path("<int:pk>/cancel/", SessionCancelView.as_view(), name="session-cancel"),
# /classes/ID/cancel/STUDENT-ID/
path("<int:pk>/cancel/<int:student_id>/", SessionCancelView.as_view(), name="session-cancel"),
]
),
),
Expand Down
3 changes: 3 additions & 0 deletions coderdojochi/views/guardian/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,3 +19,6 @@ def get_context_data(self, **kwargs):
)

return context

class SessionCancelView(DetailView):
pass
52 changes: 49 additions & 3 deletions coderdojochi/views/mentor/sessions.py
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
from django.shortcuts import get_object_or_404
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404, redirect
from django.views.generic import DetailView

from ...models import Mentor, MentorOrder, Session
Expand All@@ -14,12 +15,11 @@ def get_context_data(self, **kwargs):

session_orders = MentorOrder.objects.filter(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
context["mentor_signed_up"] = session_orders.exists()
context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
context["spots_remaining"] = session.mentor_capacity - session_orders.count()
context["account"] = mentor

Expand All@@ -31,3 +31,49 @@ def get_context_data(self, **kwargs):
)

return context


class SessionCancelView(DetailView):
model = Session
template_name = "mentor/session_cancel.html"

# redirect if order not found
def get(self, request, *args, **kwargs):
try:
self.object = self.get_object()
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)
mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
except ObjectDoesNotExist:
return redirect(session.get_absolute_url())


def get_context_data(self, **kwargs):
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)

mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
# context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
# context["spots_remaining"] = session.mentor_capacity - session_orders.count()
# context["account"] = mentor

# context["active_mentors"] = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(
# session=self.object,
# is_active=True,
# ).values("mentor__id")
# )

return context
133 changes: 30 additions & 103 deletions coderdojochi/views/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,109 +136,6 @@ def validate_partner_session_access(self, request, pk):
return False


# class SessionDetailView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
# template_name = "session_detail.html"

# def dispatch(self, request, *args, **kwargs):
# session_obj = get_object_or_404(Session, id=kwargs["pk"])

# if request.method == "GET":
# if session_obj.password and not self.validate_partner_session_access(self.request, kwargs["pk"]):
# return redirect(reverse("session-password", kwargs=kwargs))

# if request.user.is_authenticated and request.user.role:
# if "enroll" in request.GET or "enroll" in kwargs:
# return self.enroll_redirect(request, session_obj)

# # kwargs["session_obj"] = session_obj
# return super(SessionDetailView, self).dispatch(request, *args, **kwargs)

# def enroll_redirect(self, request, session_obj):
# if request.user.role == "mentor":
# return redirect("session-sign-up", pk=session_obj.id)

# guardian = get_object_or_404(Guardian, user=request.user)
# student = get_object_or_404(Student, guardian=guardian, id=(int(request.GET["student"])))

# if student:
# return redirect("session-sign-up", pk=session_obj.id, student_id=student.id)

# return redirect(f"{reverse('welcome')}?next={session_obj.get_absolute_url()}&enroll=True")

# def validate_partner_session_access(self, request, pk):
# authed_sessions = request.session.get("authed_partner_sessions")

# if authed_sessions and pk in authed_sessions:
# if request.user.is_authenticated:
# PartnerPasswordAccess.objects.get_or_create(session_id=pk, user=request.user)
# return True

# if request.user.is_authenticated:
# try:
# PartnerPasswordAccess.objects.get(session_id=pk, user_id=request.user.id)
# except PartnerPasswordAccess.DoesNotExist:
# return False
# else:
# return True

# else:
# return False

# def get_context_data(self, **kwargs):
# print(kwargs["session_obj"].__dict__)
# context = super(SessionDetailView, self).get_context_data(**kwargs)
# session_obj = kwargs["session_obj"]
# context["session"] = session_obj

# upcoming_classes = Session.objects.filter(is_active=True, start_date__gte=timezone.now()).order_by("start_date")
# context["upcoming_classes"] = upcoming_classes

# active_mentors = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(session=session_obj, is_active=True).values("mentor__id")
# )
# context["active_mentors"] = active_mentors

# if self.request.user.is_authenticated:
# if self.request.user.role == "mentor":
# account = get_object_or_404(Mentor, user=self.request.user)
# session_orders = MentorOrder.objects.filter(session=session_obj, is_active=True,)
# context["mentor_signed_up"] = session_orders.filter(mentor=account).exists()

# context["spots_remaining"] = session_obj.get_mentor_capacity() - session_orders.count()
# else:
# account = get_object_or_404(Guardian, user=self.request.user)
# context["students"] = account.get_students()
# context["spots_remaining"] = session_obj.capacity - session_obj.get_active_student_count()
# context["account"] = account
# else:
# context["upcoming_classes"] = upcoming_classes.filter(is_public=True)
# context["spots_remaining"] = session_obj.capacity - session_obj.objects.get_active_student_count()

# return context

# def post(self, request, *args, **kwargs):
# session_obj = kwargs["session_obj"]
# if "waitlist" not in request.POST:
# messages.error(request, "Invalid request, please try again.")
# return redirect(session_obj.get_absolute_url())

# if request.POST["waitlist"] == "student":
# account = Student.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_students"
# else:
# account = Guardian.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_guardians"

# if request.POST["remove"] == "true":
# getattr(session_obj, waitlist_attr).remove(account)
# session_obj.save()
# messages.success(request, "You have been removed from the waitlist. Thanks for letting us know.")
# else:
# getattr(session_obj, waitlist_attr).add(account)
# session_obj.save()
# messages.success(request, "Added to waitlist successfully.")
# return redirect(session_obj.get_absolute_url())


class SessionSignUpView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
template_name = "session_sign_up.html"
Expand All@@ -254,6 +151,8 @@ def dispatch(self, request, *args, **kwargs):
kwargs["mentor"] = get_object_or_404(Mentor, user=request.user)
kwargs["user_signed_up"] = session_orders.filter(mentor=kwargs["mentor"]).exists()

kwargs["spots_remaining"] = session_obj.mentor_capacity - session_orders.count()

elif request.user.role == "guardian":
kwargs["guardian"] = get_object_or_404(Guardian, user=request.user)
kwargs["student"] = get_object_or_404(Student, id=kwargs["student_id"])
Expand DownExpand Up@@ -286,6 +185,15 @@ def check_access(self, request, *args, **kwargs):
),
"redirect": request.META.get("HTTP_REFERER", "/dojo"),
}

# Check to make sure there is a spot open to sign up
if kwargs["spots_remaining"] <= 0:
access_dict = {
"message": (
"There are no slots open to mentor. Please check another class."
),
"redirect": request.META.get("HTTP_REFERER", kwargs["session_obj"].get_absolute_url()),
}

if kwargs.get("student"):
limits = self.student_limitations(kwargs["student"], kwargs["session_obj"], kwargs["user_signed_up"])
Expand DownExpand Up@@ -365,6 +273,25 @@ def post(self, request, *args, **kwargs):

return redirect(session_obj.get_absolute_url())

class SessionCancelView(View):
def get(self, request, *args, **kwargs):
pk = kwargs["pk"]
session = get_object_or_404(Session, id=pk)

# TODO: Do we need to check for this?
# if session.password and not self.validate_partner_session_access(request, pk):
# return redirect(reverse("session-password", kwargs=kwargs))

if request.user.is_authenticated:
if request.user.role == "mentor":
return mentor.SessionCancelView.as_view()(request, *args, **kwargs)
else:
return guardian.SessionCancelView.as_view()(request, *args, **kwargs)

return redirect(session.get_absolute_url())




class PasswordSessionView(TemplateView):
template_name = "session_partner_password.html"
Expand Down
12 changes: 6 additions & 6 deletions fixtures/12-coderdojochi.mentor.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,16 +29,16 @@
"user": 3,
"bio": "",
"is_active": true,
"background_check": false,
"is_public": false,
"background_check": true,
"is_public": true,
"avatar": "",
"avatar_approved": false,
"birthday": null,
"gender": null,
"avatar_approved": true,
"birthday": "1988-01-01",
"gender": "male",
"work_place": null,
"phone": null,
"home_address": null,
"race_ethnicity": []
"race_ethnicity": [2]
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion fixtures/14-coderdojochi.session.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
"start_date": "2022-01-01T16:00:00Z",
"location": 3,
"capacity": 20,
"mentor_capacity": 10,
"mentor_capacity": 1,
"instructor": 1,
"cost": "0.00",
"minimum_cost": null,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coderdojochi/models/session.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,6 +277,9 @@ def get_absolute_url(self) -> str:
def get_sign_up_url(self):
return reverse("session-sign-up", args=[str(self.id)])

def get_cancel_url(self):
return reverse("session-cancel", args=[str(self.id)])

def get_calendar_url(self):
return reverse("session-calendar", args=[str(self.id)])

Expand Down
33 changes: 33 additions & 0 deletions coderdojochi/templates/guardian/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Sign Up | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light"><strong>{{ student.full_name }}</strong> can no longer make it to the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Enroll <strong>{{ student.full_name }}</strong> for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.start_date|date }}</strong> from <strong>{{ session.start_date|time }}</strong> to <strong>{{ session.end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
21 changes: 21 additions & 0 deletions coderdojochi/templates/mentor/session_cancel.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
{% extends "coderdojochi/_base.html" %}

{% load i18n %}

{% block title %}{{ session.course.title }} Cancel | {{ block.super }}{% endblock %}

{% block body_class %}page-class-sign-up{% endblock %}

{% block contained_content %}
<div class="container registration min-height">

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion coderdojochi/templates/mentor/session_detail.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ <h3 class="title text-primary">Class Details & Enrollment</h3>
{% else %}
{% if mentor_signed_up %}
<p>You are signed up to mentor this class.</p>
<p><a href="{{ session.get_sign_up_url }}" class="button large tertiary">I can't make it...</a></p>
<p><a href="{{ session.get_cancel_url }}" class="button large tertiary">I can't make it...</a></p>
{% else %}
{% if spots_remaining %}
<p><a href="{{ session.get_sign_up_url }}" class="button large secondary">Sign up now!</a></p>
Expand Down
24 changes: 6 additions & 18 deletions coderdojochi/templates/mentor/session_sign_up.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,26 +8,14 @@

{% block contained_content %}
<div class="container registration min-height">
{% if user_signed_up %}

<h1 class="title light">I can no longer volunteer for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>
<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button tertiary large">Yes, cancel</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>
<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% else %}

<h1 class="title light">Sign up to mentor for the <strong>"{{ session.course.title }}"</strong> class on <strong>{{ session.mentor_start_date|date }}</strong> from <strong>{{ session.mentor_start_date|time }}</strong> to <strong>{{ session.mentor_end_date|time }}</strong>.</h1>

<form class="form" method="POST" action="">
{% csrf_token %}
<button class="button large">Yes, I'm excited!</button>
<a href="{{ session.get_absolute_url }}" class="button large secondary">Nevermind</a>
</form>

{% endif %}
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions coderdojochi/urls.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@
SessionCalendarView,
SessionDetailView,
SessionSignUpView,
SessionCancelView,
WelcomeView,
meeting_announce,
meeting_sign_up,
Expand DownExpand Up@@ -156,6 +157,12 @@
path("<int:pk>/sign-up/", SessionSignUpView.as_view(), name="session-sign-up"),
# /classes/ID/sign-up/STUDENT-ID/
path("<int:pk>/sign-up/<int:student_id>/", SessionSignUpView.as_view(), name="session-sign-up"),

# Cancel session
# /classes/ID/cancel/
path("<int:pk>/cancel/", SessionCancelView.as_view(), name="session-cancel"),
# /classes/ID/cancel/STUDENT-ID/
path("<int:pk>/cancel/<int:student_id>/", SessionCancelView.as_view(), name="session-cancel"),
]
),
),
Expand Down
3 changes: 3 additions & 0 deletions coderdojochi/views/guardian/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,3 +19,6 @@ def get_context_data(self, **kwargs):
)

return context

class SessionCancelView(DetailView):
pass
52 changes: 49 additions & 3 deletions coderdojochi/views/mentor/sessions.py
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
from django.shortcuts import get_object_or_404
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404, redirect
from django.views.generic import DetailView

from ...models import Mentor, MentorOrder, Session
Expand All@@ -14,12 +15,11 @@ def get_context_data(self, **kwargs):

session_orders = MentorOrder.objects.filter(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
context["mentor_signed_up"] = session_orders.exists()
context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
context["spots_remaining"] = session.mentor_capacity - session_orders.count()
context["account"] = mentor

Expand All@@ -31,3 +31,49 @@ def get_context_data(self, **kwargs):
)

return context


class SessionCancelView(DetailView):
model = Session
template_name = "mentor/session_cancel.html"

# redirect if order not found
def get(self, request, *args, **kwargs):
try:
self.object = self.get_object()
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)
mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
except ObjectDoesNotExist:
return redirect(session.get_absolute_url())


def get_context_data(self, **kwargs):
session = self.object
mentor = get_object_or_404(Mentor, user=self.request.user)

mentor_order = MentorOrder.objects.get(
session=session,
mentor=mentor,
is_active=True,
)

context = super().get_context_data(**kwargs)
# context["mentor_signed_up"] = session_orders.filter(mentor=mentor).exists()
# context["spots_remaining"] = session.mentor_capacity - session_orders.count()
# context["account"] = mentor

# context["active_mentors"] = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(
# session=self.object,
# is_active=True,
# ).values("mentor__id")
# )

return context
133 changes: 30 additions & 103 deletions coderdojochi/views/sessions.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,109 +136,6 @@ def validate_partner_session_access(self, request, pk):
return False


# class SessionDetailView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
# template_name = "session_detail.html"

# def dispatch(self, request, *args, **kwargs):
# session_obj = get_object_or_404(Session, id=kwargs["pk"])

# if request.method == "GET":
# if session_obj.password and not self.validate_partner_session_access(self.request, kwargs["pk"]):
# return redirect(reverse("session-password", kwargs=kwargs))

# if request.user.is_authenticated and request.user.role:
# if "enroll" in request.GET or "enroll" in kwargs:
# return self.enroll_redirect(request, session_obj)

# # kwargs["session_obj"] = session_obj
# return super(SessionDetailView, self).dispatch(request, *args, **kwargs)

# def enroll_redirect(self, request, session_obj):
# if request.user.role == "mentor":
# return redirect("session-sign-up", pk=session_obj.id)

# guardian = get_object_or_404(Guardian, user=request.user)
# student = get_object_or_404(Student, guardian=guardian, id=(int(request.GET["student"])))

# if student:
# return redirect("session-sign-up", pk=session_obj.id, student_id=student.id)

# return redirect(f"{reverse('welcome')}?next={session_obj.get_absolute_url()}&enroll=True")

# def validate_partner_session_access(self, request, pk):
# authed_sessions = request.session.get("authed_partner_sessions")

# if authed_sessions and pk in authed_sessions:
# if request.user.is_authenticated:
# PartnerPasswordAccess.objects.get_or_create(session_id=pk, user=request.user)
# return True

# if request.user.is_authenticated:
# try:
# PartnerPasswordAccess.objects.get(session_id=pk, user_id=request.user.id)
# except PartnerPasswordAccess.DoesNotExist:
# return False
# else:
# return True

# else:
# return False

# def get_context_data(self, **kwargs):
# print(kwargs["session_obj"].__dict__)
# context = super(SessionDetailView, self).get_context_data(**kwargs)
# session_obj = kwargs["session_obj"]
# context["session"] = session_obj

# upcoming_classes = Session.objects.filter(is_active=True, start_date__gte=timezone.now()).order_by("start_date")
# context["upcoming_classes"] = upcoming_classes

# active_mentors = Mentor.objects.filter(
# id__in=MentorOrder.objects.filter(session=session_obj, is_active=True).values("mentor__id")
# )
# context["active_mentors"] = active_mentors

# if self.request.user.is_authenticated:
# if self.request.user.role == "mentor":
# account = get_object_or_404(Mentor, user=self.request.user)
# session_orders = MentorOrder.objects.filter(session=session_obj, is_active=True,)
# context["mentor_signed_up"] = session_orders.filter(mentor=account).exists()

# context["spots_remaining"] = session_obj.get_mentor_capacity() - session_orders.count()
# else:
# account = get_object_or_404(Guardian, user=self.request.user)
# context["students"] = account.get_students()
# context["spots_remaining"] = session_obj.capacity - session_obj.get_active_student_count()
# context["account"] = account
# else:
# context["upcoming_classes"] = upcoming_classes.filter(is_public=True)
# context["spots_remaining"] = session_obj.capacity - session_obj.objects.get_active_student_count()

# return context

# def post(self, request, *args, **kwargs):
# session_obj = kwargs["session_obj"]
# if "waitlist" not in request.POST:
# messages.error(request, "Invalid request, please try again.")
# return redirect(session_obj.get_absolute_url())

# if request.POST["waitlist"] == "student":
# account = Student.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_students"
# else:
# account = Guardian.objects.get(id=request.POST["account_id"])
# waitlist_attr = "waitlist_guardians"

# if request.POST["remove"] == "true":
# getattr(session_obj, waitlist_attr).remove(account)
# session_obj.save()
# messages.success(request, "You have been removed from the waitlist. Thanks for letting us know.")
# else:
# getattr(session_obj, waitlist_attr).add(account)
# session_obj.save()
# messages.success(request, "Added to waitlist successfully.")
# return redirect(session_obj.get_absolute_url())


class SessionSignUpView(RoleRedirectMixin, RoleTemplateMixin, TemplateView):
template_name = "session_sign_up.html"
Expand All@@ -254,6 +151,8 @@ def dispatch(self, request, *args, **kwargs):
kwargs["mentor"] = get_object_or_404(Mentor, user=request.user)
kwargs["user_signed_up"] = session_orders.filter(mentor=kwargs["mentor"]).exists()

kwargs["spots_remaining"] = session_obj.mentor_capacity - session_orders.count()

elif request.user.role == "guardian":
kwargs["guardian"] = get_object_or_404(Guardian, user=request.user)
kwargs["student"] = get_object_or_404(Student, id=kwargs["student_id"])
Expand DownExpand Up@@ -286,6 +185,15 @@ def check_access(self, request, *args, **kwargs):
),
"redirect": request.META.get("HTTP_REFERER", "/dojo"),
}

# Check to make sure there is a spot open to sign up
if kwargs["spots_remaining"] <= 0:
access_dict = {
"message": (
"There are no slots open to mentor. Please check another class."
),
"redirect": request.META.get("HTTP_REFERER", kwargs["session_obj"].get_absolute_url()),
}

if kwargs.get("student"):
limits = self.student_limitations(kwargs["student"], kwargs["session_obj"], kwargs["user_signed_up"])
Expand DownExpand Up@@ -365,6 +273,25 @@ def post(self, request, *args, **kwargs):

return redirect(session_obj.get_absolute_url())

class SessionCancelView(View):
def get(self, request, *args, **kwargs):
pk = kwargs["pk"]
session = get_object_or_404(Session, id=pk)

# TODO: Do we need to check for this?
# if session.password and not self.validate_partner_session_access(request, pk):
# return redirect(reverse("session-password", kwargs=kwargs))

if request.user.is_authenticated:
if request.user.role == "mentor":
return mentor.SessionCancelView.as_view()(request, *args, **kwargs)
else:
return guardian.SessionCancelView.as_view()(request, *args, **kwargs)

return redirect(session.get_absolute_url())




class PasswordSessionView(TemplateView):
template_name = "session_partner_password.html"
Expand Down
12 changes: 6 additions & 6 deletions fixtures/12-coderdojochi.mentor.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,16 +29,16 @@
"user": 3,
"bio": "",
"is_active": true,
"background_check": false,
"is_public": false,
"background_check": true,
"is_public": true,
"avatar": "",
"avatar_approved": false,
"birthday": null,
"gender": null,
"avatar_approved": true,
"birthday": "1988-01-01",
"gender": "male",
"work_place": null,
"phone": null,
"home_address": null,
"race_ethnicity": []
"race_ethnicity": [2]
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion fixtures/14-coderdojochi.session.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
"start_date": "2022-01-01T16:00:00Z",
"location": 3,
"capacity": 20,
"mentor_capacity": 10,
"mentor_capacity": 1,
"instructor": 1,
"cost": "0.00",
"minimum_cost": null,
Expand Down
Loading