Commit e26d998e authored by Florent Chehab's avatar Florent Chehab

more pythonic code

parent 573a4464
......@@ -8,5 +8,6 @@
"**/.DS_Store": true,
"**/__pycache__":true
},
"cSpell.language": "en"
"cSpell.language": "en",
"python.linting.flake8Enabled": true
}
\ No newline at end of file
......@@ -56,22 +56,22 @@ MIDDLEWARE = [
]
LOGIN_URL = 'accounts/login'
# TODO add ignore administration
# TODO add ignore administration
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'django_cas_ng.backends.CASBackend',
]
CAS_SERVER_URL= 'https://cas.utc.fr/cas/'
CAS_SERVER_URL = 'https://cas.utc.fr/cas/'
CAS_APPLY_ATTRIBUTES_TO_USER = True
CAS_RENAME_ATTRIBUTES={
'mail':'email',
'givenName':'first_name',
'sn':'last_name'
CAS_RENAME_ATTRIBUTES = {
'mail': 'email',
'givenName': 'first_name',
'sn': 'last_name'
}
SESSION_EXPIRE_AT_BROWSER_CLOSE=True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
ROOT_URLCONF = 'general.urls'
......@@ -110,16 +110,20 @@ DATABASES = {
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
'NAME': 'django.contrib.auth.password_validation.\
UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'NAME': 'django.contrib.auth.password_validation.\
MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.\
CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.\
NumericPasswordValidator',
},
]
......
......@@ -5,12 +5,17 @@ from django.contrib import admin
import django_cas_ng.views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^accounts/login$', django_cas_ng.views.login, name='cas_ng_login'),
url(r'^accounts/logout$', django_cas_ng.views.logout, name='cas_ng_logout'),
url(r'^accounts/callback$', django_cas_ng.views.callback, name='cas_ng_proxy_callback'),
url(r'^accounts/login$',
django_cas_ng.views.login,
name='cas_ng_login'),
url(r'^accounts/logout$',
django_cas_ng.views.logout,
name='cas_ng_logout'),
url(r'^accounts/callback$',
django_cas_ng.views.callback,
name='cas_ng_proxy_callback'),
url(r'', include('rex.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
......
......@@ -4,5 +4,6 @@ from reversion_compare.admin import CompareVersionAdmin
from rex.models.university import University
from rex.models.country import Country
admin.site.register(University, CompareVersionAdmin)
admin.site.register(Country)
from django.db import models
class Country(models.Model):
name = models.CharField(max_length=200)
iso_code = models.CharField(primary_key = True, max_length=2)
\ No newline at end of file
iso_code = models.CharField(primary_key=True, max_length=2)
\ No newline at end of file
......@@ -6,7 +6,8 @@ from rex.models.country import Country
import reverse_geocoder as rg
path_and_rename = friendly_path("uploads/universities/logos/",'name')
path_and_rename = friendly_path("uploads/universities/logos/", 'name')
class University(models.Model):
"""
......@@ -15,12 +16,13 @@ class University(models.Model):
name = models.CharField(max_length=200)
acronym = models.CharField(max_length=20)
localization_lat = models.DecimalField(
max_digits=10,
max_digits=10,
decimal_places=6,
validators=[MinValueValidator(-85.05112878), MaxValueValidator(85.05112878)]
validators=[MinValueValidator(-85.05112878),
MaxValueValidator(85.05112878)]
)
localization_lon = models.DecimalField(
max_digits=10,
max_digits=10,
decimal_places=6,
validators=[MinValueValidator(-180), MaxValueValidator(180)]
)
......@@ -28,7 +30,7 @@ class University(models.Model):
logo = models.ImageField(upload_to=path_and_rename, max_length=250)
def localization(self):
return {'lat':self.localization_lat, 'lon':self.localization_lon}
return {'lat': self.localization_lat, 'lon': self.localization_lon}
def save(self, *args, **kwargs):
"""
......
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.home, name='home'),
]
\ No newline at end of file
from django.conf import settings
from django.utils.deconstruct import deconstructible
import os
@deconstructible
class friendly_path(object):
"""
class to generate file path with filenames
according to one of the model attribute
"""
def __init__(self, rel_path, attribute_distinction):
self.rel_path = rel_path
self.attr = attribute_distinction
......@@ -14,8 +17,10 @@ class friendly_path(object):
ext = filename.split('.')[-1]
i = 0
while True:
filename = '{}_{}.{}'.format(getattr(instance, self.attr), str(i), ext)
path_and_fn = os.path.join(settings.MEDIA_ROOT, self.rel_path, filename)
filename = '{}_{}.{}'.format(
getattr(instance, self.attr), str(i), ext)
path_and_fn = os.path.join(
settings.MEDIA_ROOT, self.rel_path, filename)
if not os.path.isfile(path_and_fn):
break
i += 1
......
......@@ -5,13 +5,13 @@ Script to insert the country data in the database
IT HAS TO BE RUN INSIDE ./manage.py shell
"""
import csv
import os
from rex.models.country import Country
tmp = os.path.join(os.path.realpath(__file__),'../../assets/country.csv')
tmp = os.path.join(os.path.realpath(__file__), '../../assets/country.csv')
country_file_loc = os.path.abspath(tmp)
if not os.path.isfile(country_file_loc):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment