Add LDAP auth, images support
This commit is contained in:
parent
8b539e5926
commit
12a01f5a0a
|
@ -2,6 +2,8 @@ FROM python:3.5
|
||||||
ENV PYTHONUNBUFFERED 1
|
ENV PYTHONUNBUFFERED 1
|
||||||
RUN mkdir /code
|
RUN mkdir /code
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
|
RUN apt-get -y update
|
||||||
|
RUN apt-get -y install libsasl2-dev libldap2-dev libssl-dev
|
||||||
ADD requirements.txt /code/
|
ADD requirements.txt /code/
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
ADD . /code/
|
ADD . /code/
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
Django==1.10.1
|
Django==1.10.1
|
||||||
git+https://github.com/djangonauts/django-hstore@61427e474cb2f4be8fdfce225d78a5330bc77eb0#egg=django-hstore
|
git+https://github.com/djangonauts/django-hstore@61427e474cb2f4be8fdfce225d78a5330bc77eb0#egg=django-hstore
|
||||||
django-appconf==1.0.2
|
django-appconf==1.0.2
|
||||||
|
django-auth-ldap==1.2.9
|
||||||
Django-Select2==5.8.10
|
Django-Select2==5.8.10
|
||||||
Pillow==3.3.1
|
Pillow==3.3.1
|
||||||
psycopg2==2.6.2
|
psycopg2==2.6.2
|
||||||
|
|
|
@ -109,6 +109,41 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
import ldap
|
||||||
|
from django_auth_ldap.config import LDAPSearch, GroupOfUniqueNamesType
|
||||||
|
|
||||||
|
AUTHENTICATION_BACKENDS = (
|
||||||
|
'django_auth_ldap.backend.LDAPBackend',
|
||||||
|
'django.contrib.auth.backends.ModelBackend',
|
||||||
|
)
|
||||||
|
|
||||||
|
AUTH_LDAP_SERVER_URI = "ldaps://ldap.hackerspace.pl"
|
||||||
|
AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=People,dc=hackerspace,dc=pl"
|
||||||
|
AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True
|
||||||
|
|
||||||
|
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
|
||||||
|
"is_active": "cn=staff,ou=Group,dc=hackerspace,dc=pl",
|
||||||
|
"is_superuser": "cn=staff,ou=Group,dc=hackerspace,dc=pl",
|
||||||
|
"is_staff": "cn=staff,ou=Group,dc=hackerspace,dc=pl",
|
||||||
|
}
|
||||||
|
|
||||||
|
# Populate the Django user from the LDAP directory.
|
||||||
|
AUTH_LDAP_USER_ATTR_MAP = {
|
||||||
|
"first_name": "givenName",
|
||||||
|
"last_name": "sn",
|
||||||
|
"email": "mail"
|
||||||
|
}
|
||||||
|
|
||||||
|
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=Group,dc=hackerspace,dc=pl",
|
||||||
|
ldap.SCOPE_SUBTREE, "(objectClass=groupOfUniqueNames)"
|
||||||
|
)
|
||||||
|
AUTH_LDAP_GROUP_TYPE = GroupOfUniqueNamesType(name_attr="cn")
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger('django_auth_ldap')
|
||||||
|
logger.addHandler(logging.StreamHandler())
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/1.10/topics/i18n/
|
# https://docs.djangoproject.com/en/1.10/topics/i18n/
|
||||||
|
@ -132,3 +167,6 @@ STATIC_URL = '/static/'
|
||||||
STATICFILES_DIRS = [
|
STATICFILES_DIRS = [
|
||||||
os.path.join(BASE_DIR, "static"),
|
os.path.join(BASE_DIR, "static"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
MEDIA_URL = '/media/'
|
||||||
|
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
||||||
|
|
|
@ -14,4 +14,6 @@ urlpatterns = [
|
||||||
url(r'^select2/', include('django_select2.urls')),
|
url(r'^select2/', include('django_select2.urls')),
|
||||||
|
|
||||||
url(r'^', include('storage.urls')),
|
url(r'^', include('storage.urls')),
|
||||||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
] \
|
||||||
|
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \
|
||||||
|
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|
|
@ -20,10 +20,11 @@ class ItemImageInline(admin.TabularInline):
|
||||||
extra = 1
|
extra = 1
|
||||||
|
|
||||||
class ItemAdmin(admin.ModelAdmin):
|
class ItemAdmin(admin.ModelAdmin):
|
||||||
list_display = ('_name', 'uuid', 'props', 'path')
|
list_display = ('_name',)
|
||||||
list_filter = ('categories',)
|
list_filter = ('categories',)
|
||||||
form = ItemForm
|
form = ItemForm
|
||||||
inlines = [ItemImageInline]
|
inlines = [ItemImageInline]
|
||||||
|
save_on_top = True
|
||||||
|
|
||||||
def _name(self, obj):
|
def _name(self, obj):
|
||||||
return '-' * obj.get_level() + '> ' + obj.name
|
return '-' * obj.get_level() + '> ' + obj.name
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
{% extends "admin/change_form.html" %}
|
{% extends "admin/change_form.html" %}
|
||||||
|
|
||||||
|
{% block submit_buttons_top %}
|
||||||
|
{# We want add another to be default submit action #}
|
||||||
|
<input type="submit" value="Save" class="hidden" name="_addanother" />
|
||||||
|
{{ block.super }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block submit_buttons_bottom %}
|
{% block submit_buttons_bottom %}
|
||||||
{# We want add another to be default submit action #}
|
{# We want add another to be default submit action #}
|
||||||
<input type="submit" value="Save" class="hidden" name="_addanother" />
|
<input type="submit" value="Save" class="hidden" name="_addanother" />
|
||||||
|
|
|
@ -8,10 +8,13 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li class="active">{{ item.name }}</li>
|
<li class="active">{{ item.name }}</li>
|
||||||
</ol>
|
</ol>
|
||||||
<h2>{{ item.name }} <small>{{ item.pk }}</small></h2>
|
<h2>
|
||||||
|
<small class="pull-right"><a href="{% url 'admin:storage_item_change' item.pk %}"><span class="glyphicon glyphicon-pencil"></span></a></small>
|
||||||
|
{{ item.name }} <small>{{ item.pk }}</small>
|
||||||
|
</h2>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
{% if item.props %}
|
<h3>Properties</h3>
|
||||||
<table class="table table-hover table-striped">
|
<table class="table table-hover table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -20,19 +23,37 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% for k, v in item.props.items %}
|
{% for k, v in item.props.items %}
|
||||||
<tr><td>{{ k }}</td><td>{{ v }}</td></tr>
|
<tr><td>{{ k }}</td><td>{{ v|urlize }}</td></tr>
|
||||||
|
{% empty %}
|
||||||
|
<tr><td colspan=2>No properties</td></tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
{% if images %}
|
||||||
|
<h3>Photos</h3>
|
||||||
|
<div class="row">
|
||||||
|
{% for image in images %}
|
||||||
|
<div class="col-md-6">
|
||||||
|
<a href="{{ image.image.url }}">
|
||||||
|
<img src="{{ image.image.url }}" class="img-responsive img-thumbnail" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{% if children %}
|
<div class="col-md-8">
|
||||||
<h3>Children</h3>
|
{{ item.description|urlize }}
|
||||||
<table class="table table-striped table-hover">
|
|
||||||
{% for child in children %}
|
<h3>Children</h3>
|
||||||
<tr><td><a href="{{ child.get_absolute_url }}">{{ child.name }}</a></td></tr>
|
<table class="table table-striped table-hover">
|
||||||
{% endfor %}
|
{% for child in children %}
|
||||||
</table>
|
<tr><td><a href="{{ child.get_absolute_url }}">{{ child.name }}</a></td></tr>
|
||||||
{% endif %}
|
{% empty %}
|
||||||
|
<tr><td colspan=2>No children</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -60,6 +60,7 @@ def item_display(request, pk):
|
||||||
|
|
||||||
return render(request, 'item.html', {
|
return render(request, 'item.html', {
|
||||||
'item': item,
|
'item': item,
|
||||||
|
'images': item.images.all(),
|
||||||
'ancestors': item.get_ancestors(),
|
'ancestors': item.get_ancestors(),
|
||||||
'children': item.get_children(),
|
'children': item.get_children(),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue