Commits

Łukasz Langa  committed f3c4cc6

initial version, very minimalistic

  • Participants

Comments (0)

Files changed (13)

File src/quotes/__init__.py

Empty file added.

File src/quotes/app/__init__.py

+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2010 Łukasz Langa
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import absolute_import
+from __future__ import print_function
+from __future__ import unicode_literals

File src/quotes/app/admin.py

+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2010 Łukasz Langa
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import absolute_import
+from __future__ import print_function
+from __future__ import unicode_literals
+
+from django.contrib import admin
+
+from quotes.app import models as m
+
+
+class QuoteAdmin(admin.ModelAdmin):
+    def get_desc(self):
+        return self.short_description()
+    get_desc.short_description = "description"
+    get_desc.admin_order_field = "content"
+
+    list_display = (get_desc,)
+    search_fields = ("content", "source", "author")
+
+admin.site.register(m.Quote, QuoteAdmin)

File src/quotes/app/models.py

+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2010 Łukasz Langa
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import absolute_import
+from __future__ import print_function
+from __future__ import unicode_literals
+
+from django.db import models as db
+
+class Quote(db.Model):
+    content = db.TextField()
+    source = db.URLField(blank=True)
+    author = db.CharField(max_length=200, blank=True)
+    added = db.DateTimeField(auto_now_add=True)
+
+    def short_description(self):
+        return "{}{}".format(self.content[:30],
+                                    " (...)" if len(self.content) > 30 \
+                                             else "")
+
+    def __unicode__(self):
+        return "{} --[{}]".format(self.short_description(),
+                                  self.source[:30] if self.source \
+                                                   else self.author)

File src/quotes/app/tests.py

+"""
+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
+"""}
+

File src/quotes/app/views.py

+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2010 Łukasz Langa
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import absolute_import
+from __future__ import print_function
+from __future__ import unicode_literals
+
+from langacore.kit.django.helpers import render
+
+from quotes.app.models import Quote
+
+def list(request):
+    quotes = Quote.objects.all().order_by('-added')
+    return render(request, "list.html", locals())

File src/quotes/manage.py

+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+    import settings # Assumed to be in the same directory.
+except ImportError:
+    import sys
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)

File src/quotes/media/css/base.css

+html {
+  background-color: #eeeeee;
+}
+
+body {
+  font: 12pt Georgia;
+  margin: 2em;
+}
+
+a {
+  color: #444444;
+}
+
+a:visited {
+  color: #888888;
+}
+
+h1 {
+  text-align: center;
+  margin-top: 1em;
+  margin-bottom: 1em;
+  font-size: 3em;
+}
+
+blockquote {
+  width: 400px;
+  margin: auto;
+  padding-left: 50px;
+  background: transparent url(/media/img/quote.gif) no-repeat;
+}
+
+p.author {
+  margin-top: 1em;
+  margin-bottom: 1em;
+  text-align: right;
+

File src/quotes/media/css/reset-min.css

+/*
+Copyright (c) 2010, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.com/yui/license.html
+version: 3.2.0
+build: 2676
+*/
+html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}

File src/quotes/media/img/quote.gif

Added
New image

File src/quotes/settings.py

+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2010 Łukasz Langa
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from langacore.kit.django import current_dir_support
+execfile(current_dir_support)
+
+from langacore.kit.django import namespace_package_support
+execfile(namespace_package_support)
+
+#
+# common stuff for each install
+#
+
+ADMINS = ((u'Łukasz Langa', 'lukasz@langa.pl'),)
+MANAGERS = ADMINS
+TIME_ZONE = 'Europe/Warsaw'
+LANGUAGE_CODE = 'en-us'
+USE_I18N = True
+USE_L10N = True
+MEDIA_ROOT = CURRENT_DIR + 'media'
+MEDIA_URL = '/media/'
+ADMIN_MEDIA_PREFIX = MEDIA_URL + 'admin/'
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.Loader',
+    'django.template.loaders.app_directories.Loader',
+)
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+ROOT_URLCONF = 'quotes.urls'
+TEMPLATE_DIRS = (
+    CURRENT_DIR + 'templates/',
+)
+INSTALLED_APPS = (
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.admin',
+    'django.contrib.webdesign',
+    'langacore.kit.django.common',
+    'quotes.app',
+)
+
+#
+# stuff that should be customized in settings_local.py
+#
+
+SECRET_KEY = '-^kuq@#gnr9u8=@v7m=q98aqpo2w&j87*gz0h(t#xut_&6spgl'
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+TEMPLATE_STRING_IF_INVALID = '[INVALID %s]'
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': CURRENT_DIR + 'development.db',
+        'USER': '',
+        'PASSWORD': '',
+        'HOST': '',
+        'PORT': '',
+    }
+}
+
+from langacore.kit.django import profile_support
+execfile(profile_support)

File src/quotes/templates/list.html

+<!doctype html>
+<html>
+  <head>
+    <meta charset="UTF-8">
+    <link rel="stylesheet" type="text/css" href="/media/css/reset-min.css"><!-- YUI 3.2.0 -->
+    <link rel="stylesheet" type="text/css" href="/media/css/base.css">
+  </head>
+  <body>
+    <h1>Remarkable Quotes</h1>
+    <p>
+    {%for quote in quotes%}
+    <blockquote>
+      <p class="quote">{{quote.content}}
+      <p class="author">
+      {%if quote.source %}
+      -- <a href="{{quote.source}}">{%if quote.author %}{{quote.author}}{%else%}{{quote.source}}{%endif%}</a>
+      {%else%}
+      -- {{quote.author}}
+      {%endif%} 
+    </blockquote>
+    {%endfor%}
+    </p>
+  </body>
+</html>

File src/quotes/urls.py

+from django.conf import settings
+from django.conf.urls.defaults import *
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+    (r'^$', 'quotes.app.views.list'),
+    (r'^admin/', include(admin.site.urls)),
+    (r'^media/(?P<path>.*)$', 'django.views.static.serve',
+                              {'document_root': settings.MEDIA_ROOT,
+                               'show_indexes': True}),
+)