From 8cf2c63815f0217f4afd0a2fdd11cdbc5b269414 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 23 Aug 2011 03:34:40 +0530 Subject: [PATCH] commit insidepages code.. bad idea.. --- itf/insidepages/__init__.py | 0 itf/insidepages/admin.py | 16 +++++++++++++++ itf/insidepages/models.py | 30 ++++++++++++++++++++++++++++ itf/insidepages/tests.py | 23 +++++++++++++++++++++ itf/insidepages/urls.py | 8 ++++++++ itf/insidepages/views.py | 40 +++++++++++++++++++++++++++++++++++++ 6 files changed, 117 insertions(+) create mode 100644 itf/insidepages/__init__.py create mode 100644 itf/insidepages/admin.py create mode 100644 itf/insidepages/models.py create mode 100644 itf/insidepages/tests.py create mode 100644 itf/insidepages/urls.py create mode 100644 itf/insidepages/views.py diff --git a/itf/insidepages/__init__.py b/itf/insidepages/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/itf/insidepages/admin.py b/itf/insidepages/admin.py new file mode 100644 index 0000000..741f9f6 --- /dev/null +++ b/itf/insidepages/admin.py @@ -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) + diff --git a/itf/insidepages/models.py b/itf/insidepages/models.py new file mode 100644 index 0000000..4c9d5e7 --- /dev/null +++ b/itf/insidepages/models.py @@ -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) + diff --git a/itf/insidepages/tests.py b/itf/insidepages/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/itf/insidepages/tests.py @@ -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 +"""} + diff --git a/itf/insidepages/urls.py b/itf/insidepages/urls.py new file mode 100644 index 0000000..875c3b3 --- /dev/null +++ b/itf/insidepages/urls.py @@ -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.*)$', views.main), +) diff --git a/itf/insidepages/views.py b/itf/insidepages/views.py new file mode 100644 index 0000000..0b1dc56 --- /dev/null +++ b/itf/insidepages/views.py @@ -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()) +