mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Began working on favorites model
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from django.contrib.postgres.search import SearchVector
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.contrib.auth.models import AbstractUser, User
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
# Create your models here.
|
||||
|
||||
@@ -110,6 +111,14 @@ class Navigation(models.Model):
|
||||
return results
|
||||
|
||||
|
||||
class CustomUser(AbstractUser):
|
||||
facebook = models.CharField(max_length=255, null=True)
|
||||
twitter = models.CharField(max_length=255, null=True)
|
||||
ulvl = models.IntegerField(default=1)
|
||||
sponsorid = models.IntegerField(null=True)
|
||||
matrixid = models.CharField(max_length=255, null=True)
|
||||
|
||||
|
||||
class Favorites(models.Model):
|
||||
"""
|
||||
pyShelfs User Database class
|
||||
@@ -122,10 +131,9 @@ class Favorites(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
favorite = models.ManyToManyField(Books)
|
||||
uname = models.ManyToManyField(settings.AUTH_USER_MODEL)
|
||||
|
||||
|
||||
book = models.ForeignKey(Books.id, on_delete=models.PROTECT)
|
||||
user = models.ForeignKey(get_user_model(), on_delete=models.PROTECT)
|
||||
def generic_search(self, query):
|
||||
try:
|
||||
results = Favorites.objects.annotate(search=SearchVector("uname"),).filter(
|
||||
@@ -136,9 +144,3 @@ class Favorites(models.Model):
|
||||
return results
|
||||
|
||||
|
||||
class CustomUser(AbstractUser):
|
||||
facebook = models.CharField(max_length=255, null=True)
|
||||
twitter = models.CharField(max_length=255, null=True)
|
||||
ulvl = models.IntegerField(default=1)
|
||||
sponsorid = models.IntegerField(null=True)
|
||||
matrixid = models.CharField(max_length=255, null=True)
|
||||
|
||||
8
src/interface/static/js/pyshelf_ux.js
vendored
8
src/interface/static/js/pyshelf_ux.js
vendored
@@ -73,6 +73,9 @@ $(document).ready(function(){
|
||||
});
|
||||
$('#btn_login').on('click', function(){
|
||||
$('#hdr_nav_login').toggle();
|
||||
});
|
||||
$('.favorite_action').on('click', toggle_favorite(){
|
||||
|
||||
});
|
||||
$('#sortlist').change(function () {
|
||||
var optionSelected = $(this).find("option:selected");
|
||||
@@ -101,3 +104,8 @@ function resize_search(win_width){
|
||||
$('.search_string').val("Search");
|
||||
}
|
||||
}
|
||||
|
||||
function toggle_favorite($(this)){
|
||||
custom_log('Favorite book by _pk'+$(this));
|
||||
}
|
||||
|
||||
|
||||
2
src/interface/templates/index.html
vendored
2
src/interface/templates/index.html
vendored
@@ -97,7 +97,7 @@
|
||||
{% endif %}
|
||||
<li class="book_tags">Tags: {{ book.tags }}</li>
|
||||
<li class="book_controls">
|
||||
<span class="favorite-button controls">
|
||||
<span class="favorite-button controls favorite_action">
|
||||
<a href="{% url 'favorite' pk=book.pk %}" class="book_link"><i class="fas fa-thumbs-up icon"></i></a>
|
||||
</span>
|
||||
<span class="download-button controls">
|
||||
|
||||
@@ -8,10 +8,13 @@ from django.http import JsonResponse
|
||||
from django.shortcuts import HttpResponse, render, redirect # render_to_response
|
||||
from django.utils.text import slugify
|
||||
from django.contrib.auth import login, authenticate, logout
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
import json
|
||||
from .forms import SignUpForm, UserLoginForm
|
||||
from .models import Books, Collections, Navigation, Favorites
|
||||
from .models import Books, Collections, Navigation, Favorites, CustomUser
|
||||
|
||||
config = Config(Path("../"))
|
||||
|
||||
@@ -63,8 +66,8 @@ def userlogout(request):
|
||||
return redirect('home')
|
||||
|
||||
|
||||
def home(request, query=None, _set=1, _limit=None, _order='title'):
|
||||
"""
|
||||
def home(request, query=None, _set=1, _limit=None, _order='title'):
|
||||
"""
|
||||
Reset Search Queries & Return Home
|
||||
"""
|
||||
_payload = payload(request, query, _set, _limit, _order, reset='1')
|
||||
@@ -203,7 +206,7 @@ def download(request, pk):
|
||||
"""
|
||||
Download book by primary key
|
||||
"""
|
||||
_book = Books.objects.all().filter(pk=pk)[0]
|
||||
_book = Books.objects.get(pk=pk)
|
||||
_fn = hr_name(_book)
|
||||
response = HttpResponse(
|
||||
open(os.path.abspath(_book.file_name), "rb"), content_type="application/zip"
|
||||
@@ -216,8 +219,10 @@ def favorite(request, pk):
|
||||
"""
|
||||
Add book to favorites bu primary key
|
||||
"""
|
||||
_book = Books.objects.all().filter(pk=pk)[0]
|
||||
print(Favorite(book=_book, uname=User))
|
||||
breakpoint()
|
||||
f = Favorites(book=Books.objects.get(pk=pk))
|
||||
f.save
|
||||
return redirect('home')
|
||||
|
||||
|
||||
def share(request, pk):
|
||||
|
||||
Reference in New Issue
Block a user