Skip to content

Commit cb9d9c4

Browse files
committed
Initial
0 parents  commit cb9d9c4

File tree

107 files changed

+2179
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+2179
-0
lines changed

.flake8

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
ignore = E203, E266, E501, W503
3+
max-line-length = 88
4+
max-complexity = 12
5+
select = B,C,E,F,W,T4,B9

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Django ###
2+
*.log
3+
*.pot
4+
*.pyc
5+
__pycache__/
6+
local_settings.py
7+
*.pyc
8+
*.swp
9+
*.swo
10+
*.bz
11+
*.b
12+
*.db
13+
.idea
14+
.vagrant
15+
local.py
16+
db.sqlite3
17+
media
18+
.vs
19+
node_modules

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
etsd
2+
=============================

dj.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python manage.py %*

dovenv.bat

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
call ..\venv\scripts\activate
2+
set DJANGO_SETTINGS_MODULE=etsd.settings.dev

etsd/__init__.py

Whitespace-only changes.

etsd/core/__init__.py

Whitespace-only changes.

etsd/core/admin.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Register your models here.

etsd/core/apps.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from __future__ import unicode_literals
2+
3+
from django.apps import AppConfig
4+
5+
6+
class CoreConfig(AppConfig):
7+
name = "core"

etsd/core/auth.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import django.contrib.auth.backends
2+
3+
4+
class NoLoginModelBackend(django.contrib.auth.backends.ModelBackend):
5+
"""
6+
Don't allow login for model-based users - please be careful this
7+
is needed to allow using django permissions!
8+
"""
9+
10+
def authenticate(self, username=None, password=None):
11+
return None

etsd/core/context_processors.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.conf import settings
2+
3+
4+
def default_cp(request):
5+
return {"site_id": settings.SITE_ID}

etsd/core/migrations/0001_initial.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 2.1.2 on 2018-10-19 08:25
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='GlobalPermissionHolder',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
],
19+
options={
20+
'permissions': (('user', 'Application user'), ('admin', 'Application admin')),
21+
'managed': False,
22+
},
23+
),
24+
]

etsd/core/migrations/__init__.py

Whitespace-only changes.

etsd/core/models.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from __future__ import unicode_literals
2+
from django.db import models
3+
4+
5+
class GlobalPermissionHolder(models.Model):
6+
"A non-managed model to be used as a holder for global permissions"
7+
8+
class Meta:
9+
managed = (
10+
False
11+
) # No database table creation or deletion operations will be performed for this model.
12+
permissions = (("user", "Application user"), ("admin", "Application admin"))

etsd/core/templatetags/__init__.py

Whitespace-only changes.

etsd/core/templatetags/core_tags.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django import template
2+
from django.conf import settings
3+
4+
register = template.Library()
5+
6+
7+
@register.simple_tag
8+
def get_setting_value(value):
9+
return getattr(settings, value)

etsd/core/tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Tests

etsd/core/tests/sample.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from django.test import TestCase
2+
3+
4+
class SampleTestCase(TestCase):
5+
6+
def setUp(self):
7+
self.value = 1
8+
9+
def test_value_is_1(self):
10+
"""Make sure that value is 1"""
11+
self.assertEqual(self.value, 1)
12+
13+
def test_value_is_2(self):
14+
"""Make sure that value is 2"""
15+
self.assertEqual(self.value, 2)

etsd/core/urls.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.urls import path
2+
from django.contrib.auth.views import LoginView, LogoutView
3+
from django.views.generic import TemplateView
4+
5+
urlpatterns = [
6+
path(r"", TemplateView.as_view(template_name="home.html"), name="home"),
7+
path(r"login/", LoginView.as_view(), name="auth_login"),
8+
path(r"logout/", LogoutView.as_view(template_name="logout.html"), name="auth_logout"),
9+
]

etsd/core/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Create your views here.

etsd/settings/__init__.py

Whitespace-only changes.

