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
25 changes: 23 additions & 2 deletions events/admin.py
Expand Up @@ -4,8 +4,9 @@
from django.contrib import admin
from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe

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 +48,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 +57,25 @@ class RegistrationInline(admin.TabularInline):
'mailme', 'creationDate', 'event']
search_fields = ['name', 'email']

class CategoryAdmin(admin.ModelAdmin):
# Autofill slugs
prepopulated_fields = {"slug": ("name",)}
list_display = ('name',)
list_filter = ['name']
search_fields = ['name']

ordering = ['name']

# TinyMCE
class Media:
js = ('/static/js/tiny_mce/tiny_mce.js', '/static/js/textareas.js')

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 +87,7 @@ class EventAdmin(admin.ModelAdmin):

inlines = [
RegistrationInline,
CategoryInline,
]

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

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

24 changes: 23 additions & 1 deletion events/models.py
Expand Up @@ -5,6 +5,7 @@
from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_str, smart_unicode
from django.template import defaultfilters

from django_countries.countries import COUNTRIES

Expand Down Expand Up @@ -101,7 +102,7 @@ def peopleAttended(self):

def __unicode__(self):
return self.name

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

def __unicode__(self):
return self.name

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

id = models.AutoField(primary_key=True)
name = models.CharField(_("Category"), max_length=100, default="")
slug = models.SlugField(_("Slug"))
description = models.TextField(_("Description"), blank=True, null=True)
Copy link
Member

Choose a reason for hiding this comment

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

Adding a slug here would be useful for urls. See comments below.


def __unicode__(self):
return self.name

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

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+)/(?P<slug>[-\w]+)/$','events_category'),
)
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')

categories = Category.objects.all()

data = {
'nextEvents': nextEvents,
'oldEvents': oldEvents,
'categories': 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"""
categories = CategoryEvent.objects.filter(event_id=id)

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

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, slug):
"""
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.name

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_categories.html', data, context_instance=RequestContext(request))
Binary file added locale/en/LC_MESSAGES/django.mo
Binary file not shown.