Procházet zdrojové kódy

First model for seum counter

Denis Merigoux před 9 roky
rodič
revize
8fc3c05f22

+ 5 - 0
.gitignore

@@ -51,6 +51,8 @@ coverage.xml
51 51
 
52 52
 # Django stuff:
53 53
 *.log
54
+*.sqlite3
55
+counter/migrations/
54 56
 
55 57
 # Sphinx documentation
56 58
 docs/_build/
@@ -60,3 +62,6 @@ target/
60 62
 
61 63
 #Ipython Notebook
62 64
 .ipynb_checkpoints
65
+
66
+#Custom
67
+python3/

+ 0 - 0
counter/__init__.py


+ 6 - 0
counter/admin.py

@@ -0,0 +1,6 @@
1
+from django.contrib import admin
2
+
3
+# Register your models here.
4
+from .models import Counter
5
+
6
+admin.site.register(Counter)

+ 5 - 0
counter/apps.py

@@ -0,0 +1,5 @@
1
+from django.apps import AppConfig
2
+
3
+
4
+class CounterConfig(AppConfig):
5
+    name = 'counter'

+ 14 - 0
counter/models.py

@@ -0,0 +1,14 @@
1
+from django.db import models
2
+from datetime import datetime
3
+from babel.dates import format_timedelta
4
+
5
+# Create your models here.
6
+class Counter(models.Model):
7
+    name=models.CharField("Nom",max_length=60)
8
+    lastReset=models.DateTimeField("Dernière remise à zéro")
9
+
10
+    def __str__(self):
11
+        return "%s : %s" % (self.name,format_timedelta(datetime.now()-self.lastReset.replace(tzinfo=None),locale='fr'))
12
+
13
+    class Meta:
14
+        verbose_name = "Compteur"

+ 1 - 0
counter/templates/counterTemplate.html

@@ -0,0 +1 @@
1
+<h1>Coucou !</h1>

+ 3 - 0
counter/tests.py

@@ -0,0 +1,3 @@
1
+from django.test import TestCase
2
+
3
+# Create your tests here.

+ 7 - 0
counter/urls.py

@@ -0,0 +1,7 @@
1
+from django.conf.urls import url
2
+
3
+from . import views
4
+
5
+urlpatterns = [
6
+    url(r'^$', views.home,name='home'),
7
+]

+ 5 - 0
counter/views.py

@@ -0,0 +1,5 @@
1
+from django.shortcuts import render
2
+
3
+# Create your views here.
4
+def home(request):
5
+	return render(request,'counterTemplate.html')

+ 10 - 0
manage.py

@@ -0,0 +1,10 @@
1
+#!/usr/bin/env python
2
+import os
3
+import sys
4
+
5
+if __name__ == "__main__":
6
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "seum.settings")
7
+
8
+    from django.core.management import execute_from_command_line
9
+
10
+    execute_from_command_line(sys.argv)

+ 0 - 0
seum/__init__.py


+ 123 - 0
seum/settings.py

