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

Rama mapeveri #68

Closed
wants to merge 16 commits into from
18 changes: 16 additions & 2 deletions events/admin.py
Expand Up @@ -5,7 +5,7 @@
from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _

from events.models import Event, Registration
from events.models import Event, Registration, Category, CategoryEvent
from events.utils import newMail, pendingMail


Expand Down Expand Up @@ -47,7 +47,6 @@ def export_as_csv(modeladmin, request, queryset):

return export_as_csv


class RegistrationInline(admin.TabularInline):
model = Registration
list_display = ('name', 'email', 'website', 'event', 'twitter',
Expand All @@ -57,6 +56,19 @@ class RegistrationInline(admin.TabularInline):
'mailme', 'creationDate', 'event']
search_fields = ['name', 'email']

class CategoryAdmin(admin.ModelAdmin):
list_display = ('descrip',)
list_filter = ['descrip']
search_fields = ['descrip']

ordering = ['descrip']

class CategoryInline(admin.TabularInline):
model = CategoryEvent

list_display = ('category',)
list_filter = ['category']
search_fields = ['category']

class EventAdmin(admin.ModelAdmin):
# Autofill slugs
Expand All @@ -68,6 +80,7 @@ class EventAdmin(admin.ModelAdmin):

inlines = [
RegistrationInline,
CategoryInline,
]

# TinyMCE
Expand Down Expand Up @@ -129,4 +142,5 @@ class RegistrationAdmin(admin.ModelAdmin):

admin.site.register(Event, EventAdmin)
admin.site.register(Registration, RegistrationAdmin)
admin.site.register(Category, CategoryAdmin)

21 changes: 20 additions & 1 deletion events/models.py
Expand Up @@ -101,7 +101,7 @@ def peopleAttended(self):

def __unicode__(self):
return self.name

class Registration(models.Model):
'''
Model for individual registrations
Expand Down Expand Up @@ -152,3 +152,22 @@ def save(self):

def __unicode__(self):
return self.name

class Category(models.Model):
'''
Model for categories of events
'''

id = models.AutoField(primary_key=True)
descrip = models.CharField(_("Category"), max_length=100, default="")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a full name for this? description

Also, maybe we want a name and description for each category, as well as a slug for linking it?


def __unicode__(self):
return self.descrip

class CategoryEvent(models.Model):
'''
Model for relationship between Event and Cateogry
'''

event = models.ForeignKey(Event)
category = models.ForeignKey(Category, verbose_name=_("Category"))
11 changes: 6 additions & 5 deletions events/urls.py
Expand Up @@ -2,11 +2,12 @@


urlpatterns = patterns('events.views',
url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/registration/confirm/(?P<hash>\w+)$',
url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/registration/confirm/(?P<hash>\w+)$',
'confirmation'),
url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/registration/decline/(?P<hash>\w+)$',
url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/registration/decline/(?P<hash>\w+)$',
'decline'),
url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/registration/$', 'registration'),
url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/tweets/$', 'tweets'),
url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/$', 'detail'),
url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/registration/$', 'registration'),
url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/tweets/$', 'tweets'),
url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/$', 'detail'),
url(r'^events/category/(?P<id>\d+)/$','events_category'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add slug here too.

)
27 changes: 25 additions & 2 deletions events/views.py
Expand Up @@ -12,7 +12,7 @@
from django.views.generic import TemplateView

from events.forms import RegistrationForm
from events.models import Event, Registration
from events.models import Event, Registration, Category, CategoryEvent
from events.utils import newMail, pendingMail


Expand All @@ -25,21 +25,27 @@ def index(request):
oldEvents = Event.objects.filter(
active=True, eventDate__lt=now).order_by('-eventDate')

categorys = Category.objects.all()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/category/categories


data = {
'nextEvents': nextEvents,
'oldEvents': oldEvents,
'categorys': categorys,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/category/categories

}

return render_to_response(
'index.html', data, context_instance=RequestContext(request))


def detail(request, id, slug):
"""Event details page."""
event = get_object_or_404(Event, id=id, active=True)

"""Get all the categories related to the event"""
categorys = CategoryEvent.objects.filter(event_id=id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/category/categories


data = {
'event': event,
'categorys': categorys,
}

return render_to_response(
Expand Down Expand Up @@ -219,3 +225,20 @@ def stats(request):

return render_to_response(
'stats/index.html', data, context_instance=RequestContext(request))

def events_category(request, id):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use here id and slug as we use for the detail page, to be more search engine friendly.

"""
Filter evets for category
"""
events = CategoryEvent.objects.filter(category_id=id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use get_object_or_404 since we expect just one valid result

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here used try and catch why i need use filter model.

Used get_object_or_404 for model category.


ct = Category.objects.get(id=id)
category = ct.descrip

data = {
'events': events,
'category': category,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you pass just the category name?

If you pass the category object then in the template you can access all values easily category.name category.slug...

}

return render_to_response(
'events/events_categorys.html', data, context_instance=RequestContext(request))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/category/categories

Binary file added locale/en/LC_MESSAGES/django.mo
Binary file not shown.