Skip to content

Commit

Permalink
#346 autoslug (#420)
Browse files Browse the repository at this point in the history
* added autoslug fields to events

* fixed url position
  • Loading branch information
eduzen authored and cmdelatorre committed Apr 30, 2018
1 parent 6cc28e0 commit 896511d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions events/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Meta:
'description',
'place',
'address',
'slug',
'url',
'start_at',
'end_at',
Expand Down
20 changes: 20 additions & 0 deletions events/migrations/0004_auto_20180429_1546.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import autoslug.fields


class Migration(migrations.Migration):

dependencies = [
('events', '0003_eventparticipation_gender'),
]

operations = [
migrations.AddField(
model_name='event',
name='slug',
field=autoslug.fields.AutoSlugField(populate_from='name', editable=True, unique=True, blank=True, null=True, verbose_name='Url'),
),
]
5 changes: 5 additions & 0 deletions events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.core.urlresolvers import reverse
from email_confirm_la.models import EmailConfirmation

from autoslug import AutoSlugField

from jobs.models import JOB_SENIORITIES


Expand All @@ -25,6 +27,9 @@ class Event(models.Model):
description = models.TextField(verbose_name=_('Descripcion'))
place = models.CharField(max_length=100, verbose_name=_('Lugar'))
address = models.CharField(max_length=100, verbose_name=_('Direccion'))
slug = AutoSlugField(
editable=True, null=True, blank=True, unique=True, populate_from='name',
)
url = models.URLField(blank=True, null=True)
start_at = models.DateTimeField(verbose_name=_('Comienza a las'))
end_at = models.DateTimeField(verbose_name=_('Termina a las'))
Expand Down
5 changes: 5 additions & 0 deletions events/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,8 @@ def test_events_view_delete(self):
response = self.client.post(reverse('events:delete', args=(event.pk, )))
self.assertEqual(response.status_code, 302)
self.assertFalse(Event.objects.filter(name=event.name).exists())

def test_events_view_slug(self):
event = EventFactory()
response_por_slug = self.client.get('/eventos/{}/'.format(event.slug))
self.assertEqual(response_por_slug.context['event'].id, event.id)
4 changes: 4 additions & 0 deletions events/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-

from django.conf.urls import patterns, url
from django.views.generic.detail import DetailView

from .models import Event
from .views import (EventDetail,
EventList,
EventCreate,
Expand All @@ -21,6 +24,7 @@
url(r'^add/$', EventCreate.as_view(), name='add'),
url(r'^(?P<pk>\d+)/editar/$', EventUpdate.as_view(), name='edit'),
url(r'^(?P<pk>\d+)/borrar/$', EventDelete.as_view(), name='delete'),
url(r'^(?P<slug>[\w-]+)/$', DetailView.as_view(model=Event), name='event_slug'),

# Event Registration Management
url(r'^(?P<pk>\d+)/inscribirse/$', EventParticipationCreate.as_view(), name='register'),
Expand Down

0 comments on commit 896511d

Please sign in to comment.