Skip to content

Commit

Permalink
History of logs per project
Browse files Browse the repository at this point in the history
Field type and Media file type needs to be adjusted
  • Loading branch information
Carles Boils Gisbert committed Mar 8, 2017
1 parent e33c526 commit 6e1335b
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 0 deletions.
11 changes: 11 additions & 0 deletions geokey/core/url/admin.py
Expand Up @@ -10,6 +10,7 @@
from geokey.applications import views as app_views
from geokey.superusertools import views as superusertools
from geokey.subsets import views as subsets
from geokey.core import views as logger


urlpatterns = [
Expand Down Expand Up @@ -165,6 +166,16 @@
subsets.SubsetDelete.as_view(),
name='subset_delete'),

# ###########################
# LOGGER
# ###########################

url(r'^projects/(?P<project_id>[0-9]+)/'
r'history/$',
logger.LoggerList.as_view(),
name='logger_list'),


# ###########################
# APPS
# ###########################
Expand Down
31 changes: 31 additions & 0 deletions geokey/core/views.py
Expand Up @@ -3,8 +3,39 @@
from rest_framework.views import APIView
from rest_framework.response import Response

from django.views.generic import TemplateView

from geokey.version import get_version
from geokey.extensions.base import extensions
from geokey.projects.views import ProjectContext
from geokey.core.models import LoggerHistory


class LoggerList(ProjectContext, TemplateView):
"""A list of all history logs."""

template_name = 'logger/logger_list.html'

def get_context_data(self, *args, **kwargs):
"""Return the context to render the view.
Overwrite the method to add the logs for the to the context.
Returns
-------
dict
Context.
"""

context = super(LoggerList, self).get_context_data(
*args,
**kwargs
)

logs = LoggerHistory.objects.filter(
project__contains={'id': str(context['project'].id)})

context['logs'] = logs[::-1]

return context


# ############################################################################
Expand Down
214 changes: 214 additions & 0 deletions geokey/templates/logger/logger_list.html
@@ -0,0 +1,214 @@
{% extends 'base.html' %}

{% block bodydata %}
data-project-id="{{ project.id }}"
data-project-locked="{{ project.islocked }}"
{% endblock %}

{% block title %} | Project: {{ project.name }} - Logger{% endblock %}

{% block main %}

<div class="page-header">
<div class="container">
<h1 class="smaller">
{% if project.islocked %}<span class="glyphicon glyphicon-lock" aria-hidden="true"></span>{% endif %}
<a href="{% url 'admin:project_overview' project.id %}">{{ project.name }}</a>
</h1>

{% include 'projects/navigation.html' %}
</div>
</div>

<div class="container">

{% include 'snippets/messages.html' %}

<div class="row">
<div class="col-md-8 col-md-push-2">
<h3 class="header">
{% if project.islocked %}<span class="glyphicon glyphicon-lock" aria-hidden="true"></span>{% endif %}
<span>History</span>
</h3>

{% for log in logs %}
{% if forloop.first %}
<ul class="list-unstyled overview-list">
{% endif %}
<li>
<h6>{{log.created}}</h6>
<h4>
{% if log.action.class == 'Project' %}
{%if log.action.id == 'created' %}
{{log.action.class}} {{log.action.id}} with a name <a href="{% url 'admin:project_overview' log.project.id %}"> {{ log.project.name }} </a>
{%elif log.action.id == 'deleted' %}
{{log.action.class}} {{log.action.id}}
{%elif log.action.id == 'updated' %}
{%if log.action.field == 'name' %}
{{log.action.class}} renamed to <a href="{% url 'admin:project_settings' log.project.id %}"> {{ log.project.name }} </a>
{%elif log.action.field == 'islocked' %}
{{log.action.class}} <a href="{% url 'admin:project_settings' log.project.id %}"> {{ log.project.name }} </a> is {%if log.action.value == 'True' %} locked {%else%} unlocked {% endif %}
{%elif log.action.field == 'isprivate' %}
{{log.action.class}} <a href="{% url 'admin:project_settings' log.project.id %}"> {{ log.project.name }} </a> is now {%if log.action.value == 'True' %} private {%else%} public {% endif %}
{%elif log.action.field == 'status' %}
{{log.action.class}} <a href="{% url 'admin:project_settings' log.project.id %}"> {{ log.project.name }} </a> is now {{log.action.value}}
{%elif log.action.field == 'geographic_extent' %}
{{log.action.class}} <a href="{% url 'admin:project_settings' log.project.id %}">{{ log.project.name }} </a> Project geographic extent changed
{%elif log.action.field == 'everyone_contributes' %}
{%if log.action.value == 'auth' %}
Only authenticated users can now contribute to the project
{%elif log.action.value == 'true' %}
All users can now contribute to the project
{%elif log.action.value == 'false' %}
Only specified members can now contribute to the project
{% endif %}
{% endif %}
{% endif %}

