Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
39a7ffc9
authored
May 05, 2016
by
Estók Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
setty: added server-side access management.
parent
ea8d0946
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
161 additions
and
158 deletions
+161
-158
circle/setty/static/setty/setty.js
+122
-150
circle/setty/templates/setty/index.html
+3
-3
circle/setty/views.py
+36
-5
No files found.
circle/setty/static/setty/setty.js
View file @
39a7ffc9
/* Settimng up csrf token, touch event and zoom options. */
function
getCookie
(
name
)
{
var
cookieValue
=
null
;
if
(
document
.
cookie
&&
document
.
cookie
!==
''
)
{
...
...
@@ -83,98 +82,80 @@ jsPlumb.ready(function() {
var
nextStepConstraint
=
0
;
/* Functions. */
/* Functions. */
setServiceStatus
=
function
(
status
)
{
if
(
status
==
"unsaved"
)
{
$
(
"#serviceStatus"
).
text
(
"Unsaved"
);
}
else
{
$
(
"#serviceStatus"
).
text
(
gettext
(
"Unsaved"
));
}
else
{
$
(
"#serviceStatus"
).
empty
();
}
};
addInfo
=
function
(
title
,
info
,
type
,
object
)
{
/*
$("#informationContainer").empty();
switch(type){
case "connection":
div =
'<div class="row">' +
'<div class="col-xs-12 text-center">' +
'<h4>' + title + '</h4>' +
'</div>' +
'</div> ' +
'<div class="row">' +
'<div class="col-xs-12">' +
'<textarea class="form-control" rows="28" id="infoInput" placeholder="Config data"></textarea>' +
'</div>' +
'</div> ' +
'<div class="row">' +
'<div class="col-xs-12 text-center">' +
'<button id="removeConnection" class="btn btn-info">Remove connection</button>' +
'</div>' +
'</div>';
break;
case "element":
div =
'<div class="row">' +
'<div class="col-xs-12 text-center">' +
'<h4>' + title + '</h4>' +
'</div>' +
'</div> ' +
'<div class="row">' +
'<div class="col-xs-12">' +
'<textarea class="form-control" rows="24" id="infoInput" placeholder="Config data"></textarea>' +
'</div>' +
'</div> ' +
'<div class="row text-center">' +
'<label>Endpoints</label>' +
'</div>' +
'<div class="row">' +
'<div class="col-xs-6 text-center">' +
'<button id="addEndpoint" class="btn btn-success"><i class="fa fa-plus"></i></button>' +
'</div>' +
'<div class="col-xs-6 text-center">' +
'<button id="removeEndpoint" class="btn btn-danger"><i class="fa fa-minus"></i></button>' +
'</div>' +
'</div> ' +
'<div class="row">' +
'<div class="col-xs-12 text-center">' +
'<button id="removeElementFromWorkspace" class="btn btn-info">Remove from workspace</button>' +
'</div>' +
'</div>';
break;
case "elementTemplate":
div =
'<div class="row">' +
'<div class="col-xs-12 text-center">' +
'<h4>' + title + '</h4>' +
'</div>' +
'</div> ' +
'<div class="row">' +
'<div class="col-xs-12">' +
'<textarea class="form-control" rows="28" id="infoInput" placeholder="Config data"></textarea>' +
'</div>' +
'</div> ' +
'<div class="row">' +
'<div class="col-xs-12 text-center">' +
'<button id="addElementToWorkspace" class="btn btn-success">Add to workspace</button>' +
'</div>' +
'</div>';
break;
}*/
// Here comes the ajax getInformation post.
// elementtemplateid vagy hostname
div
=
0
;
$
(
"#informationContainer"
).
append
(
div
);
$
(
"#infoInput"
).
val
(
info
);
addInfo
=
function
(
title
,
info
,
object
,
type
)
{
mainDiv
=
$
(
"<div>"
,
{
class
:
"row"
,
html
:
$
(
"<div>"
,
{
class
:
"col-xs-12 text-center"
,
html
:
row
=
$
(
"<h4>"
,
{
html
:
title
})
})
}).
add
(
$
(
"<div>"
,
{
class
:
"row"
,
style
:
"margin-top: 16px"
,
html
:
$
(
"<div>"
,
{
class
:
"col-xs-12 text-center"
,
html
:
row
=
$
(
"<textarea>"
,
{
class
:
"form-control"
,
style
:
"text-align: justify;"
,
rows
:
"18"
,
id
:
"infoInput"
,
disabled
:
!
type
,
text
:
info
})
})
}));
controlDiv
=
$
(
"<div>"
,
{
class
:
"row"
,
style
:
"margin-top: 16px"
,
html
:
$
(
"<div>"
,
{
class
:
"col-xs-3 text-center"
,
html
:
$
(
"<button>"
,
{
class
:
"btn btn-success btn-block"
,
id
:
"addEndpoint"
,
html
:
gettext
(
"Add endpoint"
)
})
}).
add
(
$
(
"<div>"
,
{
class
:
"col-xs-3 text-center"
,
html
:
$
(
"<button>"
,
{
class
:
"btn btn-danger btn-block"
,
id
:
"removeEndpoint"
,
html
:
gettext
(
"Delete endpoint"
)
})
})).
add
(
$
(
"<div>"
,
{
class
:
"col-xs-6 text-center"
,
html
:
$
(
"<button>"
,
{
class
:
"btn btn-info btn-block"
,
id
:
"removeElementFromWorkspace"
,
html
:
gettext
(
"Remove from workspace"
)
})
}))
});
addElementDiv
=
$
(
"<div>"
,
{
class
:
"row"
,
style
:
"margin-top: 16px"
,
html
:
$
(
"<div>"
,
{
class
:
"col-xs-12 text-center"
,
html
:
row
=
$
(
"<button>"
,
{
class
:
"btn btn-success"
,
id
:
"addElementToWorkspace"
,
html
:
gettext
(
"Add to workspace"
)
})
})
});
$
(
"#informationContainer"
).
html
(
type
?
mainDiv
.
add
(
controlDiv
):
mainDiv
.
add
(
addElementDiv
));
$
(
"#changeInformationDialog"
).
modal
(
'show'
);
...
...
@@ -211,7 +192,7 @@ jsPlumb.ready(function() {
elementConnections
[
i
].
sourceId
==
connection
.
targetId
))
&&
elementConnections
[
i
]
!=
connection
)
{
addMessage
(
"Twofold connection is forbidden."
,
"danger"
);
addMessage
(
gettext
(
"Twofold connection is forbidden."
),
"danger"
);
return
false
;
}
}
...
...
@@ -222,7 +203,7 @@ jsPlumb.ready(function() {
validTargets
=
$
(
"#"
+
sourceId
).
attr
(
"type"
).
split
(
','
);
if
(
jQuery
.
inArray
(
targetId
.
split
(
'_'
)[
1
],
validTargets
)
==
-
1
)
{
addMessage
(
"Connecting incompatible elements is forbidden."
,
"danger"
);
addMessage
(
gettext
(
"Connecting incompatible elements is forbidden."
),
"danger"
);
return
false
;
}
return
true
;
...
...
@@ -230,7 +211,7 @@ jsPlumb.ready(function() {
checkSourceTargetEquality
=
function
(
connection
)
{
if
(
connection
.
targetId
==
connection
.
sourceId
)
{
addMessage
(
"Connecting element to itself is forbidden."
,
"danger"
);
addMessage
(
gettext
(
"Connecting element to itself is forbidden."
),
"danger"
);
return
false
;
}
return
true
;
...
...
@@ -284,10 +265,8 @@ jsPlumb.ready(function() {
anchors
=
element
.
attr
(
"anchors"
);
id
=
element
.
attr
(
"id"
);
for
(
i
=
0
;
i
<
anchors
;
i
++
)
{
if
(
isConnected
(
i
+
"_"
+
id
))
{
for
(
i
=
0
;
i
<
anchors
;
i
++
)
{
if
(
isConnected
(
i
+
"_"
+
id
))
{
return
true
;
}
}
...
...
@@ -319,7 +298,7 @@ jsPlumb.ready(function() {
addEndpoint
=
function
(
element
)
{
anchors
=
element
.
attr
(
"anchors"
);
if
(
anchors
==
8
)
return
;
if
(
anchors
==
8
)
return
1
;
anchors
++
;
...
...
@@ -335,19 +314,21 @@ jsPlumb.ready(function() {
element
.
attr
(
"anchors"
,
anchors
);
jsPlumbInstance
.
repaintEverything
();
return
0
;
};
removeEndoint
=
function
(
element
)
{
anchors
=
element
.
attr
(
"anchors"
);
if
(
anchors
==
4
)
return
;
if
(
anchors
==
4
)
return
1
;
i
=
--
anchors
;
while
(
isConnected
(
i
+
"_"
+
element
.
attr
(
"id"
))
&&
i
>=
0
)
i
--
;
if
(
i
==
-
1
)
{
addMessage
(
"Removing anchors is obstructed."
,
"danger"
);
addMessage
(
gettext
(
"Removing anchors is obstructed."
),
"danger"
);
return
;
}
else
if
(
i
==
anchors
)
{
jsPlumbInstance
.
deleteEndpoint
(
jsPlumbInstance
.
getEndpoint
(
anchors
+
"_"
+
element
.
attr
(
"id"
)));
...
...
@@ -369,6 +350,8 @@ jsPlumb.ready(function() {
element
.
attr
(
"anchors"
,
anchors
);
jsPlumbInstance
.
repaintEverything
();
return
0
;
};
connectEndpoints
=
function
(
data
)
{
...
...
@@ -436,7 +419,7 @@ jsPlumb.ready(function() {
};
/* Registering events using JsPlumb. */
/* Registering events using JsPlumb. */
jsPlumbInstance
.
bind
(
"connection"
,
function
(
info
)
{
updateConnections
(
info
.
connection
);
...
...
@@ -485,20 +468,12 @@ jsPlumb.ready(function() {
jsPlumbInstance
.
detach
(
info
);
});
jsPlumbInstance
.
bind
(
"dblclick"
,
function
(
info
)
{
info
.
setPaintStyle
({
strokeStyle
:
"red"
,
lineWidth
:
8
});
addInfo
(
$
(
"#"
+
info
.
sourceId
.
split
(
'_'
)[
1
]).
attr
(
"alt"
)
+
' - '
+
$
(
"#"
+
info
.
targetId
.
split
(
'_'
)[
1
]).
attr
(
"alt"
),
info
.
parameters
,
"connection"
,
info
);
});
jsPlumbInstance
.
draggable
(
jsPlumb
.
getSelector
(
".element"
),
{
containment
:
$
(
"#dropContainer"
)
});
/* Registering events using JQuery. */
/* Registering events using JQuery. */
$
(
'body'
).
on
(
'click'
,
'.elementTemplate'
,
function
()
{
addElement
(
$
(
this
).
attr
(
"id"
),
...
...
@@ -518,7 +493,7 @@ jsPlumb.ready(function() {
element
.
addClass
(
"elementSelected"
);
addInfo
(
element
.
attr
(
"alt"
),
element
.
attr
(
"parameters"
),
"element"
,
element
);
element
,
1
);
$
(
document
).
scrollTop
(
0
);
});
...
...
@@ -535,21 +510,16 @@ jsPlumb.ready(function() {
stackIndexer
++
;
});
$
(
'body'
).
on
(
'click'
,
'#closeInfoPanel'
,
function
()
{
$
(
'#informationPanel'
).
hide
();
$
(
'#dragPanel'
).
show
();
});
$
(
'body'
).
on
(
'keyUp'
,
'#infoInput'
,
function
()
{
$
(
'body'
).
on
(
'keyup'
,
'#infoInput'
,
function
()
{
setServiceStatus
(
"unsaved"
);
newParams
=
$
(
"#infoInput"
).
val
();
if
(
type
==
"connection"
)
object
.
parameters
=
newParams
;
if
(
type
==
"element"
)
object
.
attr
(
"parameters"
,
newParams
);
sharedObject
.
attr
(
"parameters"
,
newParams
);
});
$
(
'body'
).
on
(
'click'
,
'#addEndpoint'
,
function
()
{
addEndpoint
(
sharedObject
);
setServiceStatus
(
"unsaved"
);
if
(
addEndpoint
(
sharedObject
))
return
;
undoStack
.
splice
(
stackIndexer
,
0
,
removeEndoint
);
redoStack
.
splice
(
stackIndexer
,
0
,
addEndpoint
);
objectStack
.
splice
(
stackIndexer
,
0
,
sharedObject
);
...
...
@@ -558,7 +528,8 @@ jsPlumb.ready(function() {
});
$
(
'body'
).
on
(
'click'
,
'#removeEndpoint'
,
function
()
{
removeEndoint
(
sharedObject
);
setServiceStatus
(
"unsaved"
);
if
(
removeEndoint
(
sharedObject
))
return
;
undoStack
.
splice
(
stackIndexer
,
0
,
addEndpoint
);
redoStack
.
splice
(
stackIndexer
,
0
,
removeEndoint
);
objectStack
.
splice
(
stackIndexer
,
0
,
sharedObject
);
...
...
@@ -575,6 +546,8 @@ jsPlumb.ready(function() {
objectStack
.
splice
(
stackIndexer
,
0
,
sharedObject
);
stackSize
++
;
stackIndexer
++
;
$
(
"#changeInformationDialog"
).
modal
(
'hide'
);
});
$
(
'body'
).
on
(
'click'
,
'#removeConnection'
,
function
()
{
...
...
@@ -595,7 +568,7 @@ jsPlumb.ready(function() {
});
$
(
'body'
).
on
(
'click'
,
'#clearService'
,
function
()
{
jsPlumbInstance
.
remove
(
"element"
);
//Todo
setServiceStatus
(
"unsaved"
);
elementIndex
=
0
;
...
...
@@ -620,16 +593,12 @@ jsPlumb.ready(function() {
});
$
(
'body'
).
on
(
'click'
,
'#addMachineDialog'
,
function
()
{
// Here comes the ajax post of getMachineAvailableList
// posting usedhostnames
//
//
// after it, appending obtained content to addmachinedialogbody
// Here comes the ajax post of getting machines
});
$
(
'body'
).
on
(
'click'
,
'.elementTemplateInfo'
,
function
()
{
id
=
$
(
this
).
attr
(
"element"
);
addInfo
(
$
(
"#"
+
id
).
attr
(
"alt"
),
$
(
"#"
+
id
).
attr
(
"desc"
),
"elementTemplate"
,
$
(
"#"
+
id
));
addInfo
(
$
(
"#"
+
id
).
attr
(
"alt"
),
$
(
"#"
+
id
).
attr
(
"desc"
),
$
(
"#"
+
id
),
0
);
});
$
(
'body'
).
on
(
'click'
,
'#serviceName'
,
function
()
{
...
...
@@ -653,9 +622,8 @@ jsPlumb.ready(function() {
scrollContainer
(
1
);
});
$
(
'body'
).
on
(
'hide.bs.modal'
,
'#changeInformationDialog'
,
function
()
{
$
(
'body'
).
on
(
'hide.bs.modal'
,
'#changeInformationDialog'
,
function
()
{
$
(
'.element'
).
removeClass
(
'elementSelected'
);
jsPlumbInstance
.
select
().
setPaintStyle
({
strokeStyle
:
'#9932cc'
,
lineWidth
:
8
});
});
$
(
'body'
).
on
(
'keyup'
,
'#searchElementTemplate'
,
function
()
{
...
...
@@ -688,52 +656,53 @@ jsPlumb.ready(function() {
var
eventObject
=
window
.
event
?
event
:
e
;
// Undo (CTRL + Z)
if
(
eventObject
.
keyCode
==
90
&&
eventObject
.
ctrlKey
)
{
if
(
eventObject
.
keyCode
==
90
&&
eventObject
.
ctrlKey
)
{
eventObject
.
preventDefault
();
$
(
'#undoMovement'
).
click
();
}
// Redo (CTRL + Y)
if
(
eventObject
.
keyCode
==
89
&&
eventObject
.
ctrlKey
)
{
if
(
eventObject
.
keyCode
==
89
&&
eventObject
.
ctrlKey
)
{
eventObject
.
preventDefault
();
$
(
'#redoMovement'
).
click
();
}
// Add element (CTRL + A)
if
(
eventObject
.
keyCode
==
65
&&
eventObject
.
ctrlKey
)
{
if
(
eventObject
.
keyCode
==
65
&&
eventObject
.
ctrlKey
)
{
eventObject
.
preventDefault
();
$
(
'#showAddElementDialog'
).
click
();
}
// Clean (CTRL + C)
if
(
eventObject
.
keyCode
==
67
&&
eventObject
.
ctrlKey
)
{
if
(
eventObject
.
keyCode
==
67
&&
eventObject
.
ctrlKey
)
{
eventObject
.
preventDefault
();
$
(
'#clearService'
).
click
();
}
// Save (CTRL + S)
if
(
eventObject
.
keyCode
==
83
&&
eventObject
.
ctrlKey
)
{
if
(
eventObject
.
keyCode
==
83
&&
eventObject
.
ctrlKey
)
{
eventObject
.
preventDefault
();
$
(
'#saveService'
).
click
();
}
// Delete (CTRL + D)
if
(
eventObject
.
keyCode
==
68
&&
eventObject
.
ctrlKey
)
{
if
(
eventObject
.
keyCode
==
68
&&
eventObject
.
ctrlKey
)
{
eventObject
.
preventDefault
();
$
(
'#deleteService'
).
click
();
}
// Close dialog (ESC)
if
(
eventObject
.
keyCode
==
27
)
{
eventObject
.
preventDefault
();
$
(
"#changeInformationDialog"
).
modal
(
'hide'
);
$
(
"#addElementDialog"
).
modal
(
'hide'
);
}
});
$
(
window
).
on
(
'resize'
,
function
()
{
$
(
".element"
).
each
(
function
()
{
rate
=
(
$
(
this
).
position
().
left
)
/
workspaceWidth
;
left
=
rate
*
(
$
(
"#dropContainer"
).
width
());
rate
=
(
$
(
this
).
position
().
left
)
/
workspaceWidth
;
left
=
rate
*
(
$
(
"#dropContainer"
).
width
());
$
(
this
).
css
(
"left"
,
left
);
});
workspaceWidth
=
$
(
"#dropContainer"
).
width
();
...
...
@@ -741,7 +710,7 @@ jsPlumb.ready(function() {
});
/* Registering events concerning persistence. */
/* Registering events concerning persistence. */
$
(
'body'
).
on
(
'click'
,
'#saveService'
,
function
()
{
serviceName
=
$
(
"#serviceName"
).
text
();
...
...
@@ -754,16 +723,18 @@ jsPlumb.ready(function() {
"sourceEndpoint"
:
elementConnections
[
index
].
endpoints
[
0
].
getUuid
(),
"targetId"
:
elementConnections
[
index
].
targetId
,
"targetEndpoint"
:
elementConnections
[
index
].
endpoints
[
1
].
getUuid
(),
"parameters"
:
elementConnections
[
index
].
parameters
});
"parameters"
:
elementConnections
[
index
].
parameters
});
});
$
.
each
(
$
(
".element"
),
function
()
{
instanceSet
.
push
({
"displayId"
:
$
(
this
).
prop
(
"id"
),
"positionLeft"
:
$
(
this
).
position
().
left
/
workspaceWidth
,
"positionTop"
:
$
(
this
).
position
().
top
/
workspaceHeight
,
"positionLeft"
:
$
(
this
).
position
().
left
/
workspaceWidth
,
"positionTop"
:
$
(
this
).
position
().
top
/
workspaceHeight
,
"anchorNumber"
:
$
(
this
).
attr
(
"anchors"
),
"parameters"
:
$
(
this
).
attr
(
"parameters"
)});
"parameters"
:
$
(
this
).
attr
(
"parameters"
)
});
});
$
.
post
(
""
,
{
...
...
@@ -771,15 +742,16 @@ jsPlumb.ready(function() {
data
:
JSON
.
stringify
({
"serviceName"
:
serviceName
,
"elementConnections"
:
connectionSet
,
"elements"
:
instanceSet
})
"elements"
:
instanceSet
})
},
function
(
result
)
{
addMessage
(
result
.
serviceName
+
" saved successfully."
,
"success"
);
addMessage
(
result
.
serviceName
+
gettext
(
" saved successfully."
),
"success"
);
setServiceStatus
(
"saved"
);
});
});
$
(
document
).
ready
(
function
()
{
if
(
!
$
(
"#dropContainer"
).
length
)
return
;
// Protection for not posting sites that differ from setty sites.
if
(
!
$
(
"#dropContainer"
).
length
)
return
;
// Protection for not posting sites that differ from setty sites.
$
.
post
(
""
,
{
event
:
"loadService"
},
function
(
result
)
{
...
...
@@ -788,10 +760,10 @@ jsPlumb.ready(function() {
$
.
each
(
result
.
elements
,
function
(
i
,
element
)
{
addElement
(
element
.
displayId
.
split
(
'_'
)[
1
],
element
.
displayId
,
(
element
.
positionTop
*
workspaceHeight
)
+
"px"
,
(
element
.
positionTop
*
workspaceHeight
)
+
"px"
,
element
.
anchorNumber
,
element
.
parameters
,
(
element
.
positionLeft
*
workspaceWidth
)
+
"px"
);
(
element
.
positionLeft
*
workspaceWidth
)
+
"px"
);
if
(
elementIndex
<
element
.
displayId
.
split
(
'_'
)[
0
])
elementIndex
=
element
.
displayId
.
split
(
'_'
)[
0
];
elementIndex
++
;
...
...
circle/setty/templates/setty/index.html
View file @
39a7ffc9
...
...
@@ -118,14 +118,14 @@
</div>
<div
class=
"panel-body container-fluid"
id=
"dragContainer"
>
{% for element in elementTemplateList %}
<div
class=
"col-md-
12
col-sm-4"
id=
"elementTemplatePanel"
>
<div
class=
"col-md-
6
col-sm-4"
id=
"elementTemplatePanel"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<div
class=
"row text-center"
>
<div
class=
"col-xs-
10 col-xs-push-1
text-center"
>
<div
class=
"col-xs-
8 col-xs-push-2
text-center"
>
<label
class=
"no-margin"
>
{{ element.name }}
</label>
</div>
<div
class=
"col-xs-
1 col-xs-push-1 text-righ
t"
>
<div
class=
"col-xs-
2 col-xs-push-2 text-lef
t"
>
<button
class=
"btn btn-primary btn-xs elementTemplateInfo"
element=
"{{ element.id }}"
>
<i
class=
"fa fa-info"
></i>
</button>
...
...
circle/setty/views.py
View file @
39a7ffc9
...
...
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
django.contrib
import
messages
# NOTE: ezt tettem ide
from
django.contrib
import
messages
from
django.core.exceptions
import
PermissionDenied
from
django.core.urlresolvers
import
reverse
,
reverse_lazy
from
django.db.models
import
Q
...
...
@@ -41,12 +41,24 @@ class DetailView(LoginRequiredMixin, TemplateView):
template_name
=
"setty/index.html"
def
get_context_data
(
self
,
**
kwargs
):
logger
.
debug
(
'DetailView.get_context_data() called. User:
%
s'
,
unicode
(
self
.
request
.
user
))
service
=
Service
.
objects
.
get
(
id
=
kwargs
[
'pk'
])
if
self
.
request
.
user
==
service
.
user
or
self
.
request
.
user
.
is_superuser
:
context
=
super
(
DetailView
,
self
)
.
get_context_data
(
**
kwargs
)
context
[
'elementTemplateList'
]
=
ElementTemplate
.
objects
.
all
()
context
[
'actualId'
]
=
kwargs
[
'pk'
]
return
context
else
:
raise
PermissionDenied
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
logger
.
debug
(
'DetailView.post() called. User:
%
s'
,
unicode
(
self
.
request
.
user
))
service
=
Service
.
objects
.
get
(
id
=
kwargs
[
'pk'
])
if
self
.
request
.
user
==
service
.
user
or
self
.
request
.
user
.
is_superuser
:
if
self
.
request
.
POST
.
get
(
'event'
)
==
"saveService"
:
data
=
json
.
loads
(
self
.
request
.
POST
.
get
(
'data'
))
service
=
Service
.
objects
.
get
(
id
=
kwargs
[
'pk'
])
...
...
@@ -122,15 +134,26 @@ class DetailView(LoginRequiredMixin, TemplateView):
else
:
raise
PermissionDenied
else
:
raise
PermissionDenied
class
DeleteView
(
LoginRequiredMixin
,
DeleteView
):
model
=
Service
success_url
=
reverse_lazy
(
"dashboard.index"
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
logger
.
debug
(
'DeleteView.post() called. User:
%
s'
,
unicode
(
self
.
request
.
user
))
service
=
Service
.
objects
.
get
(
id
=
kwargs
[
'pk'
])
if
self
.
request
.
user
==
service
.
user
or
self
.
request
.
user
.
is_superuser
:
return
super
(
DeleteView
,
self
)
.
post
(
request
,
*
args
,
**
kwargs
)
else
:
return
PermissionDenied
class
CreateView
(
LoginRequiredMixin
,
TemplateView
):
class
CreateView
(
LoginRequiredMixin
,
TemplateView
):
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
return
[
'dashboard/_modal.html'
]
...
...
@@ -138,6 +161,8 @@ class CreateView(LoginRequiredMixin, TemplateView):
return
[
'dashboard/nojs-wrapper.html'
]
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
logger
.
debug
(
'CreateView.get_context_data() called. User:
%
s'
,
unicode
(
self
.
request
.
user
))
context
=
super
(
CreateView
,
self
)
.
get_context_data
(
*
args
,
**
kwargs
)
context
.
update
({
...
...
@@ -148,6 +173,8 @@ class CreateView(LoginRequiredMixin, TemplateView):
return
context
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
logger
.
debug
(
'CreateView.post() called. User:
%
s'
,
unicode
(
self
.
request
.
user
))
service_name
=
self
.
request
.
POST
.
get
(
'serviceName'
)
if
not
service_name
:
...
...
@@ -181,11 +208,15 @@ class ListView(LoginRequiredMixin, FilterMixin, SingleTableView):
}
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
logger
.
debug
(
'ListView.get_context_data() called. User:
%
s'
,
unicode
(
self
.
request
.
user
))
context
=
super
(
ListView
,
self
)
.
get_context_data
(
*
args
,
**
kwargs
)
context
[
'search_form'
]
=
self
.
search_form
return
context
def
get
(
self
,
*
args
,
**
kwargs
):
logger
.
debug
(
'ListView.get() called. User:
%
s'
,
unicode
(
self
.
request
.
user
))
self
.
search_form
=
ServiceListSearchForm
(
self
.
request
.
GET
)
self
.
search_form
.
full_clean
()
...
...
@@ -203,14 +234,14 @@ class ListView(LoginRequiredMixin, FilterMixin, SingleTableView):
return
super
(
ListView
,
self
)
.
get
(
*
args
,
**
kwargs
)
def
get_queryset
(
self
):
logger
.
debug
(
'ListView.get
_queryset() called. User:
%
s'
,
logger
.
debug
(
'ListView.get_queryset() called. User:
%
s'
,
unicode
(
self
.
request
.
user
))
qs
=
self
.
model
.
objects
.
all
()
self
.
create_fake_get
()
# NOTE: ezt tettem ide
self
.
create_fake_get
()
try
:
filters
,
excludes
=
self
.
get_queryset_filters
()
if
not
self
.
request
.
user
.
is_superuser
:
filters
[
'user'
]
=
self
.
request
.
user
# NOTE: ezt visszairtam
filters
[
'user'
]
=
self
.
request
.
user
qs
=
qs
.
filter
(
**
filters
)
.
exclude
(
**
excludes
)
.
distinct
()
except
ValueError
:
messages
.
error
(
self
.
request
,
_
(
"Error during filtering."
))
...
...
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