|
1 | | -inasafe-user-map |
2 | | -================ |
| 1 | +Django User Map |
| 2 | +================= |
3 | 3 |
|
4 | | -A django application for our user's map |
| 4 | +[](https://travis-ci.org/AIFDR/inasafe-user-map) |
| 5 | +[](https://coveralls.io/r/AIFDR/inasafe-user-map?branch=develop) |
5 | 6 |
|
6 | | -This project replaces the simple flask based user map available here: |
| 7 | +A django application for making community user's map. Users can |
| 8 | +add themselves on the map by providing some information: |
| 9 | + |
| 10 | +1. Name |
| 11 | +2. E-mail - will be used for authentication |
| 12 | +3. Password - will be used for authentication |
| 13 | +4. Website |
| 14 | +5. Role - The choices can be configured through setting. |
| 15 | +6. Location on the map |
| 16 | + |
| 17 | +Live site: http://users.inasafe.org |
| 18 | + |
| 19 | +Installation |
| 20 | +============ |
| 21 | +1. Install django-user-map with pip: |
| 22 | + ``` |
| 23 | + pip install django-user-map |
| 24 | + ``` |
| 25 | + |
| 26 | +2. Make sure you have all of these items in INSTALLED_APPS of your django |
| 27 | + project settings.py: |
| 28 | + ``` |
| 29 | + INSTALLED_APPS = ( |
| 30 | + 'django.contrib.admin', |
| 31 | + 'django.contrib.auth', |
| 32 | + 'django.contrib.contenttypes', |
| 33 | + 'django.contrib.sessions', |
| 34 | + 'django.contrib.messages', |
| 35 | + 'django.contrib.staticfiles', |
| 36 | + 'django.contrib.gis', |
| 37 | + 'user_map', |
| 38 | + 'leaflet', |
| 39 | + 'bootstrapform' |
| 40 | + ) |
| 41 | + ``` |
| 42 | + |
| 43 | +3. Include user-map URLconf in your project urls.py e.g: |
| 44 | + ``` |
| 45 | + url(r'^user-map/', include('user_map.urls')), |
| 46 | + ``` |
| 47 | + |
| 48 | +3. Add authentication user model and authentication backend in your django |
| 49 | + project settings.py: |
| 50 | + ``` |
| 51 | + AUTH_USER_MODEL = 'user_map.User' |
| 52 | + AUTHENTICATION_BACKENDS = [ |
| 53 | + 'user_map.auth_backend.UserMapAuthBackend', |
| 54 | + 'django.contrib.auth.backends.ModelBackend'] |
| 55 | + ``` |
| 56 | + |
| 57 | +4. Make sure to add template context processors needed by user-map: |
| 58 | + ``` |
| 59 | + TEMPLATE_CONTEXT_PROCESSORS = ( |
| 60 | + 'django.contrib.auth.context_processors.auth', |
| 61 | + 'django.core.context_processors.request', |
| 62 | + 'django.contrib.messages.context_processors.messages', |
| 63 | + 'user_map.context_processors.user_map_settings', |
| 64 | + ) |
| 65 | + ``` |
| 66 | + |
| 67 | +5. Make sure to add mail server configuration on your project's settings.py |
| 68 | + so that this apps can send e-mail for some routines e.g sending confirmation |
| 69 | + e-mail after registration. If you are going to use SMTP server using your |
| 70 | + Gmail account, the configuration looks like this: |
| 71 | + ``` |
| 72 | + EMAIL_USE_TLS = True |
| 73 | + EMAIL_HOST = 'smtp.gmail.com' |
| 74 | + EMAIL_PORT = 587 |
| 75 | + EMAIL_HOST_USER = 'YOUR GMAIL ADDRESS' |
| 76 | + EMAIL_HOST_PASSWORD = 'YOUR GMAIL PASSWORD' |
| 77 | + DEFAULT_FROM_MAIL = 'MAIL ADDRESS AS THE DEFAULT SENDER' |
| 78 | + ``` |
| 79 | +
|
| 80 | +6. Run ```python manage.py migrate``` to create the user_map models. |
| 81 | +
|
| 82 | +7. Create a superuser so that you can log in to django admin to administer |
| 83 | +user: |
| 84 | + ```python manage.py createsuperuser``` |
| 85 | +
|
| 86 | +7. Run ```python manage.py runserver``` to start the development server. |
| 87 | +
|
| 88 | +8. Visit http://127.0.0.1:8000/user-map/ to open the apps. |
| 89 | +
|
| 90 | +9. Visit your admin page (the default is http://127.0.0.1:8000/admin) to |
| 91 | +manage user as an admin. |
| 92 | +
|
| 93 | +
|
| 94 | +Apps Configurations |
| 95 | +================== |
| 96 | +
|
| 97 | +Tile Layer |
| 98 | +------------ |
| 99 | +
|
| 100 | +You can configure the basemap of the form that uses LeafletWidget and the |
| 101 | +basemap of the homepage by adding 'LEAFLET_CONFIG' in settings.py e.g: |
| 102 | +``` |
| 103 | +LEAFLET_CONFIG = { |
| 104 | + 'TILES': [ |
| 105 | + ( |
| 106 | + 'OpenStreetMap', # The title |
| 107 | + 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', # The tile URL |
| 108 | + ('© <a href="http://www.openstreetmap.org" ' |
| 109 | + 'target="_parent">OpenStreetMap</a> and contributors, under an ' |
| 110 | + '<a href="http://www.openstreetmap.org/copyright" ' |
| 111 | + 'target="_parent">open license</a>') # The attribution |
| 112 | + )] |
| 113 | +} |
| 114 | +``` |
| 115 | +
|
| 116 | +Configurable variables |
| 117 | +---------------------- |
| 118 | +
|
| 119 | +You can also configure some variables by adding these items on your |
| 120 | +django settings.py: |
| 121 | +
|
| 122 | +1. USER_MAP_PROJECT_NAME (string). This variable represents the project name of |
| 123 | + the apps. If this is not specified, 'InaSAFE' will be used. |
| 124 | + |
| 125 | +2. USER_MAP_BRAND_LOGO (string). This variable represents the file path to |
| 126 | + the brand logo in navigation bar. If not specified, |
| 127 | + 'user_map/img/logo.png' will be used. |
| 128 | + |
| 129 | +3. USER_MAP_FAVICON_FILE (string). This variable represents the file path to |
| 130 | + the favicon on the browser's tab. If not specified, |
| 131 | + the default is 'user_map/img/user-icon.png' |
| 132 | + |
| 133 | +4. USER_MAP_USER_ROLES (list of dictionary). Using this variable, |
| 134 | + you can specify the user's role and the icon path for the role. If not |
| 135 | + specified, this variable will take this as the default: |
| 136 | + ``` |
| 137 | + default_user_roles = [ |
| 138 | + dict( |
| 139 | + name='User', |
| 140 | + icon='user_map/img/user-icon.png', |
| 141 | + shadow_icon='user_map/img/shadow-icon.png'), |
| 142 | + dict( |
| 143 | + name='Trainer', |
| 144 | + icon='user_map/img/trainer-icon.png', |
| 145 | + shadow_icon='user_map/img/shadow-icon.png'), |
| 146 | + dict( |
| 147 | + name='Developer', |
| 148 | + icon='user_map/img/developer-icon.png', |
| 149 | + shadow_icon='user_map/img/shadow-icon.png')] |
| 150 | + ``` |
| 151 | + While you can add as many roles as you want, note that we only create |
| 152 | + three css classes for the marker clusterer (it makes clusters of users |
| 153 | + based on the role). If you want to have more than three roles, |
| 154 | + you need to add these two classes with this pattern: |
| 155 | + ``` |
| 156 | + .marker-cluster-role4 { |
| 157 | + background-color: rgba(253, 156, 115, 0.6); |
| 158 | + } |
| 159 | + .marker-cluster-role4 div { |
| 160 | + background-color: rgba(241, 128, 23, 0.6); |
| 161 | + } |
| 162 | + ``` |
| 163 | +
|
| 164 | +
|
| 165 | +Testing |
| 166 | +-------- |
| 167 | +
|
| 168 | +You can run the test suite by using django manage.py from your django project: |
| 169 | +``` |
| 170 | +python manage.py test user_map |
| 171 | +``` |
| 172 | +
|
| 173 | +or you can do it from the root of this django apps by running: |
| 174 | +``` |
| 175 | +python setup.py test |
| 176 | +``` |
7 | 177 |
|
8 | | -https://github.com/timlinux/flask_user_map |
|
0 commit comments