{% elif log.action.class == 'Admins' %}
{%if log.action.id == 'created' %}
User {{log.action.user_display_name}} added as an adminstrator of the project <a href="{% url 'admin:project_settings' log.project.id %}">{{ log.project.name }} </a>
{%elif log.action.id == 'deleted' %}
User {{log.action.user_display_name}} removed from adminstrators of the project <a href="{% url 'admin:project_settings' log.project.id %}">{{ log.project.name }} </a>
{% endif %}

{% elif log.action.class == 'Category' %}
{%if log.action.id == 'created' %}
{{log.action.class}} {{log.action.id}} with name <a href="{% url 'admin:category_overview' log.project.id log.category.id %}"> {{ log.category.name }} </a>
{%elif log.action.id == 'deleted' %}
{{log.action.class}} {{ log.category.name }} {{log.action.id}}
{%else%}
{%if log.action.field == 'name' %}
{{log.action.class}} renamed to <a href="{% url 'admin:category_overview' log.project.id log.category.id %}"> {{ log.category.name }} </a>
{%elif log.action.field == 'status' %}
{{log.action.class}} <a href="{% url 'admin:category_overview' log.project.id log.category.id %}"> {{ log.category.name }} </a> is {%if log.action.value == 'active' %} activated {% else %} deactivated {% endif %}
{%elif log.action.field == 'default_status' %}
Default status for contributions of category <a href="{% url 'admin:category_overview' log.project.id log.category.id %}"> {{ log.category.name }} </a> is "{{log.action.value}}"
{% else %}
<a href="">## {{ log.action.id }} ## -- {{ log.action.class }} @@@@ {{ log.action.field }} ??? {{ log.action.value}}- date: {{log.modified}}</a>
{% endif %}
{% endif %}

{% elif log.action.class == 'Subset' %}
{%if log.action.id == 'created' %}
{{log.action.class}} {{log.action.id}} with a name <a href="{% url 'admin:subset_settings' log.project.id log.subset.id %}"> {{ log.subset.name }} </a>
{%elif log.action.id == 'deleted' %}
{{log.action.class}} {{ log.subset.name }} {{log.action.id}}
{%elif log.action.field == 'name' %}
{{log.action.class}} renamed to <a href="{% url 'admin:subset_settings' log.project.id log.subset.id %}"> {{ log.subset.name }} </a>
{% endif %}

{% elif log.action.class == 'UserGroup' %}
{%if log.action.id == 'created' %}
{{log.action.class}} {{log.action.id}} with a name <a href="{% url 'admin:usergroup_settings' log.project.id log.usergroup.id %}"> {{ log.usergroup.name }} </a>
{%elif log.action.id == 'deleted' %}
{{log.action.class}} {{ log.category.name }} {{log.action.id}}
{%else%}
{%if log.action.field == 'name' %}
{{log.action.class}} renamed to <a href="{% url 'admin:usergroup_settings' log.project.id log.usergroup.id %}"> {{ log.usergroup.name }} </a>
{%elif log.action.field == 'default_status' %}
Default status for contribution of {{log.action.class}} <a href="{% url 'admin:usergroup_settings' log.project.id log.usergroup.id %}"> {{ log.usergroup.name }} </a> is "{{log.action.value}}"
{%elif log.action.field == 'can_contribute' %}
Members of the user group can now contribute to the project
{%elif log.action.field == 'can_moderate' %}
Members of the user group can now moderate contributions of the project
{%elif log.action.field == 'can_view' %}
Members of the user group can now view data of the project
{% endif %}
{% endif %}

{% elif log.action.class == 'UserGroup_users' %}
{%if log.action.subaction == 'add' %}
User {{log.action.user_display_name}} added to user group <a href="{% url 'admin:usergroup_overview' log.project.id log.usergroup.id %}"> {{ log.usergroup.name }} </a>
{%elif log.action.subaction == 'remove' %}
User {{log.action.user_display_name}} removed from User group <a href="{% url 'admin:usergroup_overview' log.project.id log.usergroup.id %}"> {{ log.usergroup.name }} </a>
{% endif %}

