Commits

Tairan Wang  committed ddea835

a part of prototype

  • Participants
  • Parent commits 34645a2

Comments (0)

Files changed (10)

File lifeleft/app/__init__.py

Empty file added.

File lifeleft/app/forms.py

+from django import forms
+
+class SetForm(forms.Form):
+    pass

File lifeleft/app/models.py

+from django.db import models
+
+# Create your models here.

File lifeleft/app/templates/display.html

+<h2>My life left...</h2>
+{{ table|safe }}

File lifeleft/app/templates/setting.html

+<form action="" method="post">
+    <select name="year">
+        {% for year in years %}
+        <option value="{{ year }}">{{ year }}</option>
+        {% endfor %}
+    </select>
+</form>

File lifeleft/app/tests.py

+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this 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.assertEqual(1 + 1, 2)

File lifeleft/app/views.py

+#-*- coding: utf-8 -*-
+from datetime import date
+from django.shortcuts import render_to_response
+
+def _get_date(year, month, day):
+    return date(year, month, day)
+
+def _get_table(x=30, y=30):
+    html = '<table>'
+    current = 0
+    current_month = 350
+    for i in range(1, x+1):
+        html += "<tr>"
+        for j in range(1, y+1):
+            current = current + 1
+            if current == current_month:
+                html += '<td style="border:solid 1px #ccc;background-color:green;">%s</td>' % current
+            elif current < current_month:
+                html += '<td style="border:solid 1px #ccc;background-color:red;">%s</td>' % current
+            else:
+                html += '<td style="border:solid 1px #ccc">%s</td>' % current
+        html += "</tr>"
+    html += "</table>"
+    return html
+
+def setting(request, **kwargs):
+    tpl_name = kwargs.pop('template_name', 'setting.html')
+
+    context = {}
+    context['years'] = range(1900, 2012)
+    context['months'] = range(1, 12)
+    context['days'] = range(1, 31)
+    
+    return render_to_response(tpl_name, context)
+
+def display(request, **kwargs):
+    tpl_name = kwargs.pop('template_name', 'display.html')
+    
+    context = {}
+    context['table'] = _get_table()
+    
+    return render_to_response(tpl_name, context)

File lifeleft/settings.py

 # timezone as the operating system.
 # If running in a Windows environment this must be set to the same as your
 # system time zone.
-TIME_ZONE = 'America/Chicago'
+TIME_ZONE = 'Asia/Shanghai'
 
 # Language code for this installation. All choices can be found here:
 # http://www.i18nguy.com/unicode/language-identifiers.html
     # 'django.contrib.admin',
     # Uncomment the next line to enable admin documentation:
     # 'django.contrib.admindocs',
+    'lifeleft.app',
 )
 
 # A sample logging configuration. The only tangible logging

File lifeleft/urls.py

 
 urlpatterns = patterns('',
     # Examples:
-    # url(r'^$', 'lifeleft.views.home', name='home'),
+    url(r'^$', 'lifeleft.app.views.setting', name='setting'),
+    url(r'^display/$', 'lifeleft.app.views.display', name='display'),
     # url(r'^lifeleft/', include('lifeleft.foo.urls')),
 
     # Uncomment the admin/doc line below to enable admin documentation:

File lifeleft/utils.py

+#-*- coding:utf8  -*-
+from datetime import date
+
+class LeftCal():
+    birthday = None
+
+    def __init__(self, year, month, day):
+        self.birthday = date(year, month, day)