commit insidepages code.. bad idea..

This commit is contained in:
Sanj 2011-08-23 03:34:40 +05:30
parent 575984fbd7
commit 8cf2c63815
6 changed files with 117 additions and 0 deletions

View File

16
itf/insidepages/admin.py Normal file
View File

@ -0,0 +1,16 @@
from django.contrib import admin
from models import *
# from forms import ArticleForm
class TabsInline(admin.StackedInline):
model = ModuleTab
extra = 4
class ModuleAdmin(admin.ModelAdmin):
inlines = [TabsInline]
# list_display = ('name', 'order',)
# list_editable = ['order']
admin.site.register(Module, ModuleAdmin)
#admin.site.register(SliderBox, SliderBoxAdmin)

30
itf/insidepages/models.py Normal file
View File

@ -0,0 +1,30 @@
from django.db import models
from django.contrib.contenttypes.models import ContentType
class Module(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField()
def __unicode__(self):
return self.title
def get_absolute_url(self):
return "/m/" + self.slug
class ModuleTab(models.Model):
module = models.ForeignKey(Module)
title = models.CharField(max_length=64)
text = models.TextField()
model = models.ForeignKey(ContentType)
is_default = models.BooleanField(default=False)
order = models.IntegerField(default=1)
is_displayed = models.BooleanField(default=True)
def __unicode__(self):
return self.title
def get_list(self, options):
return self.model.model_class().get_list(options)

23
itf/insidepages/tests.py Normal file
View File

@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

8
itf/insidepages/urls.py Normal file
View File

@ -0,0 +1,8 @@
from django.conf.urls.defaults import *
import views
urlpatterns = patterns('',
(r'^get_list$', views.get_list),
(r'^get_details$', views.get_details),
(r'^(?P<module_slug>.*)$', views.main),
)

40
itf/insidepages/views.py Normal file
View File

@ -0,0 +1,40 @@
from models import Module, ModuleTab
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from ox.django.shortcuts import render_to_json_response
def main(request, module_slug):
m = get_object_or_404(Module, slug=module_slug)
tabs = m.moduletab_set.all()
default_tab = tabs[0]
list_options = {} #get some options as GET params, etc. to potentially pass to get_list
default_tab_list = default_tab.model.model_class().get_list(list_options)
context = RequestContext(request, {
'title': m.title,
'default_tab': tabs[0],
'default_list': default_tab_list,
'tabs': tabs[1:]
})
return render_to_response("noel/insidepage.html", context)
def get_list(request):
tab_id = request.GET.get("tab", 0)
tab = get_object_or_404(ModuleTab, pk=tab_id)
list_options = {
'search': request.GET.get("search", ""),
'sort': request.GET.get("sort", ""),
'page': request.GET.get("page_no", 1)
}
object_list = tab.get_list(list_options)
return render_to_json_response(object_list)
def get_details(request):
tab_id = request.GET.get("tab_id", 0)
tab = get_object_or_404(ModuleTab, pk=tab_id)
model_class = tab.model.model_class()
object_id = request.GET.get("object_id", 0)
obj = get_object_or_404(model_class, pk=object_id)
return render_to_json_response(obj.insidepage_dict())