From b6d579a55ea953804ca408a7739f765807570449 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 | 97 ++++++++++++++++++++++++++++++++++ 8 files changed, 210 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 2d4e06f2..12a2bb3b 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 @@ -45,6 +45,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 2739b292..ade02639 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 @@ -247,3 +248,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..8ec03854 --- /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; +} diff --git a/static/js/mentors.js b/static/js/mentors.js new file mode 100644 index 00000000..ee7274be --- /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'); + } + }); +}); diff --git a/templates/base.html b/templates/base.html index ad98415c..b32cb564 100644 --- a/templates/base.html +++ b/templates/base.html @@ -69,7 +69,7 @@