Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
bookshare
Commits
7cab4bcf
Commit
7cab4bcf
authored
Apr 21, 2015
by
Daniel W Bond
Browse files
more flake8 fixes
parent
c21b2c69
Changes
8
Hide whitespace changes
Inline
Side-by-side
bookshare/core/models.py
View file @
7cab4bcf
...
...
@@ -25,8 +25,8 @@ class Course(TimeStampedModel):
name
=
models
.
CharField
(
max_length
=
255
)
department
=
models
.
CharField
(
max_length
=
255
)
departmentAbbreviation
=
models
.
CharField
(
max_length
=
4
)
#number = models.CharField(max_length=255,
#validators=RegexValidator('[0-9]{3,}'))
#
number = models.CharField(max_length=255,
#
validators=RegexValidator('[0-9]{3,}'))
number
=
models
.
CharField
(
max_length
=
3
)
def
__unicode__
(
self
):
...
...
bookshare/core/views.py
View file @
7cab4bcf
...
...
@@ -31,7 +31,7 @@ class DetailStudent(LoginRequiredMixin, DetailView):
average_stars
=
sum
(
student_stars
)
/
float
((
len
(
student_stars
)))
else
:
average_stars
=
None
context
[
'avg_stars'
]
=
average_stars
context
[
'listings'
]
=
student_listings
context
[
'lookouts'
]
=
Lookout
.
objects
.
filter
(
owner
=
self
.
get_object
())
...
...
@@ -43,6 +43,7 @@ class DetailStudent(LoginRequiredMixin, DetailView):
return
context
class
StudentRatings
(
LoginRequiredMixin
,
DetailView
):
model
=
Student
template_name
=
'ratings.html'
...
...
@@ -61,7 +62,7 @@ class StudentRatings(LoginRequiredMixin, DetailView):
average_stars
=
sum
(
student_stars
)
/
float
((
len
(
student_stars
)))
else
:
average_stars
=
None
context
[
'avg_stars'
]
=
average_stars
context
[
'student_ratings'
]
=
student_ratings
...
...
bookshare/lookouts/models.py
View file @
7cab4bcf
...
...
@@ -17,7 +17,7 @@ class Lookout(TimeStampedModel):
validators
=
[
RegexValidator
(
'[0-9xX-]{10,20}'
,
message
=
'Please enter a valid ISBN.'
)])
# would have to load in every conceivable course first
#course = models.ForeignKey(Course)
#
course = models.ForeignKey(Course)
slug
=
RandomSlugField
(
length
=
6
)
def
get_listings
(
self
):
...
...
bookshare/lookouts/urls.py
View file @
7cab4bcf
# core django imports
from
django.conf.urls
import
patterns
,
url
from
django.views.decorators.cache
import
cache_page
# imports from your apps
# imports from your apps
from
.views
import
DetailLookout
,
CreateLookout
,
DeleteLookout
urlpatterns
=
patterns
(
''
,
...
...
bookshare/trades/models.py
View file @
7cab4bcf
...
...
@@ -9,7 +9,7 @@ from randomslugfield import RandomSlugField
from
model_utils.models
import
TimeStampedModel
from
dateutil.relativedelta
import
relativedelta
# imports from your apps
from
core.models
import
Student
#
, Course
from
core.models
import
Student
# and later
, Course
class
Listing
(
TimeStampedModel
):
...
...
@@ -46,21 +46,21 @@ class Listing(TimeStampedModel):
author
=
models
.
CharField
(
max_length
=
200
)
isbn
=
models
.
CharField
(
max_length
=
20
,
validators
=
[
RegexValidator
(
'^[0-9xX-]{10,20}'
,
message
=
'Please enter a valid ISBN.'
)])
message
=
'Please enter a valid ISBN.'
)])
year
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
,
# some professors may assign books still to be officially published
validators
=
[
MaxValueValidator
(
date
.
today
().
year
+
1
)])
edition
=
models
.
PositiveIntegerField
(
null
=
True
,
blank
=
True
,
default
=
1
,
validators
=
[
MaxValueValidator
(
1000
)])
# would have to load in every conceivable course first
#course = models.ForeignKey(Course)
#
course = models.ForeignKey(Course)
condition
=
models
.
CharField
(
choices
=
BOOK_CONDITION_CHOICES
,
max_length
=
20
,
default
=
GOOD
)
access_code
=
models
.
CharField
(
choices
=
ACCESS_CODE_CHOICES
,
max_length
=
30
,
default
=
NOT_APPLICABLE
)
course_abbr
=
models
.
CharField
(
max_length
=
10
,
blank
=
True
,
validators
=
[
RegexValidator
(
'^([a-zA-Z]){2,4} (\d){3}$'
,
message
=
'Please enter a valid course.'
)])
message
=
'Please enter a valid course.'
)])
description
=
models
.
TextField
(
blank
=
True
,
max_length
=
2000
)
price
=
models
.
PositiveIntegerField
(
default
=
0
,
validators
=
[
MaxValueValidator
(
1000
)])
...
...
@@ -88,7 +88,8 @@ class Listing(TimeStampedModel):
modified_plus_month
=
self
.
modified
.
date
()
+
relativedelta
(
months
=
1
)
# last login + two weeks
last_login_plus_two_weeks
=
self
.
seller
.
last_login
.
date
()
+
relativedelta
(
weeks
=
2
)
last_login_plus_two_weeks
=
self
.
seller
.
last_login
.
date
()
+
\
relativedelta
(
weeks
=
2
)
last_poked
=
((
today
>
created_plus_month
)
or
(
today
>
modified_plus_month
))
recent_login
=
(
today
>
last_login_plus_two_weeks
)
...
...
@@ -117,7 +118,7 @@ class Listing(TimeStampedModel):
return
'%s : %s'
%
(
self
.
isbn
,
self
.
title
)
class
Meta
:
#unique_together = (("ISBN", "seller"),)
#
unique_together = (("ISBN", "seller"),)
ordering
=
[
'isbn'
,
'title'
]
...
...
@@ -126,7 +127,7 @@ class Bid(TimeStampedModel):
bidder
=
models
.
ForeignKey
(
Student
)
listing
=
models
.
ForeignKey
(
Listing
)
price
=
models
.
PositiveIntegerField
(
default
=
0
,
validators
=
[
MaxValueValidator
(
1000
)],)
validators
=
[
MaxValueValidator
(
1000
)],)
text
=
models
.
CharField
(
blank
=
True
,
max_length
=
2000
,)
slug
=
RandomSlugField
(
length
=
6
)
...
...
bookshare/trades/templatetags/trades_extras.py
View file @
7cab4bcf
...
...
@@ -3,21 +3,23 @@ from trades.views import ISBNMetadata
register
=
template
.
Library
()
@
register
.
filter
(
name
=
'isbn_name'
)
def
isbn_name
(
isbn
):
# numbers starting with 0 throw "SyntaxError: invalid token"
isbn_str
=
str
(
isbn
)
data
=
ISBNMetadata
(
isbn
)
data
=
ISBNMetadata
(
isbn
_str
)
if
data
is
not
None
:
return
data
[
'title'
]
else
:
return
isbn
return
isbn
_str
@
register
.
filter
(
name
=
'full_stars'
)
def
full_stars
(
avg_stars
):
return
range
(
int
(
avg_stars
))
@
register
.
filter
(
name
=
'half_stars'
)
def
half_stars
(
avg_stars
):
if
(
avg_stars
%
1
)
>=
.
5
:
...
...
@@ -25,6 +27,7 @@ def half_stars(avg_stars):
else
:
return
False
@
register
.
filter
(
name
=
'empty_stars'
)
def
empty_stars
(
avg_stars
):
if
half_stars
(
avg_stars
):
...
...
@@ -32,6 +35,7 @@ def empty_stars(avg_stars):
else
:
return
range
(
5
-
int
(
avg_stars
))
@
register
.
filter
(
name
=
'int_maker'
)
def
int_maker
(
num
):
return
int
(
num
)
bookshare/trades/views.py
View file @
7cab4bcf
...
...
@@ -11,7 +11,6 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from
django.core.mail
import
EmailMultiAlternatives
from
django.template.loader
import
get_template
from
django.template
import
Context
from
django.contrib
import
messages
from
django.utils.safestring
import
mark_safe
# third party imports
import
requests
...
...
@@ -29,7 +28,9 @@ 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"
url
=
"http://xisbn.worldcat.org/webservices/xid/isbn/"
+
\
str
(
standardISBN
)
+
\
"?method=getMetadata&format=json&fl=title,year,author,ed"
metadata
=
requests
.
get
(
url
)
# format into a dictionary
dejson
=
metadata
.
json
()
...
...
@@ -64,7 +65,7 @@ def flag_slug(flagger, listing):
# (basically) duplicated code!!!
def
can_rate
(
rater
,
listing
):
user_rate_num
=
Rating
.
objects
.
filter
(
rater
=
rater
,
listing
=
listing
).
count
()
listing
=
listing
).
count
()
# we're assuming that this isn't going to go over 1
if
user_rate_num
:
return
False
...
...
@@ -118,7 +119,7 @@ class CreateListing(LoginRequiredMixin, FormValidMessageMixin, CreateView):
temp_image
.
seek
(
0
)
new_uploaded_file
=
SimpleUploadedFile
(
image_name
,
temp_image
.
read
(),
content_type
=
image_format
)
temp_image
.
read
(),
content_type
=
image_format
)
form
.
instance
.
photo
=
new_uploaded_file
...
...
@@ -297,7 +298,7 @@ class EditBid(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
model
=
Bid
template_name
=
'bid_edit.html'
context_object_name
=
'bid'
#form_class = EditBidForm
#
form_class = EditBidForm
login_url
=
'login'
form_valid_message
=
"Your bid was successfully updated!"
...
...
@@ -308,7 +309,7 @@ class EditBid(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
def
get_success_url
(
self
):
return
reverse
(
'detail_listing'
,
kwargs
=
{
'slug'
:
self
.
object
.
listing
.
slug
})
kwargs
=
{
'slug'
:
self
.
object
.
listing
.
slug
})
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
EditBid
,
self
).
get_context_data
(
**
kwargs
)
...
...
@@ -331,7 +332,7 @@ class EditListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
model
=
Listing
template_name
=
'listing_edit.html'
context_object_name
=
'listing'
#form_class = EditListingForm
#
form_class = EditListingForm
login_url
=
'login'
form_valid_message
=
"Your listing was successfully updated!"
...
...
@@ -385,8 +386,8 @@ class SellListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
subject
,
from_email
,
to
,
cc
=
(
'Your bid has been selected on Bookshare!'
,
'no-reply@bookshare.srct.io'
,
#form.instance.winning_bid.bidder.user.email,
#self.obj.seller.user.email)
#
form.instance.winning_bid.bidder.user.email,
#
self.obj.seller.user.email)
'success@simulator.amazonses.com'
,
'success@simulator.amazonses.com'
)
text_content
=
text_email
.
render
(
email_context
)
...
...
@@ -451,8 +452,8 @@ class UnSellListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
subject
,
from_email
,
to
,
cc
=
(
'Your transaction has been cancelled on Bookshare'
,
'no-reply@bookshare.srct.io'
,
#self.obj.winning_bid.bidder.user.email,
#self.obj.seller.user.email)
#
self.obj.winning_bid.bidder.user.email,
#
self.obj.seller.user.email)
'success@simulator.amazonses.com'
,
'success@simulator.amazonses.com'
)
text_content
=
text_email
.
render
(
email_context
)
...
...
@@ -463,7 +464,7 @@ class UnSellListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
msg
.
send
()
# this has to come after the email has been sent, otherwise these are
# cleaned out
# cleaned out
form
.
instance
.
sold
=
False
form
.
instance
.
date_closed
=
None
form
.
instance
.
winning_bid
=
None
...
...
@@ -483,7 +484,7 @@ class UnSellListing(LoginRequiredMixin, FormValidMessageMixin, UpdateView):
context
[
'my_form'
]
=
form
return
context
@
ratelimit
(
key
=
'user'
,
rate
=
'5/m'
,
method
=
'POST'
,
block
=
True
)
@
ratelimit
(
key
=
'user'
,
rate
=
'100/d'
,
method
=
'POST'
,
block
=
True
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -606,7 +607,7 @@ class EditRating(LoginRequiredMixin, UpdateView):
model
=
Rating
template_name
=
'rating_edit.html'
context_object_name
=
'rating'
#form_class = EditListingForm
#
form_class = EditListingForm
login_url
=
'login'
fields
=
[
'stars'
,
'review'
,
]
...
...
setup.cfg
0 → 100644
View file @
7cab4bcf
[flake8]
max-line-length = 89
exclude = */migrations/*
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