{% elif log.action.class == 'Field' %}
{%if log.action.id == 'created' %}
{{log.field.type}} {{log.action.id}} field with name <a href="{% url 'admin:category_field_settings' log.project.id log.category.id log.field.id %}"> {{ log.field.name }} </a> for category <a href="{% url 'admin:category_overview' log.project.id log.category.id %}"> {{ log.category.name }} </a>
{%elif log.action.id == 'deleted' %}
{{log.field.type}} {{log.action.id}} for category <a href="{% url 'admin:category_overview' log.project.id log.category.id %}">{{ log.category.name }} </a>
{%else%}
{%if log.action.field == 'name' %}
{{log.field.type}} field renamed to <a href="{% url 'admin:category_field_settings' log.project.id log.category.id log.field.id %}"> {{ log.field.name }}
{%elif log.action.field == 'status' %}
{{log.field.type}} field is now {{log.action.value}}
{%elif log.action.field == 'required' %}
{{log.field.type}} field set as {%if log.action.value == 'False' %} optional {% else %} mandayory{% endif %}
{% endif %}
{% endif %}
{% elif log.action.class == 'Location' %}
{%if log.action.id == 'created' %}
{{log.action.class}} added
{%elif log.action.id == 'deleted' %}
{{log.action.class}} {{log.action.id}}
{%else%}
{%if log.action.field == 'name' %}
{{log.action.class}} renamed to {{log.location.name}}
{%elif log.action.field == 'geometry' %}
{{log.action.class}} geometry changed
{% endif %}
{% endif %}
{% elif log.action.class == 'Comment' %}
{%if log.action.id == 'created' %}
{{log.action.class}} added to observation
{%elif log.action.id == 'deleted' %}
{{log.action.class}} {{log.action.id}} from observation
{% endif %}
{% elif log.action.class == 'Observation' %}
{%if log.action.id == 'created' %}
{{log.action.class}} added, and now is {{log.action.value}}
{%elif log.action.id == 'deleted' %}
{{log.action.class}} {{log.action.id}}
{%else%}
{%if log.action.field == 'properties' %}
Observation properties changed
{%elif log.action.field == 'status' %}
{% if log.action.value == 'review' %}
{{log.action.class}} reported
{% elif log.action.value == 'active' %}
{{log.action.class}} activated
{% elif log.action.value == 'pending' %}
{{log.action.class}} suspended
{% endif %}
{% endif %}
{% endif %}
{% elif log.action.class == 'MediaFile' %}
{%if log.action.id == 'created' %}
{{log.mediafile.type}} media file added to observation
{%elif log.action.id == 'deleted' %}
{{log.mediafile.type}} media file {{log.action.id}} from observation
{% endif %}
{% else %}
<a href="">## {{ log.action.id }} ## -- {{ log.action.class }} @@@@ {{ log.action.field }} ??? {{ log.action.value}}- date: {{log.modified}}</a>
{% endif %}

</h4>
</li>

{% if forloop.last %}
</ul>
{% endif %}



{% endfor %}
</div>
</div>
</div>
{% endblock %}

{% block libraries %}
<script src="/static/lib/moment/moment.min.js"></script>

<script src="/static/lib/handlebars/handlebars.js"></script>
<script src="/static/js/templates.js"></script>

<link rel="stylesheet" href="/static/lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css">
<script src="/static/lib/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>

<script src="/static/js/admin.ui.filters.data.js"></script>
<script src="/static/js/admin.ui.forms.validate.js"></script>

{% endblock %}
6 changes: 6 additions & 0 deletions geokey/templates/projects/navigation.html
Expand Up @@ -19,7 +19,13 @@
<a href="{% url 'admin:project_geographicextent' project.id %}">Geographic extent</a>
</li>

<li role="presentation" class="{% if request.resolver_match.url_name == 'logger_list' %}active{% endif %}">
<a href="{% url 'admin:logger_list' project.id %}">Logger</a>
</li>

<li role="presentation" class="{% if request.resolver_match.url_name == 'project_settings' %}active{% endif %}">
<a href="{% url 'admin:project_settings' project.id %}">Settings</a>
</li>


</ul>

0 comments on commit 6e1335b

Please sign in to comment.