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
fe6b657f
Commit
fe6b657f
authored
Feb 24, 2020
by
Daniel W Bond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove functions from top of file, and import from newly created utils
parent
ee60b4f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
71 deletions
+2
-71
bookshare/trades/views.py
bookshare/trades/views.py
+2
-71
No files found.
bookshare/trades/views.py
View file @
fe6b657f
...
...
@@ -13,7 +13,6 @@ from django.template.loader import get_template
from
django.template
import
Context
from
django.utils.safestring
import
mark_safe
# third party imports
import
requests
from
PIL
import
Image
from
braces.views
import
LoginRequiredMixin
,
SuperuserRequiredMixin
from
braces.views
import
FormValidMessageMixin
...
...
@@ -22,79 +21,11 @@ from ratelimit.decorators import ratelimit
from
.models
import
Listing
,
Bid
,
Flag
,
BidFlag
,
Rating
from
.forms
import
ListingForm
,
BidForm
,
FlagForm
,
BidFlagForm
,
\
ExchangeListingForm
,
UnExchangeListingForm
,
RatingForm
from
.utils
import
ISBNMetadata
,
can_flag
,
can_flag_bid
,
flag_slug
,
\
bid_flag_slug
,
can_rate
from
core.models
import
Student
# pulls worldcat metadata from ISBNs
def
ISBNMetadata
(
standardISBN
):
# passing in numbers starting with 0 throws "SyntaxError: invalid token"
url
=
"http://xisbn.worldcat.org/webservices/xid/isbn/"
+
\
str
(
standardISBN
)
+
\
"?method=getMetadata&format=json&fl=title,year,author,ed"
# In case the API fails to return, simply return None.
try
:
metadata
=
requests
.
get
(
url
,
timeout
=
3
)
except
requests
.
ConnectionError
:
return
None
# format into a dictionary
dejson
=
metadata
.
json
()
try
:
metadataDict
=
dejson
.
get
(
'list'
)
return
metadataDict
[
0
]
except
:
return
None
# flagging
# you can only flag a listing once...
def
can_flag
(
flagger
,
listing
):
user_flag_num
=
Flag
.
objects
.
filter
(
flagger
=
flagger
,
listing
=
listing
).
count
()
# we're assuming that this isn't going to go over 1
if
user_flag_num
:
return
False
else
:
return
True
def
can_flag_bid
(
flagger
,
bid
):
user_flag_num
=
BidFlag
.
objects
.
filter
(
flagger
=
flagger
,
bid
=
bid
).
count
()
if
user_flag_num
:
return
False
else
:
return
True
# get the listing's slug to pass to the create flag page
def
flag_slug
(
flagger
,
listing
):
if
not
can_flag
(
flagger
,
listing
):
return
Flag
.
objects
.
get
(
flagger
=
flagger
,
listing
=
listing
).
slug
else
:
return
None
def
bid_flag_slug
(
flagger
,
bid
):
if
not
can_flag_bid
(
flagger
,
bid
):
return
BidFlag
.
objects
.
get
(
flagger
=
flagger
,
bid
=
bid
).
slug
else
:
return
None
# rating
# (basically) duplicated code!!!
def
can_rate
(
rater
,
listing
):
user_rate_num
=
Rating
.
objects
.
filter
(
rater
=
rater
,
listing
=
listing
).
count
()
# we're assuming that this isn't going to go over 1
if
user_rate_num
:
return
False
else
:
return
True
class
ListListings
(
LoginRequiredMixin
,
ListView
):
model
=
Listing
context_object_name
=
'listings'
...
...
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