From cb96e0a20f43730cf779f3a79ee9809cbb6a02e7 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 1 Aug 2011 19:19:19 +0530 Subject: [PATCH] front page admin + slider --- itf/frontpage/__init__.py | 0 itf/frontpage/admin.py | 21 +++++++++++++++++ itf/frontpage/models.py | 44 +++++++++++++++++++++++++++++++++++ itf/frontpage/tests.py | 23 ++++++++++++++++++ itf/frontpage/views.py | 27 +++++++++++++++++++++ itf/settings.py | 3 +++ itf/static/css/noel/home.css | 8 +++++-- itf/templates/noel/base.html | 24 ++++++++++++++++++- itf/templates/noel/index.html | 19 ++++++++++++++- itf/urls.py | 1 + 10 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 itf/frontpage/__init__.py create mode 100644 itf/frontpage/admin.py create mode 100644 itf/frontpage/models.py create mode 100644 itf/frontpage/tests.py create mode 100644 itf/frontpage/views.py diff --git a/itf/frontpage/__init__.py b/itf/frontpage/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/itf/frontpage/admin.py b/itf/frontpage/admin.py new file mode 100644 index 0000000..07f1210 --- /dev/null +++ b/itf/frontpage/admin.py @@ -0,0 +1,21 @@ +from django.contrib import admin +from models import * +# from forms import ArticleForm + +class MenuItemInline(admin.StackedInline): + model = MenuItem + extra = 7 + +class SliderBoxAdmin(admin.ModelAdmin): + list_display = ('title', 'order',) + list_editable = ['order'] +# list_display = ('title', 'date',) + +class MenuHeadingAdmin(admin.ModelAdmin): + inlines = [MenuItemInline] + list_display = ('name', 'order',) + list_editable = ['order'] + +admin.site.register(MenuHeading, MenuHeadingAdmin) +admin.site.register(SliderBox, SliderBoxAdmin) + diff --git a/itf/frontpage/models.py b/itf/frontpage/models.py new file mode 100644 index 0000000..28287c1 --- /dev/null +++ b/itf/frontpage/models.py @@ -0,0 +1,44 @@ +from django.db import models + +class SliderBox(models.Model): + title = models.CharField(max_length=64) + image = models.ImageField(upload_to='upload/sliderImages/') + boldText = models.CharField(max_length=256, blank=True) + normalText = models.CharField(max_length=256, blank=True) + url = models.CharField(max_length=128, blank=True) + order = models.IntegerField(default=1) + imageTop = models.IntegerField(default=0) + is_displayed = models.BooleanField(default=True) + + def __unicode__(self): + return self.title + + class Meta: + ordering = ['order', 'id'] + + +class MenuHeading(models.Model): + name = models.CharField(max_length=64) + order = models.IntegerField(default=1) + + def __unicode__(self): + return self.name + + class Meta: + ordering = ['order', 'id'] + + +class MenuItem(models.Model): + name = models.CharField(max_length=64) + url = models.CharField(max_length=256) + menu = models.ForeignKey(MenuHeading) + order = models.IntegerField(default=1) + + def __unicode__(self): + return self.name + + class Meta: + ordering = ['order', 'id'] + + +# Create your models here. diff --git a/itf/frontpage/tests.py b/itf/frontpage/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/itf/frontpage/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/frontpage/views.py b/itf/frontpage/views.py new file mode 100644 index 0000000..4016eb4 --- /dev/null +++ b/itf/frontpage/views.py @@ -0,0 +1,27 @@ +# Create your views here. +from django.shortcuts import render_to_response +from models import * +from settings import TWITTER_ID +import twitter + + +def index(request): + tApi = twitter.Api() + statuses = tApi.GetUserTimeline(TWITTER_ID) + boxes = SliderBox.objects.all() + menuHeads = MenuHeading.objects.all() + menus = [] + for m in menuHeads: + d = { + 'name': m.name, + 'items': [{'name': item.name, 'url': item.url} for item in m.menuitem_set.all()] + } + menus.append(d) + return render_to_response("noel/index.html", { + 'tweets': statuses[0:5], + 'boxes': boxes, + 'menus': menus + }) + + + diff --git a/itf/settings.py b/itf/settings.py index a2716d8..1f29996 100644 --- a/itf/settings.py +++ b/itf/settings.py @@ -38,6 +38,8 @@ DATABASE_PASSWORD = '' # Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. +TWITTER_ID = "sachin_rt" + CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', @@ -142,6 +144,7 @@ INSTALLED_APPS = ( 'app', 'api', 'boxes', + 'frontpage', # 'solango', 'multilingual', # 'multilingual.flatpages', diff --git a/itf/static/css/noel/home.css b/itf/static/css/noel/home.css index c5e2d0a..68c2ef6 100644 --- a/itf/static/css/noel/home.css +++ b/itf/static/css/noel/home.css @@ -74,6 +74,7 @@ opacity:0.6;} height:282px; background-color:#FFF; position:relative; +background-repeat: no-repeat; -moz-border-radius:8px; -webkit-border-radius:8px; border-radius:8px; @@ -171,7 +172,7 @@ clear:both; margin-left:auto; margin-right:auto; padding-top:37px; -overflow-y:hidden; +overflow:hidden; clear:both; position:relative;} @@ -189,7 +190,10 @@ right:10px;} #sliderTabs /*at 800 res, we have different probs in different browsers with the tabs, ok to give position absolute to the ul?*/ -{width:4000px;} +{width:4000px; +position:absolute; +left:0px; +} ul#sliderTabs li {float:left;} diff --git a/itf/templates/noel/base.html b/itf/templates/noel/base.html index 4d93557..68d49d9 100644 --- a/itf/templates/noel/base.html +++ b/itf/templates/noel/base.html @@ -22,6 +22,16 @@ home