diff --git a/config.py b/config.py index c4a3ac1..d0e7d14 100644 --- a/config.py +++ b/config.py @@ -1,7 +1,6 @@ api_endpoint = { 'contrihub_api_1': 'https://api.github.com/repos/ContriHUB/', 'contrihub_api_2': 'https://api.github.com/repos/contrihub/', - 'contrihub_org_repos': 'https://api.github.com/orgs/ContriHUB/repos', } html_endpoint = { diff --git a/contrihub/settings.py b/contrihub/settings.py index 51f6d40..840fcd9 100644 --- a/contrihub/settings.py +++ b/contrihub/settings.py @@ -2,7 +2,6 @@ import dj_database_url from pathlib import Path import os -from config import api_endpoint # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -185,14 +184,8 @@ EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=True, cast=bool) EMAIL_USE_SSL = config('EMAIL_USE_SSL', default=False, cast=bool) -AVAILABLE_PROJECTS = config( - 'AVAILABLE_PROJECTS', - default='ContriHUB-24', - cast=lambda v: [s.strip() for s in v.split(',')], -) - -CONTRIHUB_ORG_REPOS_ENDPOINT = config('CONTRIHUB_ORG_REPOS_ENDPOINT', default=api_endpoint['contrihub_org_repos']) - +AVAILABLE_PROJECTS = config('AVAILABLE_PROJECTS', default="ContriHUB-24", + cast=lambda v: [s.strip() for s in v.split(',')]) LABEL_MENTOR = config('LABEL_MENTOR', default="mentor") LABEL_LEVEL = config('LABEL_LEVEL', default="level") LABEL_POINTS = config('LABEL_POINTS', default="points") diff --git a/home/views.py b/home/views.py index 33f0326..f7a0047 100644 --- a/home/views.py +++ b/home/views.py @@ -20,11 +20,6 @@ from user_profile.models import UserProfile from .forms import ContactForm -# Legacy dashboard filters: initialise globals before any view runs -issues_qs = Issue.objects.none() -domain = 'All' -subdomain = 'All' - def home(request): return render(request, 'home/index.html') @@ -72,7 +67,7 @@ def filter_by_domain(request, domain_pk): @complete_profile_required def filter_by_subdomain(request, subdomain_pk): - global issues_qs, subdomain + global issues_qs, domain, subdomain subdomain = SubDomain.objects.get(pk=subdomain_pk) project_qs = Project.objects.all() if domain != 'All': diff --git a/project/migrations/0043_project_archived_project_description_and_more.py b/project/migrations/0043_project_archived_project_description_and_more.py deleted file mode 100644 index c4e79dc..0000000 --- a/project/migrations/0043_project_archived_project_description_and_more.py +++ /dev/null @@ -1,43 +0,0 @@ -# Generated by Django 4.1 on 2025-10-02 03:14 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('project', '0042_alter_issue_levelcolor'), - ] - - operations = [ - migrations.AddField( - model_name='project', - name='archived', - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name='project', - name='description', - field=models.URLField(blank=True, verbose_name='Description'), - ), - migrations.AddField( - model_name='project', - name='homepage', - field=models.URLField(blank=True, verbose_name='Homepage'), - ), - migrations.AddField( - model_name='project', - name='is_current', - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name='project', - name='pushed_at', - field=models.DateTimeField(blank=True, null=True, verbose_name='Last Pushed At'), - ), - migrations.AddField( - model_name='project', - name='topics_raw', - field=models.TextField(blank=True, verbose_name='Topics'), - ), - ] diff --git a/project/models.py b/project/models.py index 056a98b..9c6a934 100644 --- a/project/models.py +++ b/project/models.py @@ -30,12 +30,6 @@ class Project(models.Model): api_url = models.URLField(verbose_name="API URL") html_url = models.URLField(verbose_name="HTML URL") - description = models.URLField(verbose_name="Description", blank=True) - homepage = models.URLField(verbose_name="Homepage", blank=True) - topics_raw = models.TextField(verbose_name="Topics", blank=True) - pushed_at = models.DateTimeField(verbose_name="Last Pushed At", null=True, blank=True) - archived = models.BooleanField(default=False) - is_current = models.BooleanField(default=False) domain = models.ForeignKey(Domain, on_delete=models.DO_NOTHING, null=True, default=None) subdomain = models.ForeignKey(SubDomain, on_delete=models.DO_NOTHING, blank=True, default=None, null=True) diff --git a/project/templates/index.html b/project/templates/index.html index 80c3941..45951da 100644 --- a/project/templates/index.html +++ b/project/templates/index.html @@ -142,41 +142,309 @@
-

Projects

+

Projects in 2024

- {% if projects %} - {% for project in projects %} -
-
-
-
- {{ project.name }} -
-

- {{ project.description|default:"No description provided." }} -

- {% if project.homepage %} - - {% endif %} - {% if project.topics_raw %} -
Topics: {{ project.topics_raw }}
- {% endif %} - {% if project.pushed_at %} -
Last updated: {{ project.pushed_at|date:"M d, Y" }}
- {% endif %} -
-
-
- {% endfor %} - {% else %} -
-

No projects available right now. Please check back soon.

-
- {% endif %} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -238,4 +506,4 @@
- + \ No newline at end of file diff --git a/project/views.py b/project/views.py index 12e40c8..4a993cb 100644 --- a/project/views.py +++ b/project/views.py @@ -1,9 +1,5 @@ -from datetime import datetime, timedelta - from django.shortcuts import HttpResponseRedirect, reverse, render -from contrihub.settings import CONTRIHUB_ORG_REPOS_ENDPOINT, AVAILABLE_PROJECTS, \ - LABEL_MENTOR, LABEL_LEVEL, \ - LABEL_POINTS, DEPENDABOT_LOGIN, \ +from contrihub.settings import AVAILABLE_PROJECTS, LABEL_MENTOR, LABEL_LEVEL, LABEL_POINTS, DEPENDABOT_LOGIN, \ LABEL_RESTRICTED, DEFAULT_FREE_POINTS, DEFAULT_VERY_EASY_POINTS, DEFAULT_EASY_POINTS, DEFAULT_MEDIUM_POINTS, \ DEFAULT_HARD_POINTS from django.contrib.auth.decorators import user_passes_test @@ -11,14 +7,12 @@ from .models import Project, Issue from helper import safe_hit_url, SUCCESS, complete_profile_required from config import api_endpoint, html_endpoint -from django.utils import timezone User = get_user_model() def home(request): - projects = Project.objects.filter(is_current=True).order_by('-pushed_at', 'name') - return render(request, 'index.html', {'projects': projects}) + return render(request, 'index.html') @user_passes_test(lambda u: u.userprofile.role == u.userprofile.ADMIN) @@ -30,78 +24,18 @@ def populate_projects(request): :param request: :return: """ - response = safe_hit_url(CONTRIHUB_ORG_REPOS_ENDPOINT) - if response['status'] != SUCCESS: - return HttpResponseRedirect(reverse('home')) - - repos = response['data'] - active_names = set() - now = timezone.now() - year_tokens = { - str(now.year), - str(now.year - 1), - str(now.year)[-2:], - str(now.year - 1)[-2:], - } - - has_current = False - - for repo in repos: - if repo.get('archived') or repo.get('fork'): - continue - - name = repo['name'] - pushed_at_raw = repo.get('pushed_at') - pushed_at = None - is_current = False - - if pushed_at_raw: - try: - pushed_at = datetime.fromisoformat(pushed_at_raw.replace('Z', '+00:00')) - except ValueError: - pushed_at = None - - if pushed_at and pushed_at >= now - timedelta(days=365): - is_current = True - - if not is_current and any(token in name for token in year_tokens): - is_current = True - - api_url = repo['url'] - html_url = repo['html_url'] - description = repo.get('description') or '' - homepage = repo.get('homepage') or '' - topics = repo.get('topics') or [] - - project, _ = Project.objects.update_or_create( - name=name, - defaults={ - 'api_url': api_url, - 'html_url': html_url, - 'description': description, - 'homepage': homepage, - 'topics_raw': ', '.join(topics), - 'pushed_at': pushed_at, - 'archived': repo.get('archived', False), - 'is_current': is_current, - }, - ) - active_names.add(project.name) - if is_current: - has_current = True - - # fallback to AVAILABLE_PROJECTS when GitHub returns nothing - if not active_names or not has_current: - api_uri = api_endpoint['contrihub_api_1'] - html_uri = html_endpoint['contrihub_html'] - for project_name in AVAILABLE_PROJECTS: - Project.objects.update_or_create( + api_uri = api_endpoint['contrihub_api_1'] + html_uri = html_endpoint['contrihub_html'] + # print(AVAILABLE_PROJECTS) + for project_name in AVAILABLE_PROJECTS: + project_qs = Project.objects.filter(name=project_name) + if not project_qs: + api_url = f"{api_uri}{project_name}" + html_url = f"{html_uri}{project_name}" + Project.objects.create( name=project_name, - defaults={ - 'api_url': f"{api_uri}{project_name}", - 'html_url': f"{html_uri}{project_name}", - 'is_current': True, - }, + api_url=api_url, + html_url=html_url ) return HttpResponseRedirect(reverse('home'))