Skip to content

Commit

Permalink
[ refs #108419] Add logging details
Browse files Browse the repository at this point in the history
* Create UserLog model refs #105

* Save user log in the database refs #105

* Add user log on Home Page refs #105

* Update user log style on HomePage refs #105

* Remove extra field from user log refs #105

* Update coding style refs #105

#110
  • Loading branch information
claudiaxpreda authored and dianaboiangiu committed Aug 27, 2019
1 parent ce434f3 commit ecc78b7
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 40 deletions.
27 changes: 27 additions & 0 deletions insitu/migrations/0024_add_user_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.21 on 2019-08-26 14:38
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('insitu', '0023_extend_product_acronym_length'),
]

operations = [
migrations.CreateModel(
name='UserLog',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.CharField(max_length=255)),
('date', models.DateTimeField()),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
6 changes: 6 additions & 0 deletions insitu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,9 @@ class DataProviderRelation(ValidationWorkflowModel, SoftDeleteModel):

def __str__(self):
return '{} - {}'.format(self.data.name, self.provider.name)


class UserLog(models.Model):
text = models.CharField(max_length=255)
date = models.DateTimeField()
user = models.ForeignKey(User, on_delete=models.CASCADE)
61 changes: 45 additions & 16 deletions insitu/static/css/style.css
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
.popover {
min-width: 40%;
max-width: 100%;
min-width: 40%;
max-width: 100%;
}

.orange {
color: #FC7300;
color: #FC7300;
}

.blue {
color: #00529B;
color: #00529B;
}

.green {
color: #007B2B;
color: #007B2B;
}

.red {
color: red;
color: red;
}

.no-padding-left {
padding-left: 0;
padding-left: 0;
}

.paginate_button:hover {
border: 0px !important;
border: 0px !important;
}

.paginate_button {
padding: 0 !important;
padding: 0 !important;
}

.filters-style{
padding-top: 10px;
padding-top: 10px;
}

.margin-left-btn{
margin-left: 1%
margin-left: 1%
}

.main-title{
Expand Down Expand Up @@ -71,13 +71,13 @@
}

.display-margin{
margin-top: 20px;
margin-bottom: 20px;
margin-top: 20px;
margin-bottom: 20px;
}

.green-text{
color: green !important;
font-weight: bold;
color: green !important;
font-weight: bold;
}

@media (min-width: 1200px){
Expand Down Expand Up @@ -110,7 +110,7 @@
}

.font-weight-bold {
font-weight: bold;
font-weight: bold;
}

.navbar-nav>li>a {
Expand All @@ -124,12 +124,41 @@
margin-left:60px;
}

.user_log {
width:30%;
height:20%;
padding-top: 68px;
}

.padding_user_log {
padding: 0px 16px 16px 0px;
}

.latest-changes-text {
font-size: 16px;
font-weight: 700;
color:red;
}

.quiet {
font-size: 11px;
font-weight: normal;
color: #999999;
}

.recent_action {
padding: 16px;
margin-bottom: 16px;
border-bottom: 1px solid #e7e7e7;
font-size: 16px;
color: #337ab7;
font-weight: 700;
}

.recent_action_bg {
background: #f8f8f8;
}

.statistics-bar {
margin-top: -15px;
text-align: center;
Expand Down
70 changes: 46 additions & 24 deletions insitu/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,54 @@
</head>

{% block content %}
<div class="jumbotron main-title">
<h1>In Situ Component</h1>
<p>Copernicus In Situ Component Information System</p>
</div>
<body>
{% if user.is_authenticated %}
<div class="latest-information">
<div>
<p class="latest-changes-text">Latest changes</p>
<h4 class="font-weight-bold">2.0.1 (2019-07-05)</h4>
<ul>
<li>Use official name in User Manual</li>
</ul>
<p><strong>The UserManual is available <a href="{% url 'user_manual' %}">here.</strong></a></p>
{% if DEBUG %}
<p class="latest-changes-text"><strong>This is a DEMO application</strong></p>
{% endif %}
<div class="row">
<div class="jumbotron main-title col-lg-7">
<h1>In Situ Component</h1>
<p>Copernicus In Situ Component Information System</p>
</div>
{% if user.is_authenticated %}
<div class="user_log col-sm-1 col-xs-offset-1">
<div class="recent_action_bg">
<p class="recent_action">Recent Actions</p>
<div class="padding_user_log">
{% if user_log %}
{% for log in user_log %}
<ul>
<li><b>{{ log.user.username }} </b>{{ log.text }}
<br>
<span class="quiet">{{ log.date }}</span>
</li>
</ul>
{% endfor %}
{% else %}
<ul>
<li><b>No recent actions</b></li>
</ul>
{% endif %}
</div>
</div>
</div>
<div class="latest-information">
<div>
<p class="latest-changes-text">Latest changes</p>
<h4 class="font-weight-bold">2.0.1 (2019-07-05)</h4>
<ul>
<li>Use official name in User Manual</li>
</ul>
<p><strong>The UserManual is available <a href="{% url 'user_manual' %}">here.</strong></a></p>
{% if DEBUG %}
<p class="latest-changes-text"><strong>This is a DEMO application</strong></p>
{% endif %}
</div>
</div>
{% endif %}
<div id="footer">
<img class="logo-copernicus" src="{% static "/images/logo-copernicus.png" %}" alt="Copernicus Logo" hspace="150">
<img class="in-situ-logo" src="{% static "/images/in-situ-logo.png" %}" alt="In Situ Logo">
<img class="european_commission-logo" src="{% static "/images/european_commission.png" %}"
alt="European Commission Logo" hspace="150">
</div>
</div>
{% endif %}
<div id="footer">
<img class="logo-copernicus" src="{% static "/images/logo-copernicus.png" %}" alt="Copernicus Logo" hspace="150">
<img class="in-situ-logo" src="{% static "/images/in-situ-logo.png" %}" alt="In Situ Logo">
<img class="european_commission-logo" src="{% static "/images/european_commission.png" %}"
alt="European Commission Logo" hspace="150">
</div>
</body>

{% endblock %}
7 changes: 7 additions & 0 deletions insitu/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
from .crash_me import *

from django.views.generic import TemplateView
from insitu.models import UserLog


class HomeView(TemplateView):
template_name = 'home.html'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
user_log = UserLog.objects.filter().order_by('-date')[:10]
context['user_log'] = user_log
return context
17 changes: 17 additions & 0 deletions insitu/views/action_logging/base_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import sys
from datetime import datetime
from insitu.models import UserLog


class BaseLoggingView:
Expand Down Expand Up @@ -29,6 +30,22 @@ def log_action(self, request, action, id=''):
]).strip(",")
spamwriter.writerow(row.split(','))

BaseLoggingView.add_user_log(request.user, action, id, self.target_type)

@staticmethod
def add_user_log(user, action, id, target_type):
text = " ".join([
action,
target_type,
str(id)
]).strip(" ")
log = {
'text': text,
'date': datetime.now(),
'user': user
}
UserLog.objects.create(**log)


class GetMethodLoggingView(BaseLoggingView):
get_action = None
Expand Down

0 comments on commit ecc78b7

Please sign in to comment.