Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
bookshare
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
30
Issues
30
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
SRCT
bookshare
Commits
6f469ea2
Commit
6f469ea2
authored
Mar 03, 2020
by
Daniel W Bond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added comments, removed duplicated code in CreateFlag
parent
c580cbce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
16 deletions
+14
-16
bookshare/trades/views.py
bookshare/trades/views.py
+14
-16
No files found.
bookshare/trades/views.py
View file @
6f469ea2
...
...
@@ -192,6 +192,7 @@ class ListingPage(View):
if
self
.
request
.
user
.
is_authenticated
:
view
=
CreateBid
.
as_view
()
return
view
(
request
,
*
args
,
**
kwargs
)
# the nonauthenticated version cannot post
else
:
pass
...
...
@@ -204,15 +205,17 @@ class CreateFlag(LoginRequiredMixin, CreateView):
context_object_name
=
'flag'
login_url
=
'login'
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
me
=
self
.
request
.
user
.
student
# duplicated code!!!
current_url
=
self
.
request
.
get_full_path
()
def
parse_url_for_listing
(
self
,
request
):
# there's possibly a better way than url parsing, but here we are
current_url
=
request
.
get_full_path
()
listing_slug
=
current_url
.
split
(
'/'
)[
3
]
# [u'', u'share', u'listing', u'C1s3oD', u'flag']
selected_listing
=
Listing
.
objects
.
get
(
slug
=
listing_slug
)
return
Listing
.
objects
.
get
(
slug
=
listing_slug
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
me
=
self
.
request
.
user
.
student
selected_listing
=
self
.
parse_url_for_listing
(
self
.
request
)
posting_student
=
selected_listing
.
poster
# can only create a flag if you haven't previously created one
...
...
@@ -229,23 +232,14 @@ class CreateFlag(LoginRequiredMixin, CreateView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
CreateFlag
,
self
).
get_context_data
(
**
kwargs
)
me
=
self
.
request
.
user
.
student
# duplicated code!!!
current_url
=
self
.
request
.
get_full_path
()
listing_slug
=
current_url
.
split
(
'/'
)[
3
]
# [u'', u'share', u'listing', u'C1s3oD', u'flag']
selected_listing
=
Listing
.
objects
.
get
(
slug
=
listing_slug
)
selected_listing
=
self
.
parse_url_for_listing
(
self
.
request
)
context
[
'listing'
]
=
selected_listing
return
context
def
form_valid
(
self
,
form
):
me
=
self
.
request
.
user
.
student
current_url
=
self
.
request
.
get_full_path
()
listing_slug
=
current_url
.
split
(
'/'
)[
3
]
# [u'', u'share', u'listing', u'C1s3oD', u'flag']
selected_listing
=
Listing
.
objects
.
get
(
slug
=
listing_slug
)
selected_listing
=
self
.
parse_url_for_listing
(
self
.
request
)
form
.
instance
.
flagger
=
me
form
.
instance
.
listing
=
selected_listing
...
...
@@ -422,9 +416,11 @@ class EditListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
me
=
self
.
request
.
user
.
student
posting_student
=
self
.
get_object
().
poster
# can't edit a bid on a cancelled listing
if
(
self
.
get_object
().
cancelled
is
True
):
raise
Http404
# can only edit your own bids
if
not
(
posting_student
==
me
):
return
HttpResponseForbidden
()
else
:
...
...
@@ -606,6 +602,7 @@ class CancelListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
if
(
self
.
get_object
().
cancelled
is
True
):
raise
Http404
# only you can cancel your own listing
if
not
(
posting_student
==
me
):
return
HttpResponseForbidden
()
else
:
...
...
@@ -637,6 +634,7 @@ class ReopenListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
if
(
self
.
get_object
().
cancelled
is
False
):
raise
Http404
# only you can re-open your own listing
if
not
(
posting_student
==
me
):
return
HttpResponseForbidden
()
else
:
...
...
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