Merge branch 'master' into production
commit
9339d47175
|
@ -130,8 +130,10 @@ class FormatFacetGroup(FacetGroup):
|
|||
return "These eBooks available in %s format." % self.facet_name
|
||||
return FormatFacet
|
||||
|
||||
idtitles = {'doab': 'indexed in DOAB', 'gtbg':'available in Project Gutenberg'}
|
||||
idlabels = {'doab': 'DOAB', 'gtbg':'Project Gutenberg'}
|
||||
idtitles = {'doab': 'indexed in DOAB', 'gtbg':'available in Project Gutenberg',
|
||||
'-doab': 'not in DOAB', '-gtbg':'not from Project Gutenberg', }
|
||||
idlabels = {'doab': 'DOAB', 'gtbg':'Project Gutenberg',
|
||||
'-doab': 'not DOAB', '-gtbg':'not Project Gutenberg'}
|
||||
class IdFacetGroup(FacetGroup):
|
||||
def __init__(self):
|
||||
super(FacetGroup,self).__init__()
|
||||
|
@ -144,10 +146,16 @@ class IdFacetGroup(FacetGroup):
|
|||
def set_name(self):
|
||||
self.facet_name=facet_name
|
||||
def id_filter(query_set):
|
||||
return query_set.filter(identifiers__type=facet_name)
|
||||
if facet_name[0] == '-':
|
||||
return query_set.exclude(identifiers__type=facet_name[1:])
|
||||
else:
|
||||
return query_set.filter(identifiers__type=facet_name)
|
||||
model_filters = {}
|
||||
def get_query_set(self):
|
||||
return self._get_query_set().filter(identifiers__type=self.facet_name)
|
||||
if facet_name[0] == '-':
|
||||
return self._get_query_set().exclude(identifiers__type=self.facet_name[1:])
|
||||
else:
|
||||
return self._get_query_set().filter(identifiers__type=self.facet_name)
|
||||
def template(self):
|
||||
return 'facets/id.html'
|
||||
@property
|
||||
|
|
|
@ -60,6 +60,8 @@ def gluejar_search(q, user_ip='69.243.24.29', page=1):
|
|||
|
||||
|
||||
def googlebooks_search(q, user_ip, page):
|
||||
if len(q) < 2 or len(q) > 2000:
|
||||
return {}
|
||||
# XXX: need to pass IP address of user in from the frontend
|
||||
headers = {'X-Forwarded-For': user_ip}
|
||||
start = (page - 1) * 10
|
||||
|
|
|
@ -154,12 +154,12 @@ class EbookForm(forms.ModelForm):
|
|||
new_label = self.data.get('new_version_label','')
|
||||
return new_label if new_label else self.cleaned_data['version_label']
|
||||
|
||||
def clean_provider(self):
|
||||
def set_provider(self):
|
||||
url = self.cleaned_data['url']
|
||||
new_provider = Ebook.infer_provider(url)
|
||||
if url and not new_provider:
|
||||
raise forms.ValidationError(_("At this time, ebook URLs must point at Internet Archive, Wikisources, Wikibooks, Hathitrust, Project Gutenberg, raw files at Github, Google Books, or OApen."))
|
||||
return new_provider if new_provider else "Unglue.it"
|
||||
self.cleaned_data['provider'] = new_provider if new_provider else "Unglue.it"
|
||||
|
||||
def clean_url(self):
|
||||
url = self.cleaned_data['url']
|
||||
|
@ -170,6 +170,7 @@ class EbookForm(forms.ModelForm):
|
|||
raise forms.ValidationError(_("There's already an ebook with that url."))
|
||||
|
||||
def clean(self):
|
||||
self.set_provider()
|
||||
format = self.cleaned_data.get('format', '')
|
||||
the_file = self.cleaned_data.get('file', None)
|
||||
url = self.cleaned_data.get('url', None)
|
||||
|
|
|
@ -7,5 +7,11 @@
|
|||
{% if facet.facet_name == 'doab' %}
|
||||
These books are included in the <a href="http://doabooks.org/">Directory of Open Access Books</a>. This means that they have been peer-reviewed and are of interest to scholars.
|
||||
{% endif %}
|
||||
{% if facet.facet_name == '-gtbg' %}
|
||||
These books are not included in <a href="https://www.gutenberg.org">Project Gutenberg</a>.
|
||||
{% endif %}
|
||||
{% if facet.facet_name == '-doab' %}
|
||||
These books do not seem to be included in the <a href="http://doabooks.org/">Directory of Open Access Books</a>.
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
|
@ -528,7 +528,11 @@ BAD_ROBOTS = [u'memoryBot']
|
|||
def is_bad_robot(request):
|
||||
user_agent = request.META.get('HTTP_USER_AGENT', '')
|
||||
for robot in BAD_ROBOTS:
|
||||
if robot in user_agent:
|
||||
try:
|
||||
if robot in user_agent:
|
||||
return True
|
||||
except UnicodeDecodeError:
|
||||
# user agent is sending illegal header
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -1898,7 +1902,7 @@ class ManageAccount(FormView):
|
|||
return render(self.request, self.template_name, self.get_context_data())
|
||||
|
||||
def search(request):
|
||||
q = request.GET.get('q', '')
|
||||
q = request.GET.get('q', '').strip()
|
||||
ty = request.GET.get('ty', 'g') # ge= 'general, au= 'author'
|
||||
request.session['q'] = q
|
||||
try:
|
||||
|
@ -1908,7 +1912,7 @@ def search(request):
|
|||
page = 1
|
||||
gbo = request.GET.get('gbo', 'n') # gbo is flag for google books only
|
||||
our_stuff = Q(is_free=True) | Q(campaigns__isnull=False)
|
||||
if q != '' and page == 1 and not gbo == 'y':
|
||||
if len(q) > 1 and page == 1 and not gbo == 'y':
|
||||
isbnq = ISBN(q)
|
||||
if isbnq.valid:
|
||||
work_query = Q(identifiers__value=str(isbnq), identifiers__type="isbn")
|
||||
|
|
|
@ -329,6 +329,7 @@ USER_AGENT = "unglue.it.bot v0.0.1 <https://unglue.it>"
|
|||
GLUEJAR_COMMISSION = 0.06
|
||||
PREAPPROVAL_PERIOD = 365 # days to ask for in a preapproval
|
||||
PREAPPROVAL_PERIOD_AFTER_CAMPAIGN = 90 # if we ask for preapproval time after a campaign deadline
|
||||
PAYPAL_GLUEJAR_EMAIL = 'info@ebookfoundation.org' #legacy code needs this
|
||||
|
||||
# How many days we will try to collect on failed transactions until they are written off
|
||||
RECHARGE_WINDOW = 14
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Loading…
Reference in New Issue