mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Add to favorites functionality backend complete.
This commit is contained in:
@@ -52,7 +52,7 @@ INSTALLED_APPS = [
|
|||||||
"interface.templatetags",
|
"interface.templatetags",
|
||||||
"debug_toolbar",
|
"debug_toolbar",
|
||||||
]
|
]
|
||||||
AUTH_USER_MODEL = "interface.CustomUser"
|
AUTH_USER_MODEL = "interface.User"
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
"django.middleware.security.SecurityMiddleware",
|
"django.middleware.security.SecurityMiddleware",
|
||||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth.admin import UserAdmin
|
from django.contrib.auth.admin import UserAdmin
|
||||||
|
|
||||||
from .models import Books, Collections, Favorites, Navigation, CustomUser
|
from .models import Books, Collections, Favorites, Navigation, User
|
||||||
from .forms import CustomUserCreationForm, CustomUserChangeForm
|
from .forms import CustomUserCreationForm, CustomUserChangeForm
|
||||||
|
|
||||||
|
|
||||||
class CustomUserAdmin(UserAdmin):
|
class CustomUserAdmin(UserAdmin):
|
||||||
model = CustomUser
|
model = User
|
||||||
add_form = CustomUserCreationForm
|
add_form = CustomUserCreationForm
|
||||||
form = CustomUserChangeForm
|
form = CustomUserChangeForm
|
||||||
list_display = ["email", "username", "facebook", "twitter", "sponsorid", "matrixid"]
|
list_display = ["email", "username", "facebook", "twitter", "sponsorid", "matrixid"]
|
||||||
@@ -27,4 +27,4 @@ admin.site.register(Books)
|
|||||||
admin.site.register(Collections)
|
admin.site.register(Collections)
|
||||||
admin.site.register(Favorites)
|
admin.site.register(Favorites)
|
||||||
admin.site.register(Navigation)
|
admin.site.register(Navigation)
|
||||||
admin.site.register(CustomUser, CustomUserAdmin)
|
admin.site.register(User, CustomUserAdmin)
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.forms import UserCreationForm, UserChangeForm, AuthenticationForm
|
from django.contrib.auth.forms import UserCreationForm, UserChangeForm, AuthenticationForm
|
||||||
from .models import CustomUser
|
from .models import User
|
||||||
|
|
||||||
|
|
||||||
class CustomUserCreationForm(UserCreationForm):
|
class CustomUserCreationForm(UserCreationForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CustomUser
|
model = User
|
||||||
fields = ("username", "email", "facebook", "twitter", "sponsorid", "matrixid")
|
fields = ("username", "email", "facebook", "twitter", "sponsorid", "matrixid")
|
||||||
|
|
||||||
|
|
||||||
class CustomUserChangeForm(UserChangeForm):
|
class CustomUserChangeForm(UserChangeForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CustomUser
|
model = User
|
||||||
fields = ("username", "email", "facebook", "twitter", "sponsorid", "matrixid")
|
fields = ("username", "email", "facebook", "twitter", "sponsorid", "matrixid")
|
||||||
|
|
||||||
|
|
||||||
class CustomUserLoginForm(AuthenticationForm):
|
class CustomUserLoginForm(AuthenticationForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
Model = CustomUser
|
Model = User
|
||||||
fields = ("username", "password")
|
fields = ("username", "password")
|
||||||
|
|
||||||
|
|
||||||
@@ -27,11 +27,11 @@ class SignUpForm(CustomUserCreationForm):
|
|||||||
matrixid = forms.CharField(max_length=30, required=False, help_text='Optional.')
|
matrixid = forms.CharField(max_length=30, required=False, help_text='Optional.')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CustomUser
|
model = User
|
||||||
fields = ("username", "email", "matrixid")
|
fields = ("username", "email", "matrixid")
|
||||||
|
|
||||||
|
|
||||||
class UserLoginForm(CustomUserLoginForm):
|
class UserLoginForm(CustomUserLoginForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CustomUser
|
model = User
|
||||||
|
|||||||
@@ -111,32 +111,39 @@ class Navigation(models.Model):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
class CustomUser(AbstractUser):
|
class User(AbstractUser):
|
||||||
facebook = models.CharField(max_length=255, null=True)
|
facebook = models.CharField(max_length=255, null=True)
|
||||||
twitter = models.CharField(max_length=255, null=True)
|
twitter = models.CharField(max_length=255, null=True)
|
||||||
ulvl = models.IntegerField(default=1)
|
ulvl = models.IntegerField(default=1)
|
||||||
sponsorid = models.IntegerField(null=True)
|
sponsorid = models.IntegerField(null=True)
|
||||||
matrixid = models.CharField(max_length=255, null=True)
|
matrixid = models.CharField(max_length=255, null=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.username
|
||||||
|
|
||||||
|
|
||||||
class Favorites(models.Model):
|
class Favorites(models.Model):
|
||||||
"""
|
"""
|
||||||
pyShelfs User Database class
|
Favorites Database class
|
||||||
:param uname: User Name
|
:param book: book foreign key
|
||||||
:param fname: First Name
|
:param user: user foreign key
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "favorites"
|
db_table = "favorites"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
pass
|
||||||
|
# return self.book
|
||||||
book = models.ForeignKey(Books.id, on_delete=models.PROTECT)
|
|
||||||
user = models.ForeignKey(get_user_model(), on_delete=models.PROTECT)
|
book = models.ForeignKey(Books, on_delete=models.CASCADE)
|
||||||
|
user = models.ForeignKey(
|
||||||
|
User,
|
||||||
|
on_delete=models.CASCADE
|
||||||
|
)
|
||||||
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("user"),).filter(
|
||||||
search=query
|
search=query
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from django.conf import settings
|
|||||||
from django.contrib.auth import get_user_model
|
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, CustomUser
|
from .models import Books, Collections, Navigation, Favorites, User
|
||||||
|
|
||||||
config = Config(Path("../"))
|
config = Config(Path("../"))
|
||||||
|
|
||||||
@@ -51,11 +51,13 @@ def signup(request):
|
|||||||
def userlogin(request):
|
def userlogin(request):
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
breakpoint()
|
||||||
username = request.POST['username']
|
username = request.POST['username']
|
||||||
password = request.POST['password']
|
password = request.POST['password']
|
||||||
user = authenticate(request, username=username, password=password)
|
user = authenticate(request, username=username, password=password)
|
||||||
if user is not None:
|
if user is not None:
|
||||||
login(request, user)
|
login(request, user)
|
||||||
|
user.save()
|
||||||
return redirect('home')
|
return redirect('home')
|
||||||
form = UserLoginForm()
|
form = UserLoginForm()
|
||||||
return render(request, 'login.html', {'form': form})
|
return render(request, 'login.html', {'form': form})
|
||||||
@@ -219,9 +221,9 @@ def favorite(request, pk):
|
|||||||
"""
|
"""
|
||||||
Add book to favorites bu primary key
|
Add book to favorites bu primary key
|
||||||
"""
|
"""
|
||||||
breakpoint()
|
|
||||||
f = Favorites(book=Books.objects.get(pk=pk))
|
f = Favorites(book=Books.objects.get(pk=pk))
|
||||||
f.save
|
f.user = request.user
|
||||||
|
f.save()
|
||||||
return redirect('home')
|
return redirect('home')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user