mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Fixed an issue with jquery selecting wrong selector on favorite
This commit is contained in:
@@ -133,7 +133,7 @@ class Favorites(models.Model):
|
||||
db_table = "favorites"
|
||||
|
||||
def __str__(self):
|
||||
return self.book
|
||||
return str(self.book)
|
||||
|
||||
book = models.ForeignKey(Books, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(
|
||||
|
||||
4
src/interface/static/js/pyshelf_ux.js
vendored
4
src/interface/static/js/pyshelf_ux.js
vendored
@@ -12,7 +12,7 @@ $(document).ready(function(){
|
||||
var scr_height = window.outerHeight;
|
||||
var scr_width = window.outerWidth;
|
||||
var hdr_height = $('.app_hdr').height(); // Get our header height
|
||||
var ftr_height = $('.app_footer').height(); // Get our footer height
|
||||
var ftr_height = $('.app_footer').height(); // Get our footer height
|
||||
var nav_width = $('.nav_l').width(); // Get the width of our nav items
|
||||
var cmp_height = window.screen.availHeight;
|
||||
var max_height = win_height - (hdr_height + ftr_height) - (scr_height - win_height); // Set our available height
|
||||
@@ -75,7 +75,7 @@ $(document).ready(function(){
|
||||
$('#hdr_nav_login').toggle();
|
||||
});
|
||||
$('.favorite_action').on('click', function(){
|
||||
$(this).toggleClass('favorite');
|
||||
$(this).children('a').toggleClass('favorite');
|
||||
});
|
||||
$('#sortlist').change(function () {
|
||||
var optionSelected = $(this).find("option:selected");
|
||||
|
||||
4
src/interface/templates/index.html
vendored
4
src/interface/templates/index.html
vendored
@@ -35,7 +35,7 @@
|
||||
<ul id="tab_nav_menu">
|
||||
<li class="nav_menu_tab active_tab" id="btn-home" data-location="/home"><i class="fas fa-home"></i> Home</li>
|
||||
<li class="nav_menu_tab"><i class="fas fa-layer-group"></i> Collections</li>
|
||||
<li class="nav_menu_tab"><i class="fas fa-star"></i> Favorites</li>
|
||||
<li class="nav_menu_tab"><i class="fas fa-star"></i><a href="/favorites" class="nav_link"> Favorites,</a></li>
|
||||
<li class="nav_menu_tab"><i class="fas fa-bug"></i> Bug report</li>
|
||||
<li class="nav_menu_tab" id="btn_login"> <i class="fa fa-user-circle" aria-hidden="true"></i>
|
||||
{% if request.user.is_authenticated %}
|
||||
@@ -101,7 +101,7 @@
|
||||
{% if book.is_favorite %}
|
||||
<a href="{% url 'favorite' pk=book.pk %}" class="book_link favorite"><i class="fas fa-thumbs-up icon"></i></a>
|
||||
{% else %}
|
||||
<a href="{% url 'favorite' pk=book.pk %}" class="book_link not_favorite"><i class="fas fa-thumbs-up icon"></i></a>
|
||||
<a href="{% url 'favorite' pk=book.pk %}" class="book_link"><i class="fas fa-thumbs-up icon"></i></a>
|
||||
{% endif %}
|
||||
</span>
|
||||
<span class="download-button controls">
|
||||
|
||||
@@ -33,6 +33,18 @@ def index(request, query=None, _set=1, _limit=None, _order='title'):
|
||||
)
|
||||
|
||||
|
||||
def favorites(request, query=None, _set=1, _limit=None, _order='title'):
|
||||
"""
|
||||
Return template index
|
||||
"""
|
||||
_payload = payload(request, query, _set, _limit, _order, favorites=True)
|
||||
return render(
|
||||
request,
|
||||
"index.html",
|
||||
_payload
|
||||
)
|
||||
|
||||
|
||||
def signup(request):
|
||||
if request.method == 'POST':
|
||||
form = SignUpForm(request.POST)
|
||||
@@ -152,27 +164,36 @@ def prev_page(request, bookset, query=None, _limit=None, _order='title'):
|
||||
)
|
||||
|
||||
|
||||
def book_set(request, _order, _limit=None, _set=1, _flip=False):
|
||||
def book_set(request, _order, _limit=None, _set=1, _flip=False, **kwargs):
|
||||
"""
|
||||
Get books results by set #
|
||||
"""
|
||||
try:
|
||||
book_key = []
|
||||
if kwargs['favorites'] is True:
|
||||
for id in Favorites.objects.all().filter(user=request.user):
|
||||
book_key.append(id.book.id)
|
||||
BookObject = Books.objects.filter(id__in=(book_key))
|
||||
except KeyError: BookObject = Books.objects.all()
|
||||
if _limit is None:
|
||||
_limit = 20 # TODO default from user choice
|
||||
_set_max = int(_set) * _limit
|
||||
_set_min = _set_max - _limit
|
||||
if _flip:
|
||||
books = Books.objects.all().order_by(_order).reverse()[_set_min:_set_max]
|
||||
books = BookObject.order_by(_order).reverse()[_set_min:_set_max]
|
||||
else:
|
||||
books = Books.objects.all().order_by(_order)[_set_min:_set_max]
|
||||
books = BookObject.order_by(_order)[_set_min:_set_max]
|
||||
try:
|
||||
favorites = Favorites.objects.filter(user=request.user)
|
||||
for book in books:
|
||||
for favorite in favorites:
|
||||
if book == favorite.book:
|
||||
if book == favorite.book:
|
||||
book.is_favorite = True
|
||||
break
|
||||
pass
|
||||
return books
|
||||
except Exception as e:
|
||||
for book in books:
|
||||
book.if_favorite = False
|
||||
return books
|
||||
|
||||
|
||||
@@ -229,7 +250,10 @@ def favorite(request, pk):
|
||||
"""
|
||||
Add book to favorites bu primary key
|
||||
"""
|
||||
_d = Favorites.objects.filter(user=request.user, book=Books.objects.get(pk=pk))
|
||||
try:
|
||||
_d = Favorites.objects.filter(user=request.user, book=Books.objects.get(pk=pk))
|
||||
except TypeError as e:
|
||||
return redirect('login')
|
||||
if len(_d) == 1:
|
||||
_d.delete()
|
||||
return HttpResponse(status=204)
|
||||
@@ -347,8 +371,8 @@ def payload(request, query, _set, _limit, _order, **kwargs):
|
||||
_set_min = _set_max - _limit
|
||||
_now_showing = "%s-%s"%(_set_min, _set_max)
|
||||
if request.session['ascending']:
|
||||
_r = book_set(request, _order, _limit, _set)
|
||||
else: _r = book_set(request, _order, _limit, _set, True)
|
||||
_r = book_set(request, _order, _limit, _set, False, **kwargs)
|
||||
else: _r = book_set(request, _order, _limit, _set, True, **kwargs)
|
||||
_r_len, _search = None, None
|
||||
except KeyError:
|
||||
_set = int(_set)
|
||||
@@ -385,8 +409,8 @@ def payload(request, query, _set, _limit, _order, **kwargs):
|
||||
_results.count()
|
||||
except KeyError:
|
||||
if request.session['ascending']:
|
||||
_r = book_set(request, _order, _limit, _set)
|
||||
else: _r = book_set(request, _order, _limit, _set, True)
|
||||
_r = book_set(request, _order, _limit, _set, False, **kwargs)
|
||||
else: _r = book_set(request, _order, _limit, _set, True, **kwargs)
|
||||
_r_len, _search = None, None
|
||||
|
||||
_bookstats, _collectionstats, _collectionobject = \
|
||||
|
||||
Reference in New Issue
Block a user