Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack field in project. #3238

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions website/migrations/0181_project_slack_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.4 on 2025-01-17 07:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("website", "0180_rename_project_visit_count_repo_repo_visit_count"),
]

operations = [
migrations.AddField(
model_name="project",
name="slack_url",
field=models.URLField(blank=True, null=True),
),
]
17 changes: 17 additions & 0 deletions website/migrations/0182_alter_repo_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1.4 on 2025-01-17 07:52

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("website", "0181_project_slack_url"),
]

operations = [
migrations.AlterModelOptions(
name="repo",
options={"ordering": ["-created"]},
),
]
6 changes: 4 additions & 2 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,7 @@ class Project(models.Model):
logo = models.ImageField(upload_to="project_logos", null=True, blank=True)
created = models.DateTimeField(auto_now_add=True) # Standardized field name
modified = models.DateTimeField(auto_now=True) # Standardized field name
# add languages
# add tags
slack_url = models.URLField(blank=True, null=True)

def save(self, *args, **kwargs):
if not self.slug:
Expand Down Expand Up @@ -1281,6 +1280,9 @@ class Repo(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
ordering = ['-created'] # Order by creation date by default

def save(self, *args, **kwargs):
if not self.slug:
base_slug = slugify(self.name)
Expand Down
8 changes: 7 additions & 1 deletion website/templates/projects/project_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,13 @@ <h3 class="text-xl font-bold text-gray-900">Add New Project</h3>
<div>
<label class="block text-sm font-medium text-gray-700">Project URL</label>
<input type="url"
name="url"
name="project_url"
class="mt-1 w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Slack URL</label>
<input type="url"
name="slack_url"
class="mt-1 w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500" />
</div>
{% if user.is_authenticated %}
Expand Down
10 changes: 10 additions & 0 deletions website/templates/projects/repo_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ <h1 class="text-3xl font-bold text-gray-900">{{ repo.name }}</h1>
Visit Homepage
</a>
{% endif %}
{% if repo.slack_url %}
<a href="{{ repo.slack_url }}"
target="_blank"
class="inline-flex items-center px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg transition-colors">
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h1v4H3v-4zm2 0h1v4H5v-4zm2 0h1v4H7v-4zm2 0h1v4H9v-4zm2 0h1v4h-1v-4zm2 0h1v4h-1v-4zm2 0h1v4h-1v-4zm2 0h1v4h-1v-4zm2 0h1v4h-1v-4zm2 0h1v4h-1v-4z" />
</svg>
Join Slack
</a>
{% endif %}
<a href="{{ repo.repo_url }}"
target="_blank"
class="inline-flex items-center px-4 py-2 bg-red-500 hover:bg-red-600 text-white rounded-lg transition-colors">
Expand Down
23 changes: 20 additions & 3 deletions website/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def get_queryset(self):

if organization_id:
queryset = queryset.filter(project__organization_id=organization_id)
return queryset.select_related("project").prefetch_related("tags", "contributor")
return queryset.select_related("project").prefetch_related("tags", "contributor").order_by('-created')

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down Expand Up @@ -343,6 +343,12 @@ def validate_url(url):
except (ValidationError, ValueError):
return False

# def validate_slack_url(url):
# """Validate Slack invite URL"""
# if not url:
# return True # Slack URL is optional
# return re.match(r"https://[a-zA-Z0-9]+\.slack\.com/invite/[a-zA-Z0-9]+", url) is not None

# Validate project URL
project_url = request.POST.get("url")
if project_url and not validate_url(project_url):
Expand Down Expand Up @@ -380,6 +386,16 @@ def validate_url(url):
status=400,
)

slack_url = request.POST.get("slack_url")
# if slack_url and not validate_slack_url(slack_url):
# return JsonResponse(
# {
# "error": "Invalid Slack invite URL",
# "code": "INVALID_SLACK_URL",
# },
# status=400,
# )

# Validate repository URLs
repo_urls = request.POST.getlist("repo_urls[]")
for url in repo_urls:
Expand Down Expand Up @@ -427,7 +443,7 @@ def validate_url(url):
) # 409 Conflict

# Check if project URL already exists
project_url = request.POST.get("url")
project_url = request.POST.get("project_url")
if project_url and Project.objects.filter(url=project_url).exists():
return JsonResponse(
{
Expand All @@ -436,7 +452,7 @@ def validate_url(url):
},
status=409,
)

slack_url = request.POST.get("slack_url")
# Check if any of the repository URLs are already linked to other projects
repo_urls = request.POST.getlist("repo_urls[]")
existing_repos = Repo.objects.filter(repo_url__in=repo_urls)
Expand All @@ -456,6 +472,7 @@ def validate_url(url):
"name": project_name,
"description": request.POST.get("description"),
"url": project_url,
"slack_url": slack_url,
"twitter": request.POST.get("twitter"),
"facebook": request.POST.get("facebook"),
}
Expand Down
Loading