etsd/settings/base.py

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
"""
2+
Django settings for etsd project.
3+
"""
4+
5+
import os
6+
from django.urls import reverse_lazy
7+
8+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
9+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10+
11+
SECRET_KEY = "7x=ion&zd9%_hqv0)zc^rh6e#p$jw(8m#xqvt_viqb#fqv(n@+"
12+
DEBUG = False
13+
SITE_ID = 3
14+
15+
ALLOWED_HOSTS = []
16+
17+
INSTALLED_APPS = [
18+
"etsd.core",
19+
"etsd.users",
20+
21+
"django.contrib.admin",
22+
"django.contrib.auth",
23+
"django.contrib.contenttypes",
24+
"django.contrib.sessions",
25+
"django.contrib.messages",
26+
"django.contrib.staticfiles",
27+
"django.contrib.sites",
28+
"compressor",
29+
"crispy_forms",
30+
"django_tables2",
31+
"django_tables2_column_shifter",
32+
"django_filters",
33+
"django_extensions",
34+
"reversion",
35+
"widget_tweaks",
36+
]
37+
38+
MIDDLEWARE = [
39+
"django.middleware.security.SecurityMiddleware",
40+
"reversion.middleware.RevisionMiddleware",
41+
"django.contrib.sessions.middleware.SessionMiddleware",
42+
"django.middleware.common.CommonMiddleware",
43+
"django.middleware.csrf.CsrfViewMiddleware",
44+
"django.contrib.auth.middleware.AuthenticationMiddleware",
45+
"django.contrib.messages.middleware.MessageMiddleware",
46+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
47+
]
48+
49+
ROOT_URLCONF = "etsd.urls"
50+
51+
TEMPLATES = [
52+
{
53+
"BACKEND": "django.template.backends.django.DjangoTemplates",
54+
"DIRS": [os.path.join(BASE_DIR, "templates")],
55+
"OPTIONS": {
56+
"context_processors": [
57+
"django.template.context_processors.debug",
58+
"django.template.context_processors.request",
59+
"django.contrib.auth.context_processors.auth",
60+
"django.contrib.messages.context_processors.messages",
61+
"etsd.core.context_processors.default_cp",
62+
],
63+
"loaders": [
64+
(
65+
"django.template.loaders.cached.Loader",
66+
[
67+
"django.template.loaders.filesystem.Loader",
68+
"django.template.loaders.app_directories.Loader",
69+
],
70+
)
71+
],
72+
},
73+
}
74+
]
75+
76+
WSGI_APPLICATION = "etsd.wsgi.application"
77+
78+
DATABASES = {
79+
"default": {
80+
"ENGINE": "django.db.backends.sqlite3",
81+
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
82+
}
83+
}
84+
85+
AUTH_USER_MODEL = 'users.User'
86+
87+
AUTH_PASSWORD_VALIDATORS = [
88+
{
89+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
90+
},
91+
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
92+
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
93+
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
94+
]
95+
96+
LOGIN_REDIRECT_URL = reverse_lazy("home")
97+
LOGIN_URL = "/login/"
98+
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
99+
100+
LANGUAGE_CODE = "el"
101+
TIME_ZONE = "Europe/Athens"
102+
USE_I18N = True
103+
USE_L10N = True
104+
USE_TZ = True
105+
106+
STATIC_ROOT = "/home/serafeim/etsd/static"
107+
STATIC_URL = "/static_etsd/"
108+
MEDIA_URL = "/media_etsd/"
109+
MEDIA_ROOT = "/home/serafeim/etsd/media"
110+
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
111+
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
112+
113+
CACHES = {
114+
"default": {
115+
"BACKEND": "django.core.cache.backends.memcached.MemcachedCache",
116+
"LOCATION": "127.0.0.1:11211",
117+
"KEY_PREFIX": "etsd",
118+
}
119+
}
120+
CACHE_MIDDLEWARE_KEY_PREFIX = "etsd"
121+
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
122+
123+
# SECURITY OPTIONS
124+
SECURE_HSTS_SECONDS = 0
125+
SECURE_CONTENT_TYPE_NOSNIFF = True
126+
SECURE_BROWSER_XSS_FILTER = True
127+
X_FRAME_OPTIONS = "DENY"
128+
SESSION_COOKIE_SECURE = (
129+
True
130+
) # Careful this allows session to work only on HTTPS on production
131+
CSRF_COOKIE_SECURE = (
132+
True
133+
) # Careful this allows CSRF to work only on HTTPS on production
134+
CSRF_COOKIE_HTTPONLY = True
135+
136+
ADMINS = MANAGERS = [("Serafeim Papastefanos", "[email protected]")]
137+
138+
# Default for django-filter
139+
FILTERS_HELP_TEXT_EXCLUDE = True
140+
FILTERS_HELP_TEXT_FILTER = False
141+
142+
# EMAIL cfg
143+
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
144+
EMAIL_HOST = "mail.hcg.gr"
145+
MAIL_PORT = 587
146+
EMAIL_HOST_USER = "[email protected]"
147+
SERVER_EMAIL = "[email protected]"
148+
EMAIL_HOST_PASSWORD = "" # Configure me in local.py
149+
EMAIL_USE_TLS = True
150+
DEFAULT_FROM_EMAIL = "[email protected]"
151+
152+
# crispy forms template pack
153+
CRISPY_TEMPLATE_PACK = "bootstrap4"
154+
155+
from .ldap_conf import *
156+
157+
AUTHENTICATION_BACKENDS = (
158+
"django_auth_ldap.backend.LDAPBackend",
159+
"etsd.core.auth.NoLoginModelBackend",
160+
)

