Commit 13903329 authored by Florent Chehab's avatar Florent Chehab

linting

parent debe4c07
[flake8]
# E501 line too long
ignore = E501
exclude = tests/*
\ No newline at end of file
......@@ -15,6 +15,13 @@ testing:
tags:
- docker
flake8:
stage: test
script:
- flake8
tags:
- docker
pages:
stage: deploy
dependencies:
......
......@@ -8,6 +8,7 @@ EXEMPT_URLS = [compile(settings.LOGIN_URL.lstrip('/'))]
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
EXEMPT_URLS += [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
class LoginRequiredMiddleware(MiddlewareMixin):
"""
Middleware that requires a user to be authenticated to view any page other
......@@ -19,7 +20,6 @@ class LoginRequiredMiddleware(MiddlewareMixin):
loaded. You'll get an error if they aren't.
"""
def process_request(self, request):
assert hasattr(request, 'user'), "The Login Required middleware\
requires authentication middleware to be installed. Edit your\
......@@ -30,4 +30,4 @@ class LoginRequiredMiddleware(MiddlewareMixin):
if not request.user.is_authenticated:
path = request.path_info.lstrip('/')
if not any(m.match(path) for m in EXEMPT_URLS):
return HttpResponseRedirect(settings.LOGIN_URL)
\ No newline at end of file
return HttpResponseRedirect(settings.LOGIN_URL)
......@@ -61,7 +61,7 @@ LOGIN_URL = 'accounts/login'
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'django_cas_ng.backends.CASBackend',
]
]
CAS_SERVER_URL = 'https://cas.utc.fr/cas/'
CAS_APPLY_ATTRIBUTES_TO_USER = True
......
......@@ -7,17 +7,14 @@ import django_cas_ng.views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^accounts/login$',
django_cas_ng.views.login,
url(r'^accounts/login$',
django_cas_ng.views.login,
name='cas_ng_login'),
url(r'^accounts/logout$',
django_cas_ng.views.logout,
url(r'^accounts/logout$',
django_cas_ng.views.logout,
name='cas_ng_logout'),
url(r'^accounts/callback$',
django_cas_ng.views.callback,
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)
from django.contrib import admin
# Register your models here.
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
......@@ -6,4 +6,5 @@ django-imagekit==4.0.2
django-reversion==2.0.13
django-reversion-compare==0.8.4
reverse-geocoder==1.5.1
coverage==4.5.1
\ No newline at end of file
coverage==4.5.1
flake8
\ No newline at end of file
from .country import country
from .university import university
\ No newline at end of file
from .country import country # noqa: F401
from .university import university # noqa: F401
from .country import Country
\ No newline at end of file
from .country import Country # noqa: F401
......@@ -3,4 +3,4 @@ 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)
from .university import University
\ No newline at end of file
from .university import University # noqa: F401
......@@ -18,27 +18,27 @@ class University(models.Model):
localization_lat = models.DecimalField(
max_digits=10,
decimal_places=6,
validators=[MinValueValidator(-85.05112878),
validators=[MinValueValidator(-85.05112878),
MaxValueValidator(85.05112878)]
)
)
localization_lon = models.DecimalField(
max_digits=10,
decimal_places=6,
validators=[MinValueValidator(-180), MaxValueValidator(180)]
)
)
country = models.ForeignKey(Country, on_delete='CASCADE')
logo = models.ImageField(upload_to=path_and_rename, max_length=250,
default='path/to/my/default/image.jpg') # TODO CHANGE !
logo = models.ImageField(upload_to=path_and_rename, max_length=250,
default='path/to/my/default/image.jpg') # TODO CHANGE !
def localization(self):
return {'lat': self.localization_lat, 'lon': self.localization_lon}
def save(self, *args, **kwargs):
"""
Override traditional save function to make sure that
Override traditional save function to make sure that
the Country is coherent with given lat / lon
"""
coord = (self.localization_lat, self.localization_lon)
res = rg.search(coord, verbose=False)
self.country = Country.objects.get(pk=res[0]['cc'])
super(University, self).save(*args, **kwargs)
\ No newline at end of file
super(University, self).save(*args, **kwargs)
from django.test import TestCase
# from django.test import TestCase
# Create your tests here.
......@@ -4,4 +4,4 @@ from . import views
urlpatterns = [
url(r'^$', views.home, name='home'),
]
\ No newline at end of file
]
......@@ -5,7 +5,7 @@ Script to insert the country data in the database
IT HAS TO BE RUN INSIDE ./manage.py shell
"""
import csv
import csv
import os
import time
from geopy.geocoders import Nominatim
......@@ -13,7 +13,8 @@ from geopy.geocoders import Nominatim
tmp = os.path.join(os.path.realpath(__file__), '../../assets/destinations.csv')
destinations_path = os.path.abspath(tmp)
tmp = os.path.join(os.path.realpath(__file__), '../../assets/destinations_extracted.csv')
tmp = os.path.join(os.path.realpath(__file__),
'../../assets/destinations_extracted.csv')
destinations_extracted_path = os.path.abspath(tmp)
if not os.path.isfile(destinations_path):
......@@ -36,25 +37,21 @@ with open(destinations_path, 'rt') as input:
spamwriter.writerow(header)
i += 1
else:
query = row[2]#+ ', ' + row[1] + ', ' + row[0]
query = row[2] # + ', ' + row[1] + ', ' + row[0]
while True:
try:
location = geolocator.geocode(query)
break
except:
except: # noqa: E722
print("error during query, retrying")
time.sleep(1)
print(location)
if location is not None:
spamwriter.writerow([row[2], location.latitude, location.longitude])
spamwriter.writerow(
[row[2], location.latitude, location.longitude])
else:
failed.append(query)
print(failed)
print(failed)
......@@ -9,6 +9,7 @@ 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
......@@ -24,6 +25,5 @@ class friendly_path(object):
if not os.path.isfile(path_and_fn):
break
i += 1
return os.path.join(self.rel_path, filename)
return os.path.join(self.rel_path, filename)
......@@ -5,11 +5,11 @@ Script to insert the country data in the database
IT HAS TO BE RUN INSIDE ./manage.py shell
"""
import csv
import csv
import os
from rex.models.country import Country
from rex.models.country import Country
tmp = os.path.join(os.path.realpath(__file__), '../../assets/country.csv')
country_file_loc = os.path.abspath(tmp)
......
......@@ -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 csv
import os
from rex.models.country import Country
from rex.models.university import University
from rex.models.university import University
tmp = os.path.join(os.path.realpath(__file__), '../../assets/destinations_extracted.csv')
tmp = os.path.join(os.path.realpath(__file__),
'../../assets/destinations_extracted.csv')
destinations_path = os.path.abspath(tmp)
if not os.path.isfile(destinations_path):
......@@ -21,9 +21,8 @@ if not os.path.isfile(destinations_path):
with open(destinations_path, 'rt') as f:
reader = csv.reader(f)
# will be changed during university.save
# dumb_country = Country.objects.get(pk='FR')
for row in reader:
if row[0] != 'University':
u = University(name=row[0], acronym='NULL', localization_lat=float(row[1]), localization_lon=float(row[2]))
u = University(name=row[0], acronym='NULL', localization_lat=float(
row[1]), localization_lon=float(row[2]))
u.save()
from django.shortcuts import render
from django.utils import timezone
from rex.models.university import University
def home(request):
universities = University.objects.all()
return render(request, 'rex/home.html', {'universities': universities})
\ No newline at end of file
return render(request, 'rex/home.html', {'universities': universities})
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