Globale Suche ins Dropdown

Links bei den Standards zum Hersteller und zum LastModified
Dashboard angefangen
This commit is contained in:
holger.trampe 2019-12-08 21:04:03 +01:00
parent 32c8b69457
commit 076583e8bd
8 changed files with 94 additions and 108 deletions

View File

@ -24,7 +24,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '_qv2t2lmsctjxpbb4rrp=op%_20_hxzonv^mvty1o85c)l$s^q'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False
ALLOWED_HOSTS = ['digitale-agentur.com', 'www.digitale-agentur.com', 'localhost']
@ -169,18 +169,16 @@ LOGIN_REDIRECT_URL = 'users-dashboard'
#SITE_ROOT = '/var/www/digitale-agentur.com/digitaleagentur/digitaleagentur/../'
#STATIC_ROOT = (os.path.join(SITE_ROOT, 'static/'))
STATIC_URL = 'users/static/'
#STATIC_URL = '/static/'
SITE_ROOT = os.path.dirname(os.path.realpath(__file__)) + '/..'
STATIC_ROOT = (os.path.join(SITE_ROOT, 'users/static/'))
STATICFILES_DIRS = (
os.path.join(SITE_ROOT, 'users/static/'),
)
if DEBUG:
STATIC_URL = '/static/'
else:
STATIC_URL = 'users/static/'
SITE_ROOT = os.path.dirname(os.path.realpath(__file__)) + '/..'
STATIC_ROOT = (os.path.join(SITE_ROOT, 'users/static/'))
STATICFILES_DIRS = (
os.path.join(SITE_ROOT, 'users/static/'),
)
# CRISPY
CRISPY_TEMPLATE_PACK = 'bootstrap4'

View File

@ -14,40 +14,6 @@
</div>
<hr>
<div class="row">
{% for item in standards_of_agency %}
{% if item.public or item.created_standard_by == user or perms.users.standard_management %}
<div class=" mb-4 col-5">
<div class="card">
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<a href="{% url 'standard-single' item.pk%}">
{% if item.public %}
<h4><u>{{item.name}}</u></h4>
{% else %}
<h4 class="text-warning"><u>{{item.name}}</u></h4>
{% endif %}
</a>
{% if item.created_standard_by == user or perms.users.standard_management %}
<div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
<!--<div class="dropdown-header">Benutzerdaten</div>-->
<a class="dropdown-item" href="{% url 'standard-update' item.pk %}">Bearbeiten</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" href="{% url 'standard-delete' item.pk %}" >Löschen</a>
</div>
</div>
{% endif %}
</div>
<div class="card-body">
<h5 class="card-title">{{item.created_standard_by.first_name}} {{item.created_standard_by.last_name}} <h6>Zuletzt bearbeitet von {{ item.last_modified_by.first_name }} {{ item.last_modified_by.last_name }} am {{ item.last_modified_on }}</h6>
</h5>
<p class="card-text">{{ item.content|truncatechars:250|safe}}</p>
</div>
</div>
</div>
{% endif %}
{% endfor%}
</div>
{% endblock content %}

View File

@ -10,7 +10,7 @@
</nav>
<small>
<h2>{{standard.name}}</h2>
Erstellt durch {{standard.created_standard_by.first_name}} {{standard.created_standard_by.last_name}} am {{standard.created_standard_date}} | Zuletzt bearbeitet von {{ standard.last_modified_by.first_name}} {{ standard.last_modified_by.last_name}} am {{ standard.last_modified_on}}
Erstellt durch <a href="{% url 'orga-single' standard.created_standard_by.pk %}">{{standard.created_standard_by.first_name}} {{standard.created_standard_by.last_name}}</a> am {{standard.created_standard_date}} | Zuletzt bearbeitet von <a href="{% url 'orga-single' standard.last_modified_by.pk %}">{{ standard.last_modified_by.first_name}} {{ standard.last_modified_by.last_name}}</a> am {{ standard.last_modified_on}}
{% if standard.created_standard_by == user or perms.users.standard_management %}
&nbsp;|&nbsp;<a href="{% url 'standard-update' standard.pk %}">Bearbeiten</a>
{% endif%}

View File

