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
e4b4af18
Commit
e4b4af18
authored
Mar 03, 2020
by
Daniel W Bond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
duplicated url parsing code
parent
f2785c42
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
40 deletions
+19
-40
bookshare/trades/views.py
bookshare/trades/views.py
+19
-40
No files found.
bookshare/trades/views.py
View file @
e4b4af18
...
...
@@ -232,10 +232,8 @@ class CreateFlag(LoginRequiredMixin, CreateView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
CreateFlag
,
self
).
get_context_data
(
**
kwargs
)
me
=
self
.
request
.
user
.
student
selected_listing
=
self
.
parse_url_for_listing
(
self
.
request
)
context
[
'listing'
]
=
sel
ected_listing
context
[
'listing'
]
=
sel
f
.
parse_url_for_listing
(
self
.
request
)
return
context
def
form_valid
(
self
,
form
):
...
...
@@ -286,15 +284,16 @@ class CreateBidFlag(LoginRequiredMixin, CreateView):
context_object_name
=
'bidflag'
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_bid
(
self
,
request
):
# there's possibly a better way than url parsing, but here we are
current_url
=
request
.
get_full_path
()
bid_slug
=
current_url
.
split
(
'/'
)[
5
]
# [u'', u'share', u'listing', u'C1s3oD', u'bid', 'u'F17jal', u'flag']
selected_bid
=
Bid
.
objects
.
get
(
slug
=
bid_slug
)
return
Bid
.
objects
.
get
(
slug
=
bid_slug
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
me
=
self
.
request
.
user
.
student
selected_bid
=
self
.
parse_url_for_bid
(
self
.
request
)
bidding_student
=
selected_bid
.
bidder
# can only create a flag if you haven't previously created one
...
...
@@ -310,25 +309,13 @@ class CreateBidFlag(LoginRequiredMixin, CreateView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
CreateBidFlag
,
self
).
get_context_data
(
**
kwargs
)
me
=
self
.
request
.
user
.
student
# duplicated code!!!
current_url
=
self
.
request
.
get_full_path
()
bid_slug
=
current_url
.
split
(
'/'
)[
5
]
# [u'', u'share', u'listing', u'C1s3oD', u'bid', 'u'F17jal', u'flag']
selected_bid
=
Bid
.
objects
.
get
(
slug
=
bid_slug
)
context
[
'bid'
]
=
sel
ected_bid
context
[
'bid'
]
=
sel
f
.
parse_url_for_bid
(
self
.
request
)
return
context
def
form_valid
(
self
,
form
):
me
=
self
.
request
.
user
.
student
# duplicated code!!!
current_url
=
self
.
request
.
get_full_path
()
bid_slug
=
current_url
.
split
(
'/'
)[
5
]
# [u'', u'share', u'listing', u'C1s3oD', u'bid', 'u'F17jal', u'flag']
selected_bid
=
Bid
.
objects
.
get
(
slug
=
bid_slug
)
selected_bid
=
self
.
parse_url_for_bid
(
self
.
request
)
form
.
instance
.
flagger
=
me
form
.
instance
.
bid
=
selected_bid
...
...
@@ -656,15 +643,16 @@ class CreateRating(LoginRequiredMixin, CreateView):
context_object_name
=
'rating'
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
)
winning_student
=
selected_listing
.
winning_bid
.
bidder
# can only create a rating if you haven't previously created one
...
...
@@ -681,12 +669,7 @@ class CreateRating(LoginRequiredMixin, CreateView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
CreateRating
,
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
)
winning_student
=
selected_listing
.
winning_bid
.
bidder
...
...
@@ -695,11 +678,7 @@ class CreateRating(LoginRequiredMixin, CreateView):
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
.
rater
=
me
form
.
instance
.
listing
=
selected_listing
...
...
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