Skip to content

Commit 71a588a

Browse files
committed
Merge pull request #10 from akbargumbira/members.python.or.id
@kriwil done @akbargumbira can you try your write access now? Sorry been busy lately in the real life.
2 parents dbbe728 + 5e17d07 commit 71a588a

19 files changed

Lines changed: 45 additions & 331 deletions

users/__init__.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def add_handler_once(logger, handler):
3333
:rtype bool: bool
3434
"""
3535
class_name = handler.__class__.__name__
36-
for handler in logger.handlers:
37-
if handler.__class__.__name__ == class_name:
36+
for logger_handler in logger.handlers:
37+
if logger_handler.__class__.__name__ == class_name:
3838
return False
3939

4040
logger.addHandler(handler)
@@ -62,24 +62,6 @@ def setup_logger():
6262
console_handler = logging.StreamHandler()
6363
console_handler.setLevel(logging.ERROR)
6464

65-
try:
66-
#pylint: disable=F0401
67-
from raven.handlers.logging import SentryHandler
68-
# noinspection PyUnresolvedReferences
69-
from raven import Client
70-
#pylint: enable=F0401
71-
client = Client(
72-
'http://12ef42a1d4394255a2041ac0428e8ef7:'
73-
'755880e336f54892bc2a65d308019997@sentry.linfiniti.com/6')
74-
sentry_handler = SentryHandler(client)
75-
sentry_handler.setFormatter(formatter)
76-
sentry_handler.setLevel(logging.ERROR)
77-
add_handler_once(logger, sentry_handler)
78-
logger.debug('Sentry logging enabled')
79-
80-
except ImportError:
81-
logger.debug('Sentry logging disabled. Try pip install raven')
82-
8365
#Set formatters
8466
file_handler.setFormatter(formatter)
8567
console_handler.setFormatter(formatter)

users/config.py.prod

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ MAIL_CONFIG = dict(
3737
MAIL_ADMIN = ('InaSAFE User Map Administrator', MAIL_CONFIG['MAIL_USERNAME'])
3838

3939
# USER ICONS: All icon paths that are used.
40-
# For now, there are only 3 icons that should be configured: user, trainer,
41-
# developer. And used the same shadow for all of the icons. Next time,
42-
# we can be more flexible about this (the role)
4340
USER_ICONS = dict(
4441
user='/static/img/user-icon.png',
45-
trainer='/static/img/trainer-icon.png',
46-
developer='/static/img/developer-icon.png',
4742
shadow='/static/img/shadow-icon.png'
4843
)

users/config.py.test

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ MAIL_CONFIG = dict(
3939
MAIL_ADMIN = ('InaSAFE User Map Administrator', MAIL_CONFIG['MAIL_USERNAME'])
4040

4141
# USER ICONS: All icon paths that are used.
42-
# For now, there are only 3 icons that should be configured: user, trainer,
43-
# developer. And used the same shadow for all of the icons. Next time,
44-
# we can be more flexible about this (the role)
4542
USER_ICONS = dict(
4643
user='/static/img/user-icon.png',
47-
trainer='/static/img/trainer-icon.png',
48-
developer='/static/img/developer-icon.png',
4944
shadow='/static/img/shadow-icon.png'
5045
)

users/resources/create_table.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
name TEXT NOT NULL,
55
email TEXT NOT NULL,
66
website TEXT,
7-
role INTEGER DEFAULT 0,
87
email_updates BOOL DEFAULT 0,
98
date_added DATETIME DEFAULT CURRENT_TIMESTAMP,
109
latitude FLOAT,

users/static/js/user-map-component.js

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,16 @@ function createIconMarkerBase(shadow_icon_path) {
4444

4545
/**
4646
* Create all icons that are used.
47-
* @param {string} user_icon_path The icon path for user role.
48-
* @param {string} trainer_icon_path The icon path for trainer role.
49-
* @param {string} developer_icon_path The icon path for developer role.
47+
* @param {string} user_icon_path The icon path for user.
5048
* @param {string} shadow_icon_path The shadow for all icons.
51-
* @returns {{user_icon: IconMarkerBase, trainer_icon: IconMarkerBase, developer_icon: IconMarkerBase}}
49+
* @returns {{user_icon: IconMarkerBase}}
5250
*/
53-
function createAllIcons(user_icon_path, trainer_icon_path, developer_icon_path, shadow_icon_path) {
51+
function createAllIcons(user_icon_path, shadow_icon_path) {
5452
var IconMarkerBase = createIconMarkerBase(shadow_icon_path);
5553
var user_icon = new IconMarkerBase({iconUrl: user_icon_path});
56-
var trainer_icon = new IconMarkerBase({iconUrl: trainer_icon_path});
57-
var developer_icon = new IconMarkerBase({iconUrl: developer_icon_path});
5854
var all_icons;
5955
all_icons = {
60-
user_icon: user_icon,
61-
trainer_icon: trainer_icon,
62-
developer_icon: developer_icon
56+
user_icon: user_icon
6357
};
6458
return all_icons;
6559
}
@@ -179,39 +173,6 @@ function createUserMenuControl(options) {
179173
return control;
180174
}
181175

182-
/**
183-
* Create legend control instance on the bottom right of the map.
184-
* The legend contains the icon and the name of the role:
185-
* 1. User
186-
* 2. Trainer
187-
* 3. Developer
188-
*
189-
* @returns {object} control
190-
*/
191-
function createLegendControl(){
192-
var control;
193-
control = L.Control.extend({
194-
options: {
195-
position: 'bottomright'
196-
},
197-
onAdd: function () {
198-
var legend_container = L.DomUtil.create('div',
199-
'info legend');
200-
legend_container.innerHTML += $("#legend").html();
201-
202-
//Prevent firing drag and onClickMap event when clicking this control
203-
var stop = L.DomEvent.stopPropagation;
204-
L.DomEvent
205-
.on(legend_container, 'click', stop)
206-
.on(legend_container, 'mousedown', stop)
207-
.on(legend_container, 'dblclick', stop)
208-
.on(legend_container, 'click', L.DomEvent.preventDefault);
209-
return legend_container;
210-
}
211-
});
212-
return control;
213-
}
214-
215176
/**
216177
* Listener to geolocation. Called when location is found.
217178
* NOTE:

users/static/js/user-map-utilities.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,6 @@ function showInformationModal(info_title, info_content) {
2121
});
2222
}
2323

24-
/**
25-
* Return user icon based on user role.
26-
* @param user_role The role.
27-
*/
28-
function getUserIcon(user_role) {
29-
var role_icon;
30-
if (user_role == USER_ROLE) {
31-
role_icon = user_icon;
32-
} else if (user_role == TRAINER_ROLE) {
33-
role_icon = trainer_icon;
34-
} else if (user_role == DEVELOPER_ROLE) {
35-
role_icon = developer_icon;
36-
}
37-
return role_icon;
38-
}
39-
40-
/**
41-
* Get User Layer that has been declared based on the role.
42-
* @param role The user role.
43-
*/
44-
function getUserLayer(role) {
45-
var layer;
46-
if (role == USER_ROLE) {
47-
layer = users_layer;
48-
} else if (role == TRAINER_ROLE) {
49-
layer = trainers_layer;
50-
} else if (role == DEVELOPER_ROLE) {
51-
layer = developers_layer;
52-
}
53-
return layer;
54-
}
55-
5624
/**
5725
* Return user form based on user attribute.
5826
* @param user The associative array containing each value of user attribute.
@@ -82,21 +50,10 @@ function getUserForm(user, mode) {
8250
$form.find('input[type=email]#email').attr('readonly', true);
8351
// Set website value
8452
$form.find('input[type=url]#website').attr('value', user['website']);
85-
// Checked one of the radio option of Role
86-
if (user['role'] == USER_ROLE) {
87-
$form.find('input[type=radio][name=role]:nth(0)').attr('checked', true);
88-
} else if (user['role'] == TRAINER_ROLE) {
89-
$form.find('input[type=radio][name=role]:nth(1)').attr('checked', true);
90-
} else if (user['role'] == DEVELOPER_ROLE) {
91-
$form.find('input[type=radio][name=role]:nth(2)').attr('checked', true);
92-
}
9353
// Checked email updates checkbox if the user should get email updates
9454
if (user['email_updates']) {
9555
$form.find('input[type=checkbox]#email_updates').attr('checked', true);
9656
}
97-
// Set latitude and longitude value
98-
$form.find('input[type=text]#lat').attr('value', user['latitude']);
99-
$form.find('input[type=text]#lng').attr('value', user['longitude']);
10057
// Set onclick attribute on button:
10158
$form.find(':button#submit_form').attr('onclick', 'editUser();');
10259
$form.find(':button#cancel_form').attr('onclick', 'cancelEditUser();');

users/static/js/user-map.js

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,17 @@
1414
* @const {int} DELETE_USER_MODE The state when user clicks delete user menu btn.
1515
* @const {int} DOWNLOAD_MODE The state when user clicks download user list btn.
1616
* @const {int} REMINDER_MODE The state when user clicks reminder button.
17-
* @const {int} USER_ROLE The number representation for user role.
18-
* @const {int} TRAINER_ROLE The number representation for trainer role.
19-
* @const {int} DEVELOPER_ROLE The number representation for developer role.
2017
*/
2118
var DEFAULT_MODE = 0;
2219
var ADD_USER_MODE = 1;
2320
var EDIT_USER_MODE = 2;
2421
var DELETE_USER_MODE = 3;
2522
var DOWNLOAD_MODE = 4;
2623
var REMINDER_MODE = 5;
27-
var USER_ROLE = 0;
28-
var TRAINER_ROLE = 1;
29-
var DEVELOPER_ROLE = 2;
3024

3125
/**
32-
* Add users to the respective layer based on user_role.
26+
* Add users to the respective layer.
3327
* @param {object} layer The layer that users will be added to.
34-
* @param {int} user_role The role of users that will be added.
3528
* @name L The Class from Leaflet.
3629
* @property geoJson Property of L class.
3730
* @property users Property of response object.
@@ -40,22 +33,19 @@ var DEVELOPER_ROLE = 2;
4033
* @property popupContent Property of properties.
4134
* @function bindPopup Bind popup to marker
4235
*/
43-
function addUsers(layer, user_role) {
36+
function addUsers(layer) {
4437
$.ajax({
4538
type: 'POST',
4639
url: '/users.json',
4740
dataType: 'json',
48-
data: {
49-
user_role: user_role
50-
},
41+
5142
success: function (response) {
52-
var role_icon = getUserIcon(user_role);
5343
L.geoJson(
5444
response.users,
5545
{
5646
onEachFeature: onEachFeature,
5747
pointToLayer: function (feature, latlng) {
58-
return L.marker(latlng, {icon: role_icon });
48+
return L.marker(latlng, {icon: user_icon });
5949
}
6050
}).addTo(layer);
6151
}
@@ -69,14 +59,11 @@ function addUsers(layer, user_role) {
6959
}
7060

7161
/**
72-
* Refresh user layer based on the role.
73-
* Each user who has the same role is grouped on the same layer.
74-
* @param {int} role The role of the users that its layer is wanted to be refreshed.
62+
* Refresh user layer.
7563
*/
76-
function refreshUserLayer(role) {
77-
var layer = getUserLayer(role);
78-
layer.clearLayers();
79-
addUsers(layer, role);
64+
function refreshUserLayer() {
65+
users_layer.clearLayers();
66+
addUsers(users_layer);
8067
}
8168

8269
/**
@@ -95,7 +82,6 @@ function addUser() {
9582
var name = $name_input.val();
9683
var email = $email_input.val();
9784
var website = $website_input.val();
98-
var role = $('input:radio[name=role]:checked').val();
9985

10086
var $email_updates_input = $('#email_updates');
10187
var email_updates;
@@ -117,7 +103,6 @@ function addUser() {
117103
name: name,
118104
email: email,
119105
website: website,
120-
role: role,
121106
email_updates: email_updates,
122107
latitude: latitude,
123108
longitude: longitude
@@ -136,14 +121,8 @@ function addUser() {
136121
} else {
137122
//Clear marker
138123
cancelMarker();
139-
// Refresh Layer according to role
140-
if (role == USER_ROLE.toString()) {
141-
refreshUserLayer(USER_ROLE);
142-
} else if (role == TRAINER_ROLE.toString()) {
143-
refreshUserLayer(TRAINER_ROLE);
144-
} else if (role == DEVELOPER_ROLE.toString()) {
145-
refreshUserLayer(DEVELOPER_ROLE);
146-
}
124+
// Refresh Layer
125+
refreshUserLayer();
147126
activateDefaultState(); // Back to default state
148127
var add_success_title = 'Information';
149128
var add_success_info =
@@ -186,10 +165,8 @@ function initializeEditedUser(user, popup_content) {
186165
* @property marker
187166
*/
188167
function addEditedUser(user, layer, popup_content) {
189-
var role_icon = getUserIcon(user['role']);
190168
edited_user_marker = L.marker(
191-
[user['latitude'], user['longitude']],
192-
{icon: role_icon }
169+
[user['latitude'], user['longitude']], {icon: user_icon }
193170
);
194171
edited_user_marker.addTo(layer);
195172
edited_user_marker.bindPopup(popup_content).openPopup();
@@ -214,7 +191,6 @@ function editUser() {
214191
var name = name_input.val();
215192
var email = email_input.val();
216193
var website = $('#website').val();
217-
var role = $('input:radio[name=role]:checked').val();
218194
var email_updates;
219195
if ($('#email_updates').is(':checked')) {
220196
email_updates = 'true';
@@ -234,7 +210,6 @@ function editUser() {
234210
name: name,
235211
email: email,
236212
website: website,
237-
role: role,
238213
email_updates: email_updates,
239214
latitude: latitude,
240215
longitude: longitude
@@ -258,8 +233,6 @@ function editUser() {
258233
* @name map Global variable of the map.
259234
* @property openPopup Method of a popup to open it.
260235
* @property closePopup Method of a popup to close it.
261-
* @property fitWorld Method from the L.map.
262-
* @property zoomIn Method from fitWorld.
263236
*/
264237
function cancelEditUser() {
265238
// Set back the marker
@@ -272,8 +245,7 @@ function cancelEditUser() {
272245
edited_user_marker.bindPopup(edited_user_popup).openPopup();
273246
// Activate Default State
274247
activateDefaultState();
275-
// Fit map to world extent
276-
map.fitWorld().zoomIn();
248+
map.setView(new L.LatLng(-3, 120), 5);
277249
}
278250

279251
/**

0 commit comments

Comments
 (0)