Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoInt_SIDT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoInt_SIDT
Commits
669d1777
Commit
669d1777
authored
May 09, 2019
by
Ulises Morales Ramírez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
descripcion reportes
parent
a5d4d557
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
364 additions
and
152 deletions
+364
-152
map.html
catalog/templates/map.html
+141
-135
views.py
catalog/views.py
+17
-3
Reports.css
reports/static/reports/css/Reports.css
+0
-5
scldata.css
reports/static/reports/css/scldata.css
+34
-0
scripts.js
users/static/users/js/scripts.js
+1
-0
profile.html
users/templates/profile.html
+107
-5
urls.py
users/urls.py
+1
-0
views.py
users/views.py
+63
-4
No files found.
catalog/templates/map.html
View file @
669d1777
...
...
@@ -121,7 +121,8 @@
<!-- search form -->
<form
role=
"form"
action=
"#"
method=
"get"
class=
"sidebar-form"
>
<div
class=
"input-group"
>
<input
type=
"text"
id=
"ajax-input"
value=
""
name=
"value"
class=
"form-control"
autocomplete=
"off"
placeholder=
"Search region..."
>
<input
type=
"text"
id=
"ajax-input"
value=
""
name=
"value"
class=
"form-control"
autocomplete=
"off"
placeholder=
"Search region..."
>
<span
class=
"input-group-btn"
>
<button
type=
"button"
name=
"search"
id=
"erase-btn"
class=
"btn btn-flat"
onclick=
"erase_input()"
>
<i
class=
"fa fa-eraser"
></i>
...
...
@@ -139,7 +140,7 @@
<!-- <form role="form" target="catalogFrame" action="{% url 'productList' %}" method="post"> -->
<form
id=
'product-form'
role=
"form"
method=
"post"
>
{% csrf_token %}
<input
type=
"hidden"
id=
"user_name"
name=
"user_name"
value=
{{
user.get_username
}}
>
<input
type=
"hidden"
id=
"user_name"
name=
"user_name"
value=
{{
user
.
get_username
}}
>
<input
type=
"hidden"
id=
"search_name"
name=
"search_name"
value=
"Drawn Polygon"
>
<input
type=
"hidden"
id=
"area_description"
name=
"area_description"
value=
"Without Description"
>
<ul
class=
"sidebar-menu"
data-widget=
"tree"
>
...
...
@@ -162,19 +163,20 @@
<span
class=
"pull-right-container"
>
<span
class=
"label label-primary pull-right"
></span>
</span>
</a>
<ul
class=
"treeview-menu sidebar-form"
>
<span>
Start Date
</span>
<li>
{{searchForm.start}}
</li>
<span>
End Date
</span>
<li>
{{searchForm.end}}
</li>
</ul>
</li>
<li
class=
"treeview "
>
<a
href=
"#"
>
<i
class=
"fa fa-map"
></i>
<span>
Polygon
</span>
<span
class=
"pull-right-container"
>
</a>
<ul
class=
"treeview-menu sidebar-form"
>
<span>
Start Date
</span>
<li>
{{ searchForm.start }}
</li>
<span>
End Date
</span>
<li>
{{ searchForm.end }}
</li>
</ul>
</li>
{% if advanced_search == True %}
<li
class=
"treeview "
>
<a
href=
"#"
>
<i
class=
"fa fa-map"
></i>
<span>
Polygon
</span>
<span
class=
"pull-right-container"
>
<span
class=
"label label-primary pull-right"
></span>
</span>
</a>
...
...
@@ -182,6 +184,7 @@
<li>
{{ searchForm.polygon }}
</li>
</ul>
</li>
{% endif %}
<li
class=
"treeview "
>
<a
href=
"#"
>
<i
class=
"fa fa-cloud"
></i>
...
...
@@ -189,27 +192,29 @@
<span
class=
"pull-right-container"
>
<span
class=
"label label-primary pull-right"
></span>
</span>
</a>
<ul
class=
"treeview-menu sidebar-form"
>
<li>
<div
class=
"row"
>
<div
class=
"col-lg-9"
style=
"padding-top: 5px;"
>
<input
class=
"cross-range"
type=
"range"
min=
"0"
max=
"100"
step=
"1"
value=
"5"
oninput=
"setCloudPercentage(this.value)"
id=
"cloudPercentageSelector"
name=
"cloudPercentage"
>
</div>
<div
class=
"col-lg-3"
style=
"padding-left:0px;padding-top: 5px;"
>
<!-- <input class="form-text" id="clouds" value="5" oninput="setCloudPercentageSlider(this.value)" name="cloudPercentage" disabled> -->
<span
id=
"clouds"
>
5
</span>
</div>
</div>
</a>
<ul
class=
"treeview-menu sidebar-form"
>
<li>
<div
class=
"row"
>
<div
class=
"col-lg-9"
style=
"padding-top: 5px;"
>
<input
class=
"cross-range"
type=
"range"
min=
"0"
max=
"100"
step=
"1"
value=
"5"
oninput=
"setCloudPercentage(this.value)"
id=
"cloudPercentageSelector"
name=
"cloudPercentage"
>
</div>
<div
class=
"col-lg-3"
style=
"padding-left:0px;padding-top: 5px;"
>
<!-- <input class="form-text" id="clouds" value="5" oninput="setCloudPercentageSlider(this.value)" name="cloudPercentage" disabled> -->
<span
id=
"clouds"
>
5
</span>
</div>
</div>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a
href=
"#"
><div
class=
"modal"
>
<!-- Place at bottom of page -->
</div>
<span>
<li>
<a
href=
"#"
>
<div
class=
"modal"
>
<!-- Place at bottom of page -->
</div>
<span>
<button
type=
"submit"
name=
"search"
id=
"search-btn"
class=
"btn btn-primary"
><i
class=
"fa fa-search"
></i>
Search
</button>
<!-- <button name="search" id="search-btn" class="btn btn-primary">Search</button> -->
<!-- <button name="search" id="search-btn" class="btn btn-primary">Search</button> -->
</span>
</a>
</li>
...
...
@@ -233,48 +238,48 @@
{% block content %}
<div
id=
"map"
class=
"map"
tabindex=
"0"
></div>
<footer
class=
" page-footer font-small special-color-dark pt-5"
style=
"bottom: 0; position: absolute"
>
<!-- Footer Elements -->
<div
class=
"container"
>
<!-- Social buttons
<ul class="list-unstyled list-inline text-center">
<li class="list-inline-item">
<a class="btn-floating btn-fb mx-1">
<i class="fa fa-faceboo"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-tw mx-1">
<i class="fa fa-twitter"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-gplus mx-1">
<i class="fa fa-google-plus"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-li mx-1">
<i class="fa fa-linkedin"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-dribbble mx-1">
<i class="fa fa-dribbble"> </i>
</a>
</li>
</ul>
<!-- Social buttons -->
<!-- Footer Elements -->
<div
class=
"container"
>
<!-- Social buttons
<ul class="list-unstyled list-inline text-center">
<li class="list-inline-item">
<a class="btn-floating btn-fb mx-1">
<i class="fa fa-faceboo"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-tw mx-1">
<i class="fa fa-twitter"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-gplus mx-1">
<i class="fa fa-google-plus"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-li mx-1">
<i class="fa fa-linkedin"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-dribbble mx-1">
<i class="fa fa-dribbble"> </i>
</a>
</li>
</ul>
<!-- Social buttons -->
</div>
<!-- Footer Elements -->
</div>
<!-- Footer Elements -->
<!-- Copyright -->
<div
class=
"footer-copyright text-center py-3"
>
© 2019 Copyright:
<a
href=
"http://geoint.mx/"
>
Centro de Investigación en Ciencias de Información Geoespacial.
</a>
</div>
<!-- Copyright -->
<!-- Copyright -->
<div
class=
"footer-copyright text-center py-3"
>
© 2019 Copyright:
<a
href=
"http://geoint.mx/"
>
Centro de Investigación en Ciencias de Información Geoespacial.
</a>
</div>
<!-- Copyright -->
</footer>
</footer>
<div
class=
"waitingModal"
></div>
{% endblock %}
...
...
@@ -282,79 +287,80 @@
{% block modal1 %}{% include "mssgModal.html" %}{% endblock %}
{% block scripts %}
<script>
var
d
=
6
;
//días diferidos entre las dos fechas
var
fecha
=
new
Date
();
//Fecha actual
var
dia
=
fecha
.
getDate
();
//obteniendo dia
var
mes
=
fecha
.
getMonth
()
+
1
;
//obteniendo mes
var
ano
=
fecha
.
getFullYear
();
//obteniendo año
<script>
var
d
=
6
;
//días diferidos entre las dos fechas
var
fecha
=
new
Date
();
//Fecha actual
var
dia
=
fecha
.
getDate
();
//obteniendo dia
var
mes
=
fecha
.
getMonth
()
+
1
;
//obteniendo mes
var
ano
=
fecha
.
getFullYear
();
//obteniendo año
if
(
dia
<
10
)
dia
=
'0'
+
dia
;
//agrega cero si el menor de 10
if
(
mes
<
10
)
mes
=
'0'
+
mes
//agrega cero si el menor de 10
document
.
getElementById
(
'id_end'
).
value
=
ano
+
"-"
+
mes
+
"-"
+
dia
;
if
(
dia
<
10
)
dia
=
'0'
+
dia
;
//agrega cero si el menor de 10
if
(
mes
<
10
)
mes
=
'0'
+
mes
//agrega cero si el menor de 10
document
.
getElementById
(
'id_end'
).
value
=
ano
+
"-"
+
mes
+
"-"
+
dia
;
var
dia_anterior
=
fecha
.
getDate
()
-
d
;
var
mes_anterior
=
fecha
.
getMonth
()
+
1
;
var
ano_anterior
=
fecha
.
getFullYear
();
var
dia_anterior
=
fecha
.
getDate
()
-
d
;
var
mes_anterior
=
fecha
.
getMonth
()
+
1
;
var
ano_anterior
=
fecha
.
getFullYear
();
//Condición donde el día anterior cae en un mes anterior
//selección del día del mes anterior con base en el todal de días del mes
//
if
(
dia_anterior
<=
0
)
{
mes_anterior
=
mes_anterior
-
1
;
//Condición donde el día anterior cae en un mes anterior
//selección del día del mes anterior con base en el todal de días del mes
//
if
(
dia_anterior
<=
0
)
{
mes_anterior
=
mes_anterior
-
1
;
if
(
mes_anterior
==
0
)
{
mes_anterior
=
12
;
ano_anterior
=
ano_anterior
-
1
;
//En caso de consulta entre diciembre y enero
}
if
(
mes_anterior
==
0
)
{
mes_anterior
=
12
;
ano_anterior
=
ano_anterior
-
1
;
//En caso de consulta entre diciembre y enero
}
if
(
mes_anterior
==
1
||
mes_anterior
==
3
||
mes_anterior
==
5
||
mes_anterior
==
7
||
mes_anterior
==
8
||
mes_anterior
==
10
||
mes_anterior
==
12
)
dia_anterior
=
31
+
(
dia
-
6
);
if
(
mes_anterior
==
1
||
mes_anterior
==
3
||
mes_anterior
==
5
||
mes_anterior
==
7
||
mes_anterior
==
8
||
mes_anterior
==
10
||
mes_anterior
==
12
)
dia_anterior
=
31
+
(
dia
-
6
);
if
(
mes_anterior
==
4
||
mes_anterior
==
6
||
mes_anterior
==
9
||
mes_anterior
==
11
)
dia_anterior
=
30
+
(
dia
-
6
);
if
(
mes_anterior
==
4
||
mes_anterior
==
6
||
mes_anterior
==
9
||
mes_anterior
==
11
)
dia_anterior
=
30
+
(
dia
-
6
);
if
(
mes_anterior
==
2
)
dia_anterior
=
28
+
(
dia
-
6
);
}
//Condicion donde el día o el mes es menor a 10
if
(
dia_anterior
<
10
)
dia_anterior
=
'0'
+
dia_anterior
;
//agrega cero si el menor de 10
if
(
mes_anterior
==
2
)
dia_anterior
=
28
+
(
dia
-
6
);
}
//Condicion donde el día o el mes es menor a 10
if
(
dia_anterior
<
10
)
dia_anterior
=
'0'
+
dia_anterior
;
//agrega cero si el menor de 10
if
(
mes_anterior
<
10
)
mes_anterior
=
'0'
+
mes_anterior
;
//agrega cero si el menor de 10
if
(
mes_anterior
<
10
)
mes_anterior
=
'0'
+
mes_anterior
;
//agrega cero si el menor de 10
document
.
getElementById
(
'id_start'
).
value
=
ano_anterior
+
"-"
+
mes_anterior
+
"-"
+
dia_anterior
;
document
.
getElementById
(
'id_start'
).
value
=
ano_anterior
+
"-"
+
mes_anterior
+
"-"
+
dia_anterior
;
</script>
<script>
function
setCloudPercentage
(
clouds
)
{
//console.log(clouds)
//document.getElementById("clouds").value = clouds;
document
.
getElementById
(
"clouds"
).
innerHTML
=
clouds
;
}
function
setCloudPercentageSlider
(
clouds
)
{
//console.log(clouds)
//TODO
document
.
getElementById
(
"cloudPercentageSelector"
).
value
=
clouds
;
if
(
parseInt
(
clouds
)
>
100
){
document
.
getElementById
(
"cloudPercentageSelector"
).
value
=
100
;
</script>
<script>
function
setCloudPercentage
(
clouds
)
{
//console.log(clouds)
//document.getElementById("clouds").value = clouds;
document
.
getElementById
(
"clouds"
).
innerHTML
=
clouds
;
}
function
setCloudPercentageSlider
(
clouds
)
{
//console.log(clouds)
//TODO
document
.
getElementById
(
"cloudPercentageSelector"
).
value
=
clouds
;
if
(
parseInt
(
clouds
)
>
100
)
{
document
.
getElementById
(
"cloudPercentageSelector"
).
value
=
100
;
}
if
(
parseInt
(
clouds
)
<
0
)
{
document
.
getElementById
(
"cloudPercentageSelector"
).
value
=
0
;
}
}
if
(
parseInt
(
clouds
)
<
0
){
document
.
getElementById
(
"cloudPercentageSelector"
).
value
=
0
;
}
}
//var osmap = new OpenStreetMapsClass("map", -99.145556,19.419444, 10);
var
osmap
=
new
sidtMap
(
"map"
,
-
89.63873079999999
,
21.0404457
,
7
);
osmap
.
geolocation
();
osmap
.
addInteraction
();
//var osmap = new OpenStreetMapsClass("map", -99.145556,19.419444, 10);
var
osmap
=
new
sidtMap
(
"map"
,
-
89.63873079999999
,
21.0404457
,
7
);
osmap
.
geolocation
();
osmap
.
addInteraction
();
var
req_url
=
"{% url 'search-submit' %}"
;
// url for requesting polygon data
var
prod_req_url
=
"{% url 'productList' %}"
;
// url for requesting product data
...
...
catalog/views.py
View file @
669d1777
...
...
@@ -10,7 +10,7 @@ from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
from
django.urls
import
reverse
from
django.views.generic.base
import
View
from
django.template
import
loader
,
RequestContext
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
,
Permission
import
requests
,
json
,
unicodedata
,
sys
,
base64
import
os
from
geosentinel
import
APISentinel
,
polygonToBox
...
...
@@ -57,10 +57,17 @@ def map(request):
"""
View function for home page of site.
"""
if
Permission
.
objects
.
filter
(
user
=
request
.
user
.
id
):
advanced_search
=
True
else
:
advanced_search
=
False
form
=
ASFSearchForm
(
request
.
POST
)
showcart
=
True
# Render the HTML template index.html with the data in the context variable
return
render
(
request
,
'map.html'
,
{
"searchForm"
:
form
,
"showcart"
:
showcart
})
return
render
(
request
,
'map.html'
,
{
"searchForm"
:
form
,
"showcart"
:
showcart
,
"advanced_search"
:
advanced_search
})
# -------------------------------------------------------------------------------
...
...
@@ -620,11 +627,18 @@ def Registration(request):
return
HttpResponse
(
"the username or password already exist"
)
else
:
print
(
"agregado"
)
User
.
objects
.
create_user
(
first_name
=
request
.
POST
[
'name'
],
last_name
=
request
.
POST
[
'last_name'
],
username
=
request
.
POST
[
'username'
],
user
=
User
.
objects
.
create_user
(
first_name
=
request
.
POST
[
'name'
],
last_name
=
request
.
POST
[
'last_name'
],
username
=
request
.
POST
[
'username'
],
email
=
request
.
POST
[
'email'
],
password
=
request
.
POST
[
'password'
],
is_active
=
False
)
permissions
=
Permission
.
objects
.
filter
(
content_type__app_label
=
'auth'
,
codename__in
=
[
'advanced_search'
])
user
.
user_permissions
.
add
(
*
permissions
.
filter
(
content_type__model
=
'user'
))
message
=
"your registration is being processed"
subject
=
"Registro RepSat"
wsMail2
(
request
.
POST
[
'email'
],
request
.
POST
[
'username'
],
message
,
subject
)
messages
.
success
(
request
,
'your registration is being processed'
)
return
HttpResponseRedirect
(
'login'
)
reports/static/reports/css/Reports.css
View file @
669d1777
.map
{
height
:
400px
;
width
:
100%
;
}
.switch
{
position
:
relative
;
display
:
inline-block
;
...
...
reports/static/reports/css/scldata.css
View file @
669d1777
...
...
@@ -217,3 +217,37 @@ select::-ms-expand {
-o-transition
:
.25s
all
ease
;
transition
:
.25s
all
ease
;
}
.arrow_box
{
position
:
relative
;
background
:
#ffffff
;
border
:
1px
solid
#ffa74f
;
min-height
:
30px
;
bottom
:
10px
;
}
.arrow_box
:after
,
.arrow_box
:before
{
top
:
100%
;
left
:
50%
;
border
:
solid
transparent
;
content
:
" "
;
height
:
0
;
width
:
0
;
position
:
absolute
;
pointer-events
:
none
;
}
.arrow_box
:after
{
border-color
:
rgba
(
255
,
255
,
255
,
0
);
border-top-color
:
#ffffff
;
border-width
:
10px
;
margin-left
:
-10px
;
}
.arrow_box
:before
{
border-color
:
rgba
(
255
,
167
,
79
,
0
);
border-top-color
:
#ffa74f
;
border-width
:
11px
;
margin-left
:
-11px
;
}
users/static/users/js/scripts.js
View file @
669d1777
...
...
@@ -45,3 +45,4 @@ $(document).ready(function () {
order
:
[
1
,
'asc'
]
});
});
users/templates/profile.html
View file @
669d1777
{% load staticfiles %}
<style>
.switch
{
position
:
relative
;
display
:
inline-block
;
width
:
30px
;
height
:
17px
;
}
.switch
input
{
opacity
:
0
;
width
:
0
;
height
:
0
;
}
.slider
{
position
:
absolute
;
cursor
:
pointer
;
top
:
0
;
left
:
0
;
right
:
0
;
bottom
:
0
;
background-color
:
#ccc
;
-webkit-transition
:
.4s
;
transition
:
.4s
;
}
.slider
:before
{
position
:
absolute
;
content
:
""
;
height
:
13px
;
width
:
13px
;
left
:
4px
;
bottom
:
3px
;
background-color
:
white
;
-webkit-transition
:
.4s
;
transition
:
.4s
;
}
input
:checked
+
.slider
{
background-color
:
#f38e19
;
}
input
:focus
+
.slider
{
box-shadow
:
0
0
1px
#f38e19
;
}
input
:checked
+
.slider
:before
{
-webkit-transform
:
translateX
(
13px
);
-ms-transform
:
translateX
(
13px
);
transform
:
translateX
(
13px
);
}
/* Rounded sliders */
.slider.round
{
border-radius
:
14px
;
}
.slider.round
:before
{
border-radius
:
50%
;
}
</style>
<div
class=
"col-md-3"
>
{% for data in user_data %}
...
...
@@ -30,6 +92,23 @@
<i
class=
"fa fa-pie-chart margin-r-5"
></i>
<b>
Disk usage
</b>
<a
class=
"pull-right"
>
{{ data.size }}
</a>
</li>
<li
class=
"list-group-item"
>
<div
class=
"row ccontent "
>
<div
class=
"col-md-10 col-xs-10 col-lg-10 col-sm-10 col-xl-10"
>
<i
class=
"fa fa-search-plus margin-r-5"
></i>
<b>
Advanced Search
</b>
</div>
<div
class=
"col-md-2 col-xs-2 col-lg-2 col-sm-2 col-xl-2 pull-right"
>
<label
class=
"switch"
>
<input
class=
"pull-right"
id=
"{{ data.user_id }}"
type=
"checkbox"
onclick=
"change_permission({{ data.user_id }})"
{%
if
data
.
advanced_search =
=
True
%}
checked
{%
endif
%}
>
<span
class=
"slider round pull-right"
style=
"margin-right: 0px"
></span>
</label>
</div>
</div>
</li>
</ul>
<!--a href="#" class="btn btn-primary btn-block"><b>Follow</b></a-->
...
...
@@ -52,10 +131,10 @@
<div
class=
"box-body"
>
<ul
class=
"list-group list-group-unbordered"
>
{% for data in user_searches %}
<li
class=
"list-group-item"
>
<i
class=
"fa fa-map-marker margin-r-5"
></i>
<b>
{{ data.search_name }}
</b>
<a
class=
"pull-right"
>
{{ data.count }}
</a>
</li>
<li
class=
"list-group-item"
>
<i
class=
"fa fa-map-marker margin-r-5"
></i>
<b>
{{ data.search_name }}
</b>
<a
class=
"pull-right"
>
{{ data.count }}
</a>
</li>
{% endfor %}
</ul>
</div>
...
...
@@ -64,6 +143,29 @@
</div>
<!-- /.box -->
<div><br></div>
</div>
<script>
function
change_permission
(
user_id
)
{
var
checkBox
=
document
.
getElementById
(
user_id
);
if
(
checkBox
.
checked
==
true
)
{
permission
(
user_id
,
'True'
);
}
else
{
permission
(
user_id
,
'False'
);
}
}
function
permission
(
user_id
,
status
)
{
$
.
ajax
({
dataType
:
"json"
,
url
:
'ws/change_permission'
,
data
:
{
'user_id'
:
user_id
,
'status'
:
status
},
success
:
function
(
data
)
{
alert
(
data
);
}
});
}
</script>
\ No newline at end of file
users/urls.py
View file @
669d1777
...
...
@@ -27,5 +27,6 @@ urlpatterns = [
url
(
r'^$'
,
views
.
Users
,
name
=
'users'
),
url
(
r'^(?P<user_id>(\d+))/$'
,
views
.
User_id
,
name
=
'user_id'
),
url
(
r'^ws/report_table$'
,
views
.
wsPurchasesPM
,
name
=
'wsPurchasesPM'
),
url
(
r'^ws/change_permission'
,
views
.
wsChangePermission
,
name
=
'wsChangePermission'
),
]
# + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
users/views.py
View file @
669d1777
import
calendar
import
os
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
,
Permission
from
django.db.models
import
Count
from
django.http
import
HttpResponse
,
Http404
from
django.shortcuts
import
render
# Create your views here.
import
json
...
...
@@ -35,6 +36,15 @@ def Users(request):
purchases
=
Purchase
.
objects
.
filter
(
user_id
=
user
.
id
)
in_process
=
Purchase
.
objects
.
filter
(
user_id
=
user
.
id
)
.
exclude
(
progress
=
100
)
if
Permission
.
objects
.
filter
(
user
=
user
.
id
):
advanced_search
=
True
else
:
advanced_search
=
False
print
(
advanced_search
)
#bytes_size = 0
#for path, directories, files in os.walk(USERS_PATH + "repsat_test_dev/" + user.email):
# for filename in files:
...
...
@@ -50,11 +60,11 @@ def Users(request):
"searches"
:
searches
.
count
(),
"purchases"
:
purchases
.
count
(),
"in_process"
:
in_process
.
count
(),
#"size": size_repsat
,
"advanced_search"
:
advanced_search
,
})
for
search
in
Search
.
objects
.
values
(
'search_name'
)
.
filter
(
user_id
=
user
.
id
)
.
annotate
(
count
=
Count
(
'search_name'
))
.
order_by
(
'-count'
)[:
6
]:
count
=
Count
(
'search_name'
))
.
order_by
(
'-count'
)[:
5
]:
user_searches
.
append
({
"search_name"
:
search
[
'search_name'
],
"count"
:
search
[
'count'
],
...
...
@@ -173,7 +183,7 @@ def User_id(request, user_id):
})
for
search
in
Search
.
objects
.
values
(
'search_name'
)
.
filter
(
user_id
=
user
.
id
)
.
annotate
(
count
=
Count
(
'search_name'
))
.
order_by
(
'-count'
)[:
6
]:
count
=
Count
(
'search_name'
))
.
order_by
(
'-count'
)[:
5
]:
user_searches
.
append
({
"search_name"
:
search
[
'search_name'
],
"count"
:
search
[
'count'
],
...
...
@@ -338,3 +348,52 @@ def best_unit_size(bytes_size):
return
str
(
round
(
bu_size
,
2
))
+
" "
+
unit
# ------------------------------------------------
@
csrf_exempt
def
wsChangePermission
(
request
):
if
request
.
is_ajax
():
table_data
=
[]
data
=
Purchase
.
objects
.
values
(
'user_id'
,
'search__endDate'
,
'search__startDate'
,
'aggreg_date'
,
'search__process_id__name'
,
'name'
)
.
filter
(
user_id
=
request
.
POST
.
get
(
'user_id'
),
purchased
=
True
,
aggreg_date__month
=
to_if
(
request
.
POST
.
get
(
'title'
)))
.
order_by
(
'aggreg_date'
)
for
producto
in
data
:
table_data
.
append
({
"search_name"
:
producto
[
'name'
],
"process"
:
producto
[
'search__process_id__name'
],
"purchase_date"
:
str
(
producto
[
'aggreg_date'
])[:
10
],
"startDate"
:
str
(
producto
[
'search__startDate'
])[:
10
],
"endDate"
:
str
(
producto
[
'search__endDate'
])[:
10
],
})
return
HttpResponse
(
json
.
dumps
(
table_data
))
# return HttpResponse({'table_data':table_data})
else
:
raise
Http404
pass
#----------------------------------------------
@
csrf_exempt
def
wsChangePermission
(
request
):
if
request
.
is_ajax
():
permissions
=
Permission
.
objects
.
filter
(
content_type__app_label
=
'auth'
,
codename__in
=
[
'advanced_search'
])
user
=
User
.
objects
.
get
(
pk
=
request
.
GET
.
get
(
"user_id"
))
if
request
.
GET
.
get
(
"status"
)
==
'True'
:
print
(
"verdadero"
)
user
.
user_permissions
.
add
(
*
permissions
.
filter
(
content_type__model
=
'user'
))
else
:
print
(
"falso"
)
user
.
user_permissions
.
remove
(
*
permissions
.
filter
(
content_type__model
=
'user'
))
return
HttpResponse
(
"hola"
)
else
:
raise
Http404
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment