Skip to content

Commit

Permalink
Merge pull request #3908 from askerry/metadata-flag
Browse files Browse the repository at this point in the history
Check if facility is missing metadata. If so, promp user (via icon/to…
  • Loading branch information
rtibbles committed Aug 12, 2015
2 parents 67e5c9c + 042ba9d commit 59fad04
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 6 deletions.
5 changes: 4 additions & 1 deletion kalite/control_panel/static/css/control_panel/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ h2 {
}
.add-new-table-item {
margin-left: 8px;
}
}
.notice {
color:#dd8844;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ <h2>
<small>
<span class="help-tooltip glyphicon glyphicon-question-sign" data-toggle="tooltip" data-placement="right" title='{% trans "A facility is a physical location where learners learn." %}'></span>
</small>
{% if missing_meta %}
<small>
<span class="help-tooltip glyphicon glyphicon-exclamation-sign
notice" data-toggle="tooltip" data-placement="right" title='{%trans "The facilities highlighted below are missing metadata (e.g. location, contact information). Click the pencil icon to edit or update this information." %}'></span>
</small>
{% endif %}
</h2>
{% if not facilities %}
<p id="no-facilities-message">
Expand All @@ -27,11 +33,12 @@ <h2>
</thead>
<tbody>
{% for id,facility in facilities.items %}
<tr>
<tr {% if facility.meta_data_in_need %} class="warning" {% endif %}>
<td>
<a class="facility-name" href="{% url 'facility_management' zone_id=zone_id facility_id=facility.id %}">
{{ facility.name }}
</a>
<a class="facility-name" href="{% url 'facility_management' zone_id=zone_id facility_id=facility.id %}">{{ facility.name }}</a>
{% if facility.meta_data_in_need %}
<a href="{% url 'facility_form' facility_id=facility.id %}" class="help-tooltip glyphicon glyphicon-pencil notice" data-toggle="tooltip" data-placement="right" title="{% trans "Edit/update information for this facility." %}"></a>
{% endif %}
</td>
<td>
{{ facility.num_users }}
Expand Down
50 changes: 50 additions & 0 deletions kalite/control_panel/tests/control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,56 @@ def test_teachers_have_no_facility_delete_button(self):
with self.assertRaises(NoSuchElementException):
self.browser.find_element_by_xpath('//a[@class="facility-delete-link"]')

def test_facility_with_no_missing_metadata(self):
facility_name = 'no-missing-metadata'
self.fac = self.create_facility(name=facility_name)
for field in ['user_count', 'latitude', 'longitude', 'contact_phone']:
setattr(self.fac, field, 100)
for field in ['address', 'contact_name', 'contact_email']:
setattr(self.fac, field, 'Not Empty')
teacher_username, teacher_password = 'teacher1', 'password'
self.teacher = self.create_teacher(username=teacher_username,
password=teacher_password)
self.browser_login_teacher(username=teacher_username,
password=teacher_password,
facility_name=facility_name)
self.browse_to(self.reverse('zone_redirect')) # zone_redirect so it will bring us to the right zone

with self.assertRaises(NoSuchElementException):
self.browser.find_element_by_xpath('//*[@id="facilities-table"]/table/tbody/tr[@class="warning"]')

def test_facility_with_missing_metadata(self):
facility_name = 'missing-metadata'
self.fac = self.create_facility(name=facility_name)
teacher_username, teacher_password = 'teacher1', 'password'
self.teacher = self.create_teacher(username=teacher_username,
password=teacher_password)
self.browser_login_teacher(username=teacher_username,
password=teacher_password,
facility_name=facility_name)
self.browse_to(self.reverse('zone_redirect')) # zone_redirect so it will bring us to the right zone
#should raise NoSuchElementException if there is (incorrectly) no facility no with the warning class
self.browser.find_element_by_xpath('//*[@id="facilities-table"]/table/tbody/tr[@class="warning"]')


def test_facility_with_empty_string_metadata(self):
facility_name = 'empy-string-metadata'
self.fac = self.create_facility(name=facility_name)
for field in ['user_count', 'latitude', 'longitude', 'contact_phone']:
setattr(self.fac, field, 100)
for field in ['address', 'contact_name']:
setattr(self.fac, field, 'Not Empty')
self.fac.contact_email = ''
teacher_username, teacher_password = 'teacher1', 'password'
self.teacher = self.create_teacher(username=teacher_username,
password=teacher_password)
self.browser_login_teacher(username=teacher_username,
password=teacher_password,
facility_name=facility_name)
self.browse_to(self.reverse('zone_redirect')) # zone_redirect so it will bring us to the right zone
#should raise NoSuchElementException if there is (incorrectly) no facility no with the warning class
self.browser.find_element_by_xpath('//*[@id="facilities-table"]/table/tbody/tr[@class="warning"]')


class GroupControlTests(FacilityMixins,
CreateAdminMixin,
Expand Down
16 changes: 15 additions & 1 deletion kalite/control_panel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,19 @@ def zone_management(request, zone_id="None"):

user_activity = UserLogSummary.objects.filter(user__facility=facility)
exercise_activity = ExerciseLog.objects.filter(user__facility=facility)

facility_data[facility.id] = {
"name": facility.name,
"num_users": FacilityUser.objects.filter(facility=facility).count(),
"num_groups": FacilityGroup.objects.filter(facility=facility).count(),
"id": facility.id,
"meta_data_in_need": check_meta_data(facility),
"last_time_used": exercise_activity.order_by("-completion_timestamp")[0:1] if user_activity.count() == 0 else user_activity.order_by("-last_activity_datetime", "-end_datetime")[0],
}

context.update({
"is_headless_zone": is_headless_zone,
"facilities": facility_data,
"missing_meta": any([facility['meta_data_in_need'] for facility in facility_data.values()]),
"devices": device_data,
"upload_form": UploadFileForm(),
"own_device_is_trusted": Device.get_own_device().get_metadata().is_trusted,
Expand Down Expand Up @@ -558,6 +559,19 @@ def _get_user_usage_data(users, groups=None, period_start=None, period_end=None,
return (user_data, group_data)


def check_meta_data(facility):
'''Checks whether any metadata is missing for the specified facility.
Args:
facility (Facility instance): facility to check for missing metadata
Returns:
bool: True if one or more metadata fields are missing'''

check_fields = ['user_count', 'latitude', 'longitude', 'address', 'contact_name', 'contact_phone', 'contact_email']
return any([ (getattr(facility, field, None) is None or getattr(facility, field)=='') for field in check_fields])


# context functions

def control_panel_context(request, **kwargs):
Expand Down

0 comments on commit 59fad04

Please sign in to comment.