From 6eb13a13cb84ee1e4c0588a33029607649023fe8 Mon Sep 17 00:00:00 2001 From: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:43:59 -0500 Subject: [PATCH 1/2] Fix URL handling in add_domain_to_company and streamline date handling in ProjectDetailView --- website/views/organization.py | 5 ++++- website/views/project.py | 12 +++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/website/views/organization.py b/website/views/organization.py index b139d45d7..52a69a30f 100644 --- a/website/views/organization.py +++ b/website/views/organization.py @@ -54,7 +54,10 @@ def add_domain_to_company(request): company = Company.objects.filter(name=company_name).first() if not company: - response = requests.get(domain.url) + url = domain.url + if not url.startswith(("http://", "https://")): + url = "http://" + url + response = requests.get(url) soup = BeautifulSoup(response.text, "html.parser") if company_name in soup.get_text(): company = Company.objects.create(name=company_name) diff --git a/website/views/project.py b/website/views/project.py index 10e5964fc..84451dd67 100644 --- a/website/views/project.py +++ b/website/views/project.py @@ -1,6 +1,6 @@ import json import re -from datetime import datetime, timedelta, timezone +from datetime import datetime, timedelta from pathlib import Path import requests @@ -8,6 +8,7 @@ from django.contrib.auth.decorators import user_passes_test from django.http import HttpResponse from django.shortcuts import get_object_or_404, redirect, render +from django.utils.timezone import now from django.views.generic import DetailView, ListView from PIL import Image, ImageDraw, ImageFont from rest_framework.views import APIView @@ -87,9 +88,6 @@ def post(self, request, *args, **kwargs): elif "refresh_contributors" in request.POST: call_command("fetch_contributors", "--project_id", project.pk) - messages.success(request, f"Refreshing contributors for {project.name}") - return redirect("project_view", slug=project.slug) - return redirect("project_view", slug=project.slug) def get(self, request, *args, **kwargs): @@ -100,7 +98,7 @@ def get(self, request, *args, **kwargs): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - end_date = timezone.now() + end_date = now() display_end_date = end_date.date() selected_year = self.request.GET.get("year", None) if selected_year: @@ -151,7 +149,7 @@ def get_context_data(self, **kwargs): user_stats = dict(sorted(user_stats.items(), key=lambda x: x[1]["total"], reverse=True)) - current_year = timezone.now().year + current_year = now().year year_list = list(range(current_year, current_year - 10, -1)) context.update( @@ -168,7 +166,7 @@ def get_context_data(self, **kwargs): class ProjectBadgeView(APIView): - def get(self, request, slug, format=None): + def get(self, request, slug): # Retrieve the project or return 404 project = get_object_or_404(Project, slug=slug) From 64e3b18bce2c306208fd748662f47ad5c32ba7f9 Mon Sep 17 00:00:00 2001 From: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:46:32 -0500 Subject: [PATCH 2/2] Redirect to 'home' instead of 'index' after adding domain to company --- website/views/organization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/views/organization.py b/website/views/organization.py index 52a69a30f..6a7e9681a 100644 --- a/website/views/organization.py +++ b/website/views/organization.py @@ -74,7 +74,7 @@ def add_domain_to_company(request): messages.success(request, "Organization added successfully") return redirect("domain", slug=domain.url) else: - return redirect("index") + return redirect("home") @login_required(login_url="/accounts/login")