etsd/settings/dev.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from .base import *
2+
3+
DEBUG = True
4+
SITE_ID = 1
5+
6+
CACHES = {
7+
"default": {
8+
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
9+
"LOCATION": "unique-snowflake",
10+
}
11+
}
12+
13+
INSTALLED_APPS += ("debug_toolbar",)
14+
15+
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
16+
SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
17+
18+
TEMPLATES[0]["OPTIONS"]["loaders"] = (
19+
"django.template.loaders.filesystem.Loader",
20+
"django.template.loaders.app_directories.Loader",
21+
)
22+
23+
AUTHENTICATION_BACKENDS += ("django.contrib.auth.backends.ModelBackend",)
24+
25+
CSRF_COOKIE_SECURE = False # Override CSRF to work also with http
26+
SESSION_COOKIE_SECURE = False # Override session to work also with http
27+
INTERNAL_IPS = ["127.0.0.1"]
28+
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]
29+
try:
30+
from .local import *
31+
except ImportError:
32+
pass

etsd/settings/ldap_conf.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ldap
2+
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion
3+
4+
AUTH_LDAP_BIND_DN = ""
5+
AUTH_LDAP_BIND_PASSWORD = ""
6+
AUTH_LDAP_SERVER_URI = "ldap://login1.yen.gr"
7+
AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(
8+
LDAPSearch("ou=People,dc=yen,dc=gr", ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
9+
)
10+
AUTH_LDAP_USER_ATTR_MAP = {
11+
"first_name": "givenName",
12+
"last_name": "sn",
13+
"email": "mail",
14+
}
15+
AUTH_LDAP_PROFILE_ATTR_MAP = {}
16+
AUTH_LDAP_ALWAYS_UPDATE_USER = True

etsd/settings/local.py.template

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Override settings - this is not to be included in the version control
2+
import os
3+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
4+
SECRET_KEY = 'overrideme1298etsd031892jklaksdiasdlkajsdlkasjetsddlkdfgdfg'
5+
6+
DATABASES = {
7+
"default": {
8+
"ENGINE": "django.db.backends.sqlite3",
9+
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
10+
}
11+
}

etsd/settings/prod.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from .base import *
2+
3+
# These should be imprted from from base.py but I'll redefine them for clarity
4+
DEBUG = False
5+
SITE_ID = 1
6+
COMPRESS_OFFLINE = True
7+
8+
9+
10+
import sentry_sdk
11+
from sentry_sdk.integrations.django import DjangoIntegration
12+
13+
sentry_sdk.init(
14+
dsn="https://[email protected]/37",
15+
integrations=[DjangoIntegration()],
16+
)
17+
18+
19+
STATICFILES_FINDERS = (
20+
"django.contrib.staticfiles.finders.FileSystemFinder",
21+
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
22+
"compressor.finders.CompressorFinder",
23+
)
24+
25+
26+
try:
27+
from .local import *
28+
except ImportError:
29+
pass

0 commit comments

Comments
 (0)