@@ -0,0 +1,123 @@
1
+"""
2
+Django settings for seum project.
3
+
4
+Generated by 'django-admin startproject' using Django 1.9.4.
5
+
6
+For more information on this file, see
7
+https://docs.djangoproject.com/en/1.9/topics/settings/
8
+
9
+For the full list of settings and their values, see
10
+https://docs.djangoproject.com/en/1.9/ref/settings/
11
+"""
12
+
13
+import os
14
+
15
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17
+
18
+
19
+# Quick-start development settings - unsuitable for production
20
+# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
21
+
22
+# SECURITY WARNING: keep the secret key used in production secret!
23
+SECRET_KEY = '(#lovv#uky9unr9azzqy14gktpf0(d&+cp@++l95*y4e%m%_ex'
24
+
25
+# SECURITY WARNING: don't run with debug turned on in production!
26
+DEBUG = True
27
+
28
+ALLOWED_HOSTS = []
29
+
30
+
31
+# Application definition
32
+
33
+INSTALLED_APPS = [
34
+    'babel',
35
+    'django.contrib.admin',
36
+    'django.contrib.auth',
37
+    'django.contrib.contenttypes',
38
+    'django.contrib.sessions',
39
+    'django.contrib.messages',
40
+    'django.contrib.staticfiles',
41
+    'counter'
42
+]
43
+
44
+MIDDLEWARE_CLASSES = [
45
+    'django.middleware.security.SecurityMiddleware',
46
+    'django.contrib.sessions.middleware.SessionMiddleware',
47
+    'django.middleware.common.CommonMiddleware',
48
+    'django.middleware.csrf.CsrfViewMiddleware',
49
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
50
+    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
51
+    'django.contrib.messages.middleware.MessageMiddleware',
52
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
53
+]
54
+
55
+ROOT_URLCONF = 'seum.urls'
56
+
57
+TEMPLATES = [
58
+    {
59
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
60
+        'DIRS': [],
61
+        'APP_DIRS': True,
62
+        'OPTIONS': {
63
+            'context_processors': [
64
+                'django.template.context_processors.debug',
65
+                'django.template.context_processors.request',
66
+                'django.contrib.auth.context_processors.auth',
67
+                'django.contrib.messages.context_processors.messages',
68
+            ],
69
+        },
70
+    },
71
+]
72
+
73
+WSGI_APPLICATION = 'seum.wsgi.application'
74
+
75
+
76
+# Database
77
+# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
78
+
79
+DATABASES = {
80
+    'default': {
81
+        'ENGINE': 'django.db.backends.sqlite3',
82
+        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
83
+    }
84
+}
85
+
86
+
87
+# Password validation
88
+# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
89
+
90
+AUTH_PASSWORD_VALIDATORS = [
91
+    {
92
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
93
+    },
94
+    {
95
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
96
+    },
97
+    {
98
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
99
+    },
100
+    {
101
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
102
+    },
103
+]
104
+
105
+
106
+# Internationalization
107
+# https://docs.djangoproject.com/en/1.9/topics/i18n/
108
+
109
+LANGUAGE_CODE = 'en-us'
110
+
111
+TIME_ZONE = 'UTC'
112
+
113
+USE_I18N = True
114
+
115
+USE_L10N = True
116
+
117
+USE_TZ = True
118
+
119
+
120
+# Static files (CSS, JavaScript, Images)
121
+# https://docs.djangoproject.com/en/1.9/howto/static-files/
122
+
123
+STATIC_URL = '/static/'

+ 22 - 0
seum/urls.py

@@ -0,0 +1,22 @@
1
+"""seum URL Configuration
2
+
3
+The `urlpatterns` list routes URLs to views. For more information please see:
4
+    https://docs.djangoproject.com/en/1.9/topics/http/urls/
5
+Examples:
6
+Function views
7
+    1. Add an import:  from my_app import views
8
+    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
9
+Class-based views
10
+    1. Add an import:  from other_app.views import Home
11
+    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
12
+Including another URLconf
13
+    1. Import the include() function: from django.conf.urls import url, include
14
+    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
15
+"""
16
+from django.conf.urls import url, include
17
+from django.contrib import admin
18
+
19
+urlpatterns = [
20
+    url(r'^admin/', admin.site.urls),
21
+    url(r'seum/', include('counter.urls'))
22
+]

+ 16 - 0
seum/wsgi.py

@@ -0,0 +1,16 @@
1
+"""
2
+WSGI config for seum project.
3
+
4
+It exposes the WSGI callable as a module-level variable named ``application``.
5
+
6
+For more information on this file, see
7
+https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
8
+"""
9
+
10
+import os
11
+
12
+from django.core.wsgi import get_wsgi_application
13
+
14
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "seum.settings")
15
+
16
+application = get_wsgi_application()