Began working on favorites model

This commit is contained in:
Raelon Masters
2020-07-19 16:52:01 -04:00
parent a72f39863a
commit 802a07e52f
5 changed files with 36 additions and 19 deletions

View File

@@ -17,6 +17,8 @@ from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.urls import include, path, re_path from django.urls import include, path, re_path
from django.contrib.auth import views as auth_views from django.contrib.auth import views as auth_views
from django.contrib.auth.models import User
from django.shortcuts import HttpResponse
from interface import views from interface import views
urlpatterns = [ urlpatterns = [
@@ -26,7 +28,6 @@ urlpatterns = [
path("sort/<_order>", views.index, name="index"), path("sort/<_order>", views.index, name="index"),
path("flip_sort/<_order>", views.flip_sort, name="index"), path("flip_sort/<_order>", views.flip_sort, name="index"),
path("download/<pk>", views.download, name="download"), path("download/<pk>", views.download, name="download"),
path("favorite/<pk>", views.favorite, name="favorite"),
path("share/<pk>", views.share, name="share"), path("share/<pk>", views.share, name="share"),
path("share/<pk>", views.info, name="info"), path("share/<pk>", views.info, name="info"),
path("prev_page/<bookset>", views.prev_page, name="prev_page"), path("prev_page/<bookset>", views.prev_page, name="prev_page"),
@@ -40,6 +41,7 @@ urlpatterns = [
path("signup", views.signup, name="signup"), path("signup", views.signup, name="signup"),
path("login", views.userlogin, name="login"), path("login", views.userlogin, name="login"),
path('logout', views.userlogout, name='logout'), path('logout', views.userlogout, name='logout'),
path('favorite/<pk>', views.favorite, name='favorite'),
path( path(
'admin/password_reset/', 'admin/password_reset/',
auth_views.PasswordResetView.as_view(), auth_views.PasswordResetView.as_view(),

View File

@@ -1,7 +1,8 @@
from django.contrib.postgres.search import SearchVector from django.contrib.postgres.search import SearchVector
from django.db import models from django.db import models
from django.conf import settings 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. # Create your models here.
@@ -110,6 +111,14 @@ class Navigation(models.Model):
return results 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): class Favorites(models.Model):
""" """
pyShelfs User Database class pyShelfs User Database class
@@ -122,10 +131,9 @@ class Favorites(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title
favorite = models.ManyToManyField(Books) book = models.ForeignKey(Books.id, on_delete=models.PROTECT)
uname = models.ManyToManyField(settings.AUTH_USER_MODEL) user = models.ForeignKey(get_user_model(), on_delete=models.PROTECT)
def generic_search(self, query): def generic_search(self, query):
try: try:
results = Favorites.objects.annotate(search=SearchVector("uname"),).filter( results = Favorites.objects.annotate(search=SearchVector("uname"),).filter(
@@ -136,9 +144,3 @@ class Favorites(models.Model):
return results 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)

View File

@@ -73,6 +73,9 @@ $(document).ready(function(){
}); });
$('#btn_login').on('click', function(){ $('#btn_login').on('click', function(){
$('#hdr_nav_login').toggle(); $('#hdr_nav_login').toggle();
});
$('.favorite_action').on('click', toggle_favorite(){
}); });
$('#sortlist').change(function () { $('#sortlist').change(function () {
var optionSelected = $(this).find("option:selected"); var optionSelected = $(this).find("option:selected");
@@ -101,3 +104,8 @@ function resize_search(win_width){
$('.search_string').val("Search"); $('.search_string').val("Search");
} }
} }
function toggle_favorite($(this)){
custom_log('Favorite book by _pk'+$(this));
}

View File

@@ -97,7 +97,7 @@
{% endif %} {% endif %}
<li class="book_tags">Tags: {{ book.tags }}</li> <li class="book_tags">Tags: {{ book.tags }}</li>
<li class="book_controls"> <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> <a href="{% url 'favorite' pk=book.pk %}" class="book_link"><i class="fas fa-thumbs-up icon"></i></a>
</span> </span>
<span class="download-button controls"> <span class="download-button controls">

View File

@@ -8,10 +8,13 @@ from django.http import JsonResponse
from django.shortcuts import HttpResponse, render, redirect # render_to_response from django.shortcuts import HttpResponse, render, redirect # render_to_response
from django.utils.text import slugify from django.utils.text import slugify
from django.contrib.auth import login, authenticate, logout from django.contrib.auth import login, authenticate, logout
from django.contrib import auth
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.auth import get_user_model
import json import json
from .forms import SignUpForm, UserLoginForm from .forms import SignUpForm, UserLoginForm
from .models import Books, Collections, Navigation, Favorites from .models import Books, Collections, Navigation, Favorites, CustomUser
config = Config(Path("../")) config = Config(Path("../"))
@@ -63,8 +66,8 @@ def userlogout(request):
return redirect('home') 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 Reset Search Queries & Return Home
""" """
_payload = payload(request, query, _set, _limit, _order, reset='1') _payload = payload(request, query, _set, _limit, _order, reset='1')
@@ -203,7 +206,7 @@ def download(request, pk):
""" """
Download book by primary key Download book by primary key
""" """
_book = Books.objects.all().filter(pk=pk)[0] _book = Books.objects.get(pk=pk)
_fn = hr_name(_book) _fn = hr_name(_book)
response = HttpResponse( response = HttpResponse(
open(os.path.abspath(_book.file_name), "rb"), content_type="application/zip" 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 Add book to favorites bu primary key
""" """
_book = Books.objects.all().filter(pk=pk)[0] breakpoint()
print(Favorite(book=_book, uname=User)) f = Favorites(book=Books.objects.get(pk=pk))
f.save
return redirect('home')
def share(request, pk): def share(request, pk):