Commit 95c62049 authored by Mirko Vucicevich's avatar Mirko Vucicevich
Browse files

Added slug field and made default project URLS use slugs

parent 8c9dfa2e
......@@ -51,7 +51,7 @@ class ProjectAdmin(admin.ModelAdmin):
list_display = ['title', 'url', 'get_groups']
fieldsets = [
('Project Information', {
'fields': ['title', 'icon', 'tagline', 'description', 'url', 'project_created']
'fields': ['title', 'slug', 'icon', 'tagline', 'description', 'url', 'project_created']
}),
('Project Details', {'fields': ['scope', 'technologies', 'groups']}),
('Gitlab Integration', {
......@@ -61,6 +61,8 @@ class ProjectAdmin(admin.ModelAdmin):
}),
]
prepopulated_fields = {'slug': ("title",)}
filter_horizontal = ['technologies', 'groups']
inlines = [ContributorInline, ContactInline, NoticeInline]
......
# Generated by Django 2.2.16 on 2020-10-07 17:38
from django.db import migrations, models
from django.utils.text import slugify
def forward_func(apps, schema_editor):
Project = apps.get_model('projector', 'Project')
for p in Project.objects.all():
slug = slugify(p.title)
existing_similar=Project.objects.filter(slug__startswith=slug).count()
if existing_similar > 0:
slug = '{}{}'.format(slug, existing_similar)
p.slug = slug
p.save()
def reverse_func(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('projector', '0031_auto_20191119_0721'),
]
operations = [
migrations.RunPython(forward_func, reverse_func),
migrations.AlterField(
model_name='project',
name='slug',
field=models.SlugField(max_length=250, unique=True),
),
]
......@@ -16,7 +16,10 @@ class Project(models.Model):
null=True,
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250, blank=True)
slug = models.SlugField(
max_length=250, unique=True,
help_text="Must be unique. Used for URLs"
)
tagline = models.CharField(
max_length=100,
help_text="Short, catchy sentence about the project"
......
......@@ -46,7 +46,7 @@ body {
}
.main{
padding-top: 68px;
padding-top: 4rem;
}
......
......@@ -41,7 +41,7 @@
<tbody>
{% for project in projects %}
<tr>
<th scope="row"><a href="{% url 'detail' project.id %}">{{ project.title }}</a></th>
<th scope="row"><a href="{% url 'detail' project.slug %}">{{ project.title }}</a></th>
<td>{{ project.tagline }}</td>
<td>
{% for group in project.groups.all %}
......
......@@ -27,9 +27,13 @@ except:
urlpatterns = [
path('', include(custom_url_patterns)),
path('', views.IndexView.as_view(), name='index'),
# Until we deprecate PK, both int and PK work :)
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
path('<int:pk>/json', project_json_view, name='json-detail'),
path('<int:pk>/send-message', send_message, name='send-message'),
path('<slug:slug>/', views.DetailView.as_view(), name='detail'),
path('<slug:slug>/json', project_json_view, name='json-detail'),
path('<slug:slug>/send-message', send_message, name='send-message'),
path('about/', views.about, name='about'),
path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment