Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit 6781b7f

Browse files
Merge pull request #513 from diwash007/revamp
Revamp to support extended timelines
2 parents 586c18a + 48b359c commit 6781b7f

16 files changed

+821
-44
lines changed

Diff for: gsoc/admin.py

+48-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from .models import *
22
from .forms import (
3+
GeneratorForm,
4+
GsocEndDateStandardForm,
5+
GsocStartDateForm,
36
ArticleReviewForm,
47
UserProfileForm,
58
UserDetailsForm,
69
RegLinkForm,
7-
BlogPostDueDateForm,
810
EventForm,
911
GsocEndDateForm,
1012
)
@@ -351,8 +353,15 @@ class HiddenUserProfileAdmin(admin.ModelAdmin):
351353
"gsoc_year",
352354
"role",
353355
"github_handle",
356+
"gsoc_end"
357+
)
358+
list_filter = (
359+
"role",
360+
"gsoc_invited",
361+
"suborg_full_name",
362+
"gsoc_end",
363+
"gsoc_year"
354364
)
355-
list_filter = ("role", "gsoc_invited", "suborg_full_name", "gsoc_year")
356365
readonly_fields = (
357366
"user",
358367
"role",
@@ -371,6 +380,7 @@ class HiddenUserProfileAdmin(admin.ModelAdmin):
371380
"user",
372381
"role",
373382
"gsoc_year",
383+
"gsoc_end",
374384
"accepted_proposal_pdf",
375385
"proposal_confirmed",
376386
"blog_link",
@@ -567,23 +577,57 @@ def short_data(self, obj):
567577

568578
class BlogPostDueDateInline(admin.TabularInline):
569579
model = BlogPostDueDate
570-
form = BlogPostDueDateForm
580+
fields = ("title", "category", "date")
581+
readonly_fields = ("title", "category", "date")
582+
583+
def has_add_permission(self, request, obj=None):
584+
return False
585+
586+
def has_change_permission(self, request, obj=None):
587+
return False
588+
589+
def has_delete_permission(self, request, obj=None):
590+
return False
571591

572592

573593
class EventInline(admin.TabularInline):
574594
model = Event
575595
form = EventForm
596+
extra = 1
576597

577598

578599
class GsocEndDateInline(admin.TabularInline):
579600
model = GsocEndDate
580601
form = GsocEndDateForm
581602

582603

604+
class GsocStartDateInline(admin.TabularInline):
605+
model = GsocStartDate
606+
form = GsocStartDateForm
607+
608+
609+
class GsocEndDateStandardInline(admin.TabularInline):
610+
model = GsocEndDateDefault
611+
form = GsocEndDateStandardForm
612+
613+
614+
class GeneratorInline(admin.TabularInline):
615+
model = Generator
616+
form = GeneratorForm
617+
max_num = 2
618+
619+
583620
class TimelineAdmin(admin.ModelAdmin):
584621
list_display = ("gsoc_year",)
585622
exclude = ("calendar_id",)
586-
inlines = (BlogPostDueDateInline, EventInline, GsocEndDateInline)
623+
inlines = (
624+
EventInline,
625+
GsocStartDateInline,
626+
GsocEndDateStandardInline,
627+
GsocEndDateInline,
628+
GeneratorInline,
629+
BlogPostDueDateInline
630+
)
587631

588632

589633
admin.site.register(Timeline, TimelineAdmin)

Diff for: gsoc/common/utils/build_tasks.py

+218-36
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
from datetime import datetime, timedelta
12
import json
23
import uuid
3-
4-
from django.utils import timezone
54
from django.conf import settings
65

7-
from gsoc.models import (Event, GsocEndDate, Timeline, UserProfile, GsocYear,
8-
BlogPostDueDate, Scheduler, ReaddUser)
6+
from django.utils import timezone
7+
from gsoc.settings import ADMINS
8+
9+
from gsoc.models import (
10+
DaysConf,
11+
Event,
12+
GsocEndDate,
13+
GsocEndDateDefault,
14+
GsocStartDate, Timeline,
15+
UserProfile,
16+
GsocYear,
17+
BlogPostDueDate,
18+
Scheduler,
19+
ReaddUser
20+
)
921
from gsoc.common.utils.tools import build_send_mail_json
1022

1123
from googleapiclient.discovery import build
@@ -17,7 +29,11 @@ def build_pre_blog_reminders(builder):
1729
data = json.loads(builder.data)
1830
due_date = BlogPostDueDate.objects.get(pk=data["due_date_pk"])
1931
gsoc_year = GsocYear.objects.first()
20-
profiles = UserProfile.objects.filter(gsoc_year=gsoc_year, role=3).all()
32+
profiles = UserProfile.objects.filter(
33+
gsoc_year=gsoc_year,
34+
role=3,
35+
gsoc_end__gte=due_date.date
36+
).all()
2137
categories = ((0, "Weekly Check-In"), (1, "Blog Post"))
2238
category = categories[due_date.category][1]
2339
for profile in profiles:
@@ -57,7 +73,11 @@ def build_post_blog_reminders(builder):
5773
category = categories[due_date.category][1]
5874

5975
gsoc_year = GsocYear.objects.first()
60-
profiles = UserProfile.objects.filter(gsoc_year=gsoc_year, role=3).all()
76+
profiles = UserProfile.objects.filter(
77+
gsoc_year=gsoc_year,
78+
role=3,
79+
gsoc_end__gte=due_date.date
80+
).all()
6181
for profile in profiles:
6282
if profile.current_blog_count > blogs_count and not (
6383
profile.hidden or profile.reminder_disabled
@@ -67,13 +87,19 @@ def build_post_blog_reminders(builder):
6787
suborg_admins = UserProfile.objects.filter(
6888
suborg_full_name=suborg, role=1
6989
)
90+
POST_BLOG_REMINDER_FIRST = DaysConf.objects.get(title="POST_BLOG_REMINDER_FIRST")
91+
POST_BLOG_REMINDER_SECOND = DaysConf.objects.get(title="POST_BLOG_REMINDER_SECOND")
7092

7193
activation_date = builder.activation_date.date()
7294

73-
if activation_date - due_date.date == timezone.timedelta(days=1):
95+
if activation_date - due_date.date == timezone.timedelta(
96+
days=POST_BLOG_REMINDER_FIRST.days
97+
):
7498
student_template = "first_post_blog_reminder_student.html"
7599

76-
elif activation_date - due_date.date == timezone.timedelta(days=3):
100+
elif activation_date - due_date.date == timezone.timedelta(
101+
days=POST_BLOG_REMINDER_SECOND.days
102+
):
77103
student_template = "second_post_blog_reminder_student.html"
78104

79105
mentors_emails = ["[email protected]"]
@@ -250,33 +276,189 @@ def build_add_event_to_calendar(builder):
250276

251277
def build_add_end_to_calendar(builder):
252278
data = json.loads(builder.data)
253-
try:
254-
creds = getCreds()
255-
if creds:
256-
service = build("calendar", "v3", credentials=creds, cache_discovery=False)
257-
event = {
258-
"summary": data["title"],
259-
"start": {"date": data["date"]},
260-
"end": {"date": data["date"]},
261-
}
262-
cal_id = builder.timeline.calendar_id if builder.timeline else "primary"
263-
if not data["event_id"]:
264-
event = (
265-
service.events()
266-
.insert(calendarId=cal_id, body=event)
267-
.execute()
268-
)
269-
item = GsocEndDate.objects.get(id=data["id"])
270-
item.event_id = event.get("id")
271-
item.save()
272-
else:
273-
service.events().update(
274-
calendarId=cal_id, eventId=data["event_id"], body=event
275-
).execute()
279+
creds = getCreds()
280+
if creds:
281+
service = build("calendar", "v3", credentials=creds, cache_discovery=False)
282+
event = {
283+
"summary": data["title"],
284+
"start": {"date": data["date"]},
285+
"end": {"date": data["date"]},
286+
}
287+
cal_id = builder.timeline.calendar_id if builder.timeline else "primary"
288+
if not data["event_id"]:
289+
event = (
290+
service.events()
291+
.insert(calendarId=cal_id, body=event)
292+
.execute()
293+
)
294+
item = GsocEndDate.objects.get(id=data["id"])
295+
item.event_id = event.get("id")
296+
item.save()
276297
else:
277-
raise Exception(
278-
f"Please get the Access Token: " +
279-
f"{settings.OAUTH_REDIRECT_URI + 'authorize'}"
298+
service.events().update(
299+
calendarId=cal_id, eventId=data["event_id"], body=event
300+
).execute()
301+
else:
302+
raise Exception(
303+
f"Please get the Access Token: " +
304+
f"{settings.OAUTH_REDIRECT_URI + 'authorize'}"
305+
)
306+
307+
308+
def build_add_start_to_calendar(builder):
309+
data = json.loads(builder.data)
310+
creds = getCreds()
311+
if creds:
312+
service = build("calendar", "v3", credentials=creds, cache_discovery=False)
313+
event = {
314+
"summary": data["title"],
315+
"start": {"date": data["date"]},
316+
"end": {"date": data["date"]},
317+
}
318+
cal_id = builder.timeline.calendar_id if builder.timeline else "primary"
319+
if not data["event_id"]:
320+
event = (
321+
service.events()
322+
.insert(calendarId=cal_id, body=event)
323+
.execute()
280324
)
281-
except Exception as e:
282-
return str(e)
325+
item = GsocStartDate.objects.get(id=data["id"])
326+
item.event_id = event.get("id")
327+
item.save()
328+
else:
329+
service.events().update(
330+
calendarId=cal_id, eventId=data["event_id"], body=event
331+
).execute()
332+
else:
333+
raise Exception(
334+
f"Please get the Access Token: " +
335+
f"{settings.OAUTH_REDIRECT_URI + 'authorize'}"
336+
)
337+
338+
339+
def build_add_end_standard_to_calendar(builder):
340+
data = json.loads(builder.data)
341+
creds = getCreds()
342+
if creds:
343+
service = build("calendar", "v3", credentials=creds, cache_discovery=False)
344+
event = {
345+
"summary": data["title"],
346+
"start": {"date": data["date"]},
347+
"end": {"date": data["date"]},
348+
}
349+
cal_id = builder.timeline.calendar_id if builder.timeline else "primary"
350+
if not data["event_id"]:
351+
event = (
352+
service.events()
353+
.insert(calendarId=cal_id, body=event)
354+
.execute()
355+
)
356+
item = GsocEndDateDefault.objects.get(id=data["id"])
357+
item.event_id = event.get("id")
358+
item.save()
359+
else:
360+
service.events().update(
361+
calendarId=cal_id, eventId=data["event_id"], body=event
362+
).execute()
363+
else:
364+
raise Exception(
365+
f"Please get the Access Token: " +
366+
f"{settings.OAUTH_REDIRECT_URI + 'authorize'}"
367+
)
368+
369+
370+
def build_evaluation_reminder(builder):
371+
data = json.loads(builder.data)
372+
gsoc_year = GsocYear.objects.latest('gsoc_year')
373+
start_date = GsocStartDate.objects.latest('date')
374+
start_date = start_date.date
375+
exam_date = datetime.strptime(data["exam_date"], "%Y-%m-%d").date()
376+
is_midterm = data["Midterm"]
377+
378+
gsoc_end = exam_date
379+
if is_midterm:
380+
gsoc_end = start_date + 2 * (exam_date - start_date) + timedelta(days=7-1)
381+
382+
# 4 days before
383+
notify_date = exam_date - timedelta(days=4)
384+
385+
tl_users = UserProfile.objects.filter(
386+
gsoc_year=gsoc_year,
387+
role=3,
388+
gsoc_end=gsoc_end
389+
).all()
390+
391+
tl_suborg = [user.suborg_full_name for user in tl_users]
392+
393+
profiles = UserProfile.objects.filter(
394+
suborg_full_name__in=tl_suborg,
395+
role__in=[1, 2]
396+
)
397+
398+
for profile in profiles:
399+
template_data = {
400+
"date": str(exam_date),
401+
}
402+
403+
scheduler_data = build_send_mail_json(
404+
profile.user.email,
405+
template="exam_reminder.html",
406+
subject=f"Evaluation Due Reminder",
407+
template_data=template_data,
408+
)
409+
410+
Scheduler.objects.create(
411+
command="send_email",
412+
data=scheduler_data,
413+
activation_date=notify_date
414+
)
415+
416+
# 2 days before
417+
notify_date = exam_date - timedelta(days=2)
418+
419+
tl_users = UserProfile.objects.filter(
420+
gsoc_year=gsoc_year,
421+
role=3,
422+
gsoc_end=gsoc_end
423+
).all()
424+
425+
tl_suborg = [user.suborg_full_name for user in tl_users]
426+
427+
profiles = UserProfile.objects.filter(
428+
suborg_full_name__in=tl_suborg,
429+
role__in=[1, 2]
430+
)
431+
432+
for profile in profiles:
433+
template_data = {
434+
"date": str(exam_date),
435+
}
436+
437+
scheduler_data = build_send_mail_json(
438+
profile.user.email,
439+
template="exam_reminder.html",
440+
subject=f"Evaluation Due Reminder",
441+
template_data=template_data,
442+
)
443+
444+
Scheduler.objects.create(
445+
command="send_email",
446+
data=scheduler_data,
447+
activation_date=notify_date
448+
)
449+
450+
template_data = {
451+
"date": str(exam_date),
452+
}
453+
454+
scheduler_data = build_send_mail_json(
455+
ADMINS,
456+
template="exam_reminder.html",
457+
subject="Evaluation Due Reminder",
458+
template_data=template_data,
459+
)
460+
Scheduler.objects.create(
461+
command="send_email",
462+
data=scheduler_data,
463+
activation_date=notify_date
464+
)

0 commit comments

Comments
 (0)