@ -173,13 +173,18 @@
<!-- Topbar Search -->
<form class="d-none d-sm-inline-block form-inline mr-auto ml-md-3 my-2 my-md-0 mw-100 navbar-search">
<div class="input-group">
<input list="searchres" placeholder="Suche..." id="search_string" onchange="javascript:checkValue()" onkeyup="javascript:startSearch(this.value)" class="form-control bg-light border-0 small" >
<datalist id="searchres" >
</datalist>
<!--
<input type="text" onkeyup="javascript:startSearch(this.value)" class="form-control bg-light border-0 small" placeholder="Suche..." aria-label="Suche" aria-describedby="basic-addon2" id="searchfield">
<div class="input-group-append">
-->
<!--<div class="input-group-append">
<button class="btn btn-primary" type="button" onclick="javascript:clearSF()">
<i class="fas fa-times fa-sm"></i>
</button>
</div>
</button>-->
</div>
</form>
@ -221,9 +226,7 @@
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- RESULTS -->
<div id="searchresults_div"></div>
<!-- MESSAGES -->
{% if messages %}
{% for message in messages %}
@ -233,17 +236,9 @@
<span aria-hidden="true">&times;</span>
</button>
</div>
<script>
//Ausfaden der Meldungen erstmal rausgenommen
/*
setTimeout(function() {
$('#message_{{forloop.counter}}').fadeOut();
}, 3000 );
*/
</script>
{% endfor %}
{% endif %}
<div id="maincontent_for_search">
<div id="maincontent">
{% block content %}
{% endblock %}
</div>
@ -296,19 +291,10 @@
</html>
<script type="text/javascript">
function clearSF(){
$("#searchfield").val("");
$("#searchresults_div").empty();
$("#searchresults_div").hide();
$("#maincontent_for_search").show();
}
function startSearch(searchstring){
if(searchstring.length > 2){
$("#maincontent_for_search").hide();
$("#searchresults_div").show();
$.ajax(
{
type: "GET",
@ -318,43 +304,28 @@
},
success: function( data )
{
$("#searchresults_div").empty();
if(data['res'].length > 1){
$("#searchresults_div").append('<h4>' + data['res'].length + ' Sucherergebnisse</h4><hr>');
}
else if(data['res'].length == 1){
$("#searchresults_div").append('<h4>' + data['res'].length + ' Sucherergebnis</h4><hr>');
}
else {
$("#searchresults_div").append('<h4>Keine Sucherergebnis</h4><hr>');
}
$("#searchres").empty();
for (var i = 0; i < data['res'].length; i++)
{
$("#searchresults_div").append('<div class="mb-4"><div class="card"><div class="card-header py-3 d-flex flex-row align-items-center justify-content-between"><a href="/standards/standard/'+data['res'][i]['id']+'/single"><h5><u>'+data['res'][i]['name']+'</u></h5></a><div class="dropdown no-arrow"></div></div><div class="card-body"><h6 class="card-title">Von '+data['res'][i]['first_name']+' '+data['res'][i]['last_name']+' | <small>Zuletzt bearbeitet von '+data['res'][i]['first_name_mod']+' '+data['res'][i]['last_name_mod']+' am '+data['res'][i]['last_modified_on']+'</small></h6><p class="card-text">'+data['res'][i]['content']+'</p></div></div></div>');
{
id = data['res'][i]['id'];
name = data['res'][i]['name'] + " | " + data['res'][i]['content'];
$("#searchres").append('<option id="'+id+'" value="'+name+'"></option>');
}
}
});
}
else {
$("#searchresults_div").empty();
$("#searchresults_div").hide();
$("#maincontent_for_search").show();
}
}
function goToStandard(id){
$.ajax(
{
type: "GET",
url: "/dashboard/standardrout",
data:{
's_id': id
},
success (data){
console.log(data);
}
});
//Check valid input and go to standard by click
function checkValue(){
for(i = 0; i < document.getElementById("searchres").options.length; i++){
var value = $("#search_string").val();
var choosen = document.getElementById("searchres").options[i].value;
if(value.search(choosen) != -1){
window.location = "/standards/standard/"+document.getElementById("searchres").options[i]['id']+"/single";
}
}
}
</script>

View File

@ -5,8 +5,44 @@
<small>Letzter Login: {{ request.user.last_login }}</small>
<hr>
Agentur: <b>{{ request.user.profile.agency.name }}</b>
<div class="col-md-6">
<div class="">
<img class="img-profile" width="75%" src="{{ request.user.profile.agency.agencypic.url }}">
<hr>
{% for item in standards_of_agency %}
{% if item.public or item.created_standard_by == user or perms.users.standard_management %}
<div class=" mb-4 col-5">
<div class="card">
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<a href="{% url 'standard-single' item.pk%}">
{% if item.public %}
<h4><u>{{item.name}}</u></h4>
{% else %}
<h4 class="text-warning"><u>{{item.name}}</u></h4>
{% endif %}
</a>
{% if item.created_standard_by == user or perms.users.standard_management %}
<div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
<!--<div class="dropdown-header">Benutzerdaten</div>-->
<a class="dropdown-item" href="{% url 'standard-update' item.pk %}">Bearbeiten</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" href="{% url 'standard-delete' item.pk %}" >Löschen</a>
</div>
</div>
{% endif %}
</div>
<div class="card-body">
<h5 class="card-title">{{item.created_standard_by.first_name}} {{item.created_standard_by.last_name}} <h6>Zuletzt bearbeitet von {{ item.last_modified_by.first_name }} {{ item.last_modified_by.last_name }} am {{ item.last_modified_on }}</h6>
</h5>
<p class="card-text">{{ item.content|truncatechars:250|safe}}</p>
</div>
</div>
</div>
{% endif %}
{% endfor%}
</div>
</div>
{% endblock content %}

View File

@ -58,6 +58,13 @@ def dashboard(request):
context = {
'active_link' : 'dashboard'
}
# Adding active_link
# Loading only user same agency
# Change context and return for template-data
# # Get all Users of the Same Agency as logged user
standards_of_agency = Standards.objects.filter(agency__pk=request.user.profile.agency.pk).order_by('-last_modified_on')[:10]
context.update({'active_link' : 'standards', 'standards_of_agency' : standards_of_agency})
#return context
return render (request, 'users/dashboard.html', context)
@ -270,6 +277,14 @@ def UsersPrioUpdate(request):
else:
return HttpResponse("Request method is not a GET")
import re
def cleanhtml(raw_html):
cleanr = re.compile('<.*?>')
cleantext = re.sub(cleanr, '', raw_html)
return cleantext
# Searxh for Standards by name, content, creator - standards needs to be public!
def GlobalSearch(request):
if request.method == 'GET':
@ -288,7 +303,7 @@ def GlobalSearch(request):
tempele['id'] = ele.pk
tempele['name'] = ele.name
# First 100 chars of the Content
tempele['content'] = ele.content[:100]
tempele['content'] = cleanhtml(ele.content[:100])
tempele['first_name'] = ele.created_standard_by.first_name
tempele['last_name'] = ele.created_standard_by.last_name
tempele['first_name_mod'] = ele.last_modified_by.first_name