Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MyMovieLibrary
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
MyMovieLibrary
Commits
36771e20
Commit
36771e20
authored
11 years ago
by
Brian Wood
Browse files
Options
Downloads
Patches
Plain Diff
You can now return loaned movies
parent
fa02287d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
project/controllers/loan.py
+25
-2
25 additions, 2 deletions
project/controllers/loan.py
project/templates/library/library.html
+33
-0
33 additions, 0 deletions
project/templates/library/library.html
with
58 additions
and
2 deletions
project/controllers/loan.py
+
25
−
2
View file @
36771e20
...
@@ -45,7 +45,6 @@ def reminderEmail(user=None):
...
@@ -45,7 +45,6 @@ def reminderEmail(user=None):
@app.route
(
'
/loan-movie
'
,
methods
=
[
'
POST
'
])
@app.route
(
'
/loan-movie
'
,
methods
=
[
'
POST
'
])
@security
(
'
user
'
)
@security
(
'
user
'
)
def
createLoan
(
user
=
None
):
def
createLoan
(
user
=
None
):
import
smtplib
from
datetime
import
datetime
from
datetime
import
datetime
borrower
=
request
.
form
[
'
email
'
]
borrower
=
request
.
form
[
'
email
'
]
return_date
=
request
.
form
[
'
date
'
]
or
None
return_date
=
request
.
form
[
'
date
'
]
or
None
...
@@ -71,3 +70,27 @@ def createLoan(user=None):
...
@@ -71,3 +70,27 @@ def createLoan(user=None):
borrowed_lib
.
addUnit
(
movie
)
borrowed_lib
.
addUnit
(
movie
)
return
jsonify
(
response
=
'
success
'
,
type
=
"
reload
"
)
return
jsonify
(
response
=
'
success
'
,
type
=
"
reload
"
)
@app.route
(
'
/return-movie
'
,
methods
=
[
'
POST
'
])
@security
(
'
user
'
)
def
returnMovie
(
user
=
None
):
movie_id
=
request
.
form
[
'
id
'
]
if
not
movie_id
:
return
jsonify
(
response
=
'
error
'
,
message
=
'
Invalid Movie given
'
),
404
from
project.model.Movie
import
Movie
movie
=
Movie
.
objects
(
id
=
movie_id
).
first
()
if
not
movie
:
return
jsonify
(
response
=
'
error
'
,
message
=
'
Invalid Movie given
'
),
404
from
project.model.Loan
import
Loan
loan
=
Loan
.
objects
(
user
=
user
,
movie
=
movie
).
first
()
if
not
loan
:
return
jsonify
(
response
=
'
error
'
,
message
=
'
This movie has not been loaned out and cannot be returned
'
),
404
from
project.model.Library
import
Library
borrowed_lib
=
Library
.
objects
(
user
=
user
,
unit
=
"
Movie
"
,
name
=
"
Borrowed
"
).
first
()
borrowed_lib
.
removeUnit
(
movie
)
loan
.
delete
()
return
jsonify
(
response
=
'
success
'
,
type
=
"
reload
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
project/templates/library/library.html
+
33
−
0
View file @
36771e20
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
<button
type=
"button"
class=
"btn btn-default btn-small lend-movie"
data-toggle=
"modal"
data-target=
"#loan-form"
data-id=
'{{ movie.id }}'
>
Lend
</button>
<button
type=
"button"
class=
"btn btn-default btn-small lend-movie"
data-toggle=
"modal"
data-target=
"#loan-form"
data-id=
'{{ movie.id }}'
>
Lend
</button>
{% else %}
{% else %}
This movie is loaned to {{ loan.email }} and is due back on {{ loan.expected_return_date.strftime('%m-%d-%Y') }}
This movie is loaned to {{ loan.email }} and is due back on {{ loan.expected_return_date.strftime('%m-%d-%Y') }}
<button
type=
"button"
class=
"btn btn-default btn-small return-movie"
data-toggle=
"modal"
data-target=
"#return-form"
data-id=
'{{ movie.id }}'
>
Return
</button>
{% endif %}
{% endif %}
{% if library.name != "Master" or loan == None %}
{% if library.name != "Master" or loan == None %}
<button
type=
"button"
class=
"btn btn-default btn-small remove-movie"
data-id=
'{{ loop.index }}'
>
Remove
</button>
<button
type=
"button"
class=
"btn btn-default btn-small remove-movie"
data-id=
'{{ loop.index }}'
>
Remove
</button>
...
@@ -61,6 +62,7 @@
...
@@ -61,6 +62,7 @@
<button
type=
"button"
class=
"btn btn-default btn-small lend-movie"
data-toggle=
"modal"
data-target=
"#loan-form"
data-id=
'{{ movie.id }}'
>
Lend
</button>
<button
type=
"button"
class=
"btn btn-default btn-small lend-movie"
data-toggle=
"modal"
data-target=
"#loan-form"
data-id=
'{{ movie.id }}'
>
Lend
</button>
{% else %}
{% else %}
This movie is loaned to {{ loan.borrower_email }} and is due back on {{ loan.expected_return_date.strftime('%m-%d-%Y') }}
This movie is loaned to {{ loan.borrower_email }} and is due back on {{ loan.expected_return_date.strftime('%m-%d-%Y') }}
<button
type=
"button"
class=
"btn btn-default btn-small return-movie"
data-toggle=
"modal"
data-target=
"#return-form"
data-id=
'{{ movie.id }}'
>
Return
</button>
{% endif %}
{% endif %}
{% if library.name != "Master" or loan == None %}
{% if library.name != "Master" or loan == None %}
<button
type=
"button"
class=
"btn btn-default btn-small remove-movie"
data-id=
'{{ loop.index }}'
>
Remove
</button>
<button
type=
"button"
class=
"btn btn-default btn-small remove-movie"
data-id=
'{{ loop.index }}'
>
Remove
</button>
...
@@ -120,6 +122,37 @@
...
@@ -120,6 +122,37 @@
}
}
});
});
var
returnPath
=
'
{{ url_for("returnMovie") }}
'
;
$
(
'
.return-movie
'
).
on
(
'
click
'
,
function
(
event
){
var
movie_id
=
$
(
this
).
data
(
'
id
'
);
var
message
=
"
Are you sure you want return this movie?
"
;
if
(
confirm
(
message
)){
event
.
stopPropagation
();
event
.
preventDefault
();
$
.
ajax
({
url
:
returnPath
,
data
:
{
id
:
movie_id
},
method
:
'
POST
'
,
success
:
function
(
data
,
status
,
jqXHR
){
if
(
data
[
'
response
'
]
==
'
success
'
){
if
(
data
[
'
type
'
]
==
'
redirect
'
){
window
.
document
.
location
=
data
[
'
path
'
];
}
else
if
(
data
[
'
type
'
]
==
'
reload
'
)
{
window
.
document
.
location
.
reload
();
}
}
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
){
response
=
jqXHR
.
responseJSON
;
if
(
'
message
'
in
response
){
alert
(
response
[
'
message
'
]);
}
}
});
}
});
});
});
</script>
</script>
{% endblock %}
{% endblock %}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment