Skip to content

Commit 786fbfe

Browse files
committed
Merge branch 'develop' of github.com:akbargumbira/django-user-map
2 parents 486f82e + fa16f72 commit 786fbfe

Some content is hidden

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

59 files changed

+1410
-2073
lines changed

README.md

Lines changed: 287 additions & 153 deletions
Large diffs are not rendered by default.

docs/img/with_nav.png

564 KB
Loading

docs/img/without_nav.png

607 KB
Loading

requirements.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
Django==1.7
2-
django-leaflet==0.14.1
3-
psycopg2==2.5.4
4-
factory-boy==2.4.1
5-
django-bootstrap-form==3.1
1+
Django>=1.8
2+
django-leaflet==0.18.0
3+
psycopg2==2.6.1
4+
factory-boy==2.6.0
5+
django-bootstrap-form==3.2
6+
djangorestframework==3.3.2
7+
djangorestframework-gis==0.10.1
8+
Pillow==3.1.1

setup.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='django-user-map',
13-
version='0.1.2',
13+
version='1.0.0',
1414
author='Akbar Gumbira',
1515
author_email='akbargumbira@gmail.com',
1616
packages=find_packages(),
@@ -23,11 +23,16 @@
2323
'django web site.'),
2424
long_description=open('README.md').read(),
2525
install_requires=[
26-
"Django==1.7",
27-
"django-leaflet==0.14.1",
28-
"psycopg2==2.5.4",
29-
"factory-boy==2.4.1",
30-
"django-bootstrap-form==3.1",
26+
"Django>=1.8",
27+
"django-leaflet",
28+
"psycopg2",
29+
"django-bootstrap-form",
30+
"djangorestframework",
31+
"djangorestframework-gis",
32+
"Pillow"
33+
],
34+
tests_require=[
35+
"factory-boy>=2.4.1",
3136
],
3237
test_suite='user_map.run_tests.run',
3338
)

user_map/admin.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,16 @@
22
"""Model Admin Class."""
33

44
from django.contrib.gis import admin
5-
from leaflet.admin import LeafletGeoAdmin
65

7-
from user_map.models import User, Role
6+
from leaflet.admin import LeafletGeoAdmin
87

8+
from user_map.models import UserMap, Role
99

10-
class UserAdmin(LeafletGeoAdmin):
11-
"""Admin Class for User Model."""
12-
list_display = ('name', 'email', 'role', 'website', 'email_updates',
13-
'last_login', 'is_confirmed', 'is_admin')
14-
list_filter = ['role', 'is_confirmed', 'is_admin']
15-
search_fields = ['name', 'email']
16-
fieldsets = [
17-
('Basic Information', {
18-
'fields': [
19-
'name', 'email', 'website', 'role', 'email_updates']}),
20-
('Location', {'fields': ['location']}),
21-
('Advanced Information', {
22-
'fields': ['is_confirmed', 'is_active', 'is_admin', 'last_login']
23-
}),
24-
]
2510

11+
class UserMapAdmin(LeafletGeoAdmin):
12+
"""Admin Class for User Map Model."""
13+
model = UserMap
14+
can_delete = False
2615

27-
admin.site.register(User, UserAdmin)
16+
admin.site.register(UserMap, UserMapAdmin)
2817
admin.site.register(Role)

user_map/app_settings.py

Lines changed: 91 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,100 @@
44
..note: By design, you can override these settings from your project's
55
settings.py with prefix 'USER_MAP' on the variable e.g
66
'USER_MAP_USER_ICONS'.
7-
8-
For mailing. as the default, it wil use 'DEFAULT_FROM_MAIL' setting from
9-
the project.
107
"""
118
from django.conf import settings
129

13-
# PROJECT_NAME: The project name for this apps e.g InaSAFE
14-
default_project_name = 'InaSAFE'
15-
PROJECT_NAME = getattr(settings, 'USER_MAP_PROJECT_NAME', default_project_name)
1610

17-
# LOGO/BRAND
18-
default_brand_logo = 'user_map/img/logo.png'
19-
BRAND_LOGO = getattr(settings, 'USER_MAP_BRAND_LOGO', default_brand_logo)
11+
# USER_MODEL: The auth user model is set in project's settings
12+
USER_MODEL = settings.AUTH_USER_MODEL
13+
14+
# USER MAP Settings
15+
default_setting = {
16+
'project_name': 'Django',
17+
'favicon_file': '',
18+
'login_view': 'django.contrib.auth.views.login',
19+
'marker': {
20+
# See leaflet icon valid options here:
21+
# http://leafletjs.com /reference.html#icon-iconurl
22+
'iconUrl': 'static/user_map/img/user-icon.png',
23+
'shadowUrl': 'static/user_map/img/shadow-icon.png',
24+
'iconSize': [19, 32],
25+
'shadowSize': [42, 35],
26+
'iconAnchor': [10, 0],
27+
'shadowAnchor': [12, 0],
28+
},
29+
'leaflet_config': {
30+
'TILES': [(
31+
# The title
32+
'MapQuest',
33+
# Tile's URL
34+
'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
35+
# More valid leaflet option are passed here
36+
# See here: http://leafletjs.com/reference.html#tilelayer
37+
{
38+
'attribution':
39+
'© <a href="http://www.openstreetmap.org" '
40+
'target="_parent">OpenStreetMap'
41+
'</a> and contributors, under an <a '
42+
'href="http://www.openstreetmap.org/copyright" '
43+
'target="_parent">open license</a>. Tiles Courtesy of '
44+
'<a '
45+
'href="http://www.mapquest.com/">MapQuest</a> <img '
46+
'src="http://developer.mapquest.com/content/osm/mq_logo'
47+
'.png"',
48+
'subdomains': '1234'
49+
50+
}
51+
)]
52+
},
53+
'roles': [
54+
{
55+
'id': 1,
56+
'name': 'Django User',
57+
'badge': 'user_map/img/badge-user.png'
58+
},
59+
{
60+
'id': 2,
61+
'name': 'Django Trainer',
62+
'badge': 'user_map/img/badge-trainer.png'
63+
},
64+
{
65+
'id': 3,
66+
'name': 'Django Developer',
67+
'badge': 'user_map/img/badge-developer.png'
68+
}
69+
],
70+
'api_user_fields': [
71+
# e.g 'username', 'first_name', 'last_name'
72+
],
73+
}
74+
75+
user_map_settings = getattr(settings, 'USER_MAP', default_setting)
76+
77+
# PROJECT_NAME: The project name for this apps e.g InaSAFE
78+
PROJECT_NAME = user_map_settings.get(
79+
'project_name', default_setting['project_name'])
2080

2181
# FAVICON_FILE: Favicon for this apps
22-
default_favicon_file = 'user_map/img/user-icon.png'
23-
FAVICON_FILE = getattr(settings, 'USER_MAP_FAVICON_FILE', default_favicon_file)
24-
25-
# USER ROLES: All user roles and their icons
26-
default_user_roles = [
27-
dict(
28-
name='User',
29-
icon='user_map/img/user-icon.png',
30-
shadow_icon='user_map/img/shadow-icon.png'),
31-
dict(
32-
name='Trainer',
33-
icon='user_map/img/trainer-icon.png',
34-
shadow_icon='user_map/img/shadow-icon.png'),
35-
dict(
36-
name='Developer',
37-
icon='user_map/img/developer-icon.png',
38-
shadow_icon='user_map/img/shadow-icon.png')]
39-
USER_ROLES = getattr(settings, 'USER_MAP_USER_ROLES', default_user_roles)
40-
41-
# MAIL SENDER
42-
default_mail_sender = 'noreply@inasafe.org'
43-
DEFAULT_FROM_MAIL = getattr(settings, 'DEFAULT_FROM_MAIL', default_mail_sender)
44-
45-
# LEAFLET CONFIG
46-
default_leaflet_tiles = (
47-
'OpenStreetMap',
48-
'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
49-
('© <a href="http://www.openstreetmap.org" target="_parent">OpenStreetMap'
50-
'</a> and contributors, under an <a '
51-
'href="http://www.openstreetmap.org/copyright" target="_parent">open '
52-
'license</a>')
53-
)
54-
LEAFLET_TILES = getattr(settings, 'LEAFLET_TILES', default_leaflet_tiles)
82+
FAVICON_FILE = user_map_settings.get(
83+
'favicon_file', default_setting['favicon_file'])
84+
85+
86+
# LOGIN_VIEW: The view to the login page
87+
LOGIN_VIEW = user_map_settings.get(
88+
'login_view', default_setting['login_view'])
89+
90+
# MARKER
91+
MARKER = user_map_settings.get(
92+
'marker', default_setting['marker'])
93+
94+
LEAFLET_CONFIG = user_map_settings.get(
95+
'leaflet_config', default_setting['leaflet_config'])
96+
LEAFLET_TILES = LEAFLET_CONFIG['TILES']
97+
98+
# ROLES: All user roles and their badges
99+
ROLES = user_map_settings.get('roles', default_setting['roles'])
100+
101+
# API_USER_FIELDS
102+
API_USER_FIELDS = user_map_settings.get(
103+
'api_user_fields', default_setting['api_user_fields'])

user_map/auth_backend.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

user_map/context_processors.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

user_map/forms/custom_widget.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from django.utils.safestring import mark_safe
2+
from django.utils.html import escape, conditional_escape
3+
from django.utils.encoding import force_unicode
4+
from django.forms.widgets import ClearableFileInput, Input, CheckboxInput
5+
6+
7+
class CustomClearableFileInput(ClearableFileInput):
8+
"""A custom ClearableFileInput widget.
9+
10+
..note:: Adapted from django.forms.widgets.ClearableFileInput and also
11+
utilising img-responsive bootstrap class.
12+
"""
13+
def render(self, name, value, attrs=None):
14+
"""Render the custom widget."""
15+
substitutions = {
16+
'input_text': self.input_text,
17+
'clear_template': '',
18+
'clear_checkbox_label': self.clear_checkbox_label,
19+
}
20+
template = '%(input)s'
21+
substitutions['input'] = Input.render(self, name, value, attrs)
22+
23+
if value and hasattr(value, "url"):
24+
template = ('%(initial)s %(clear_template)s<br />%(input_text)s: '
25+
'%(input)s')
26+
substitutions['initial'] = (
27+
'<img class="img-responsive" src="%s" alt="%s"/>' % (
28+
escape(value.url), escape(force_unicode(value))))
29+
if not self.is_required:
30+
checkbox_name = self.clear_checkbox_name(name)
31+
checkbox_id = self.clear_checkbox_id(checkbox_name)
32+
substitutions['clear_checkbox_name'] = conditional_escape(
33+
checkbox_name)
34+
substitutions['clear_checkbox_id'] = conditional_escape(
35+
checkbox_id)
36+
substitutions['clear'] = CheckboxInput().render(
37+
checkbox_name, False, attrs={'id': checkbox_id})
38+
substitutions['clear_template'] = \
39+
self.template_with_clear % substitutions
40+
return mark_safe(template % substitutions)

0 commit comments

Comments
 (0)