From e822faf8eb27cc2d4c023a09c588ba365dffc569 Mon Sep 17 00:00:00 2001 From: Keshav Garg Date: Fri, 2 Aug 2019 21:43:28 +0530 Subject: [PATCH] community/: Add web-page displaying mentors The web-page displays all the mentors of the upcoming summer/winter program or of previous year, if no mentors are being found for upcoming program Closes https://github.com/coala/community/issues/271 --- community/urls.py | 8 ++- community/views.py | 48 ++++++++++++++++- data/migrations/0011_mentor.py | 23 ++++++++ data/models.py | 7 +++ static/css/mentors.css | 13 +++++ static/js/mentors.js | 15 ++++++ templates/base.html | 2 +- templates/mentors.html | 98 ++++++++++++++++++++++++++++++++++ 8 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 data/migrations/0011_mentor.py create mode 100644 static/css/mentors.css create mode 100644 static/js/mentors.js create mode 100644 templates/mentors.html diff --git a/community/urls.py b/community/urls.py index f6a4b025..4319d01f 100644 --- a/community/urls.py +++ b/community/urls.py @@ -10,7 +10,7 @@ from community.views import ( HomePageView, JoinCommunityView, OrganizationTeams, InactiveIssuesList, - UnassignedIssuesActivityList + UnassignedIssuesActivityList, OrganizationMentors ) from gci.views import GCIStudentsList from gci.feeds import LatestTasksFeed as gci_tasks_rss @@ -46,6 +46,12 @@ def get_index(): distill_func=get_index, distill_file='teams/index.html', ), + distill_url( + r'mentors/', OrganizationMentors.as_view(), + name='org-mentors', + distill_func=get_index, + distill_file='mentors/index.html', + ), distill_url( r'gci/tasks/rss.xml', gci_tasks_rss(), name='gci-tasks-rss', diff --git a/community/views.py b/community/views.py index c2cc1930..4989acb8 100644 --- a/community/views.py +++ b/community/views.py @@ -1,4 +1,5 @@ import os +from datetime import datetime import logging @@ -23,7 +24,7 @@ NewcomerPromotion, Feedback ) -from data.models import Team, InactiveIssue, UnassignedIssuesActivity +from data.models import Team, InactiveIssue, UnassignedIssuesActivity, Mentor from gamification.models import Participant as GamificationParticipant from meta_review.models import Participant as MetaReviewer @@ -244,3 +245,48 @@ def get_context_data(self, **kwargs): context = get_header_and_footer(context) context['page_name'] = 'Unassigned Issues Activity List' return context + + +class OrganizationMentors(ListView): + + template_name = 'mentors.html' + model = Mentor + today = datetime.today() + context = None + + def get_gsoc_students_details(self): + gsoc_previous_year_mentors = False + if self.today.month > 10: # GSoC ends in September + year = self.today.year + 1 + mentors = Mentor.objects.filter(year=year, program='GSoC') + if not mentors.exists(): + year = self.today.year + gsoc_previous_year_mentors = True + + else: + year = self.today.year + section_name = f"Google Summer of Code'{year} Mentors" + mentors = Mentor.objects.filter(year=year, program='GSoC') + self.context['gsoc_previous_mentors'] = gsoc_previous_year_mentors + self.context['gsoc_section_name'] = section_name + self.context['gsoc_mentors'] = mentors + + def get_gci_students_details(self): + gci_previous_year_mentors = False + year = self.today.year + mentors = Mentor.objects.filter(year=year, program='GCI') + if not mentors.exists(): + year = self.today.year-1 + mentors = Mentor.objects.filter(year=year, program='GCI') + gci_previous_year_mentors = True + section_name = f"Google Code-In'{year} Mentors" + self.context['gci_previous_mentors'] = gci_previous_year_mentors + self.context['gci_section_name'] = section_name + self.context['gci_mentors'] = mentors + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + self.context = get_header_and_footer(context) + self.get_gsoc_students_details() + self.get_gci_students_details() + return self.context diff --git a/data/migrations/0011_mentor.py b/data/migrations/0011_mentor.py new file mode 100644 index 00000000..87a6eb4c --- /dev/null +++ b/data/migrations/0011_mentor.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.7 on 2019-08-02 14:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('data', '0010_unassignedissuesactivity'), + ] + + operations = [ + migrations.CreateModel( + name='Mentor', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('username', models.CharField(max_length=100)), + ('name', models.CharField(max_length=100)), + ('year', models.SmallIntegerField(verbose_name='Mentoring year')), + ('program', models.CharField(max_length=20, verbose_name='Mentoring program')), + ], + ), + ] diff --git a/data/models.py b/data/models.py index 71db35c8..cada89aa 100644 --- a/data/models.py +++ b/data/models.py @@ -132,3 +132,10 @@ class UnassignedIssuesActivity(models.Model): repository = models.CharField(max_length=100) number = models.SmallIntegerField() url = models.URLField() + + +class Mentor(models.Model): + username = models.CharField(max_length=100) + name = models.CharField(max_length=100) + year = models.SmallIntegerField(verbose_name='Mentoring year') + program = models.CharField(max_length=20, verbose_name='Mentoring program') diff --git a/static/css/mentors.css b/static/css/mentors.css new file mode 100644 index 00000000..c227a93a --- /dev/null +++ b/static/css/mentors.css @@ -0,0 +1,13 @@ +.mentors-list { + width: 100%; +} + +.program-input-field { + width: 200px; + float: right; + margin-right: 20px; +} + +.program-input-field label { + font-size: 1.3em; +} \ No newline at end of file diff --git a/static/js/mentors.js b/static/js/mentors.js new file mode 100644 index 00000000..78e41056 --- /dev/null +++ b/static/js/mentors.js @@ -0,0 +1,15 @@ +$(document).ready(function () { + var program_selector = $('select#program'); + program_selector.on('change', function () { + var page_name = program_selector.val(); + $('.page-name').text(page_name); + if(page_name.search('Summer') > 0){ + $('.gsoc-mentors').css('display', 'flex'); + $('.gci-mentors').css('display', 'none'); + } + else if(page_name.search('Code-In') > 0){ + $('.gsoc-mentors').css('display', 'none'); + $('.gci-mentors').css('display', 'flex'); + } + }); +}); \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index ec77054b..455b6109 100644 --- a/templates/base.html +++ b/templates/base.html @@ -76,7 +76,7 @@