This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!- ALong with other HTML --> | |
<button type="button" class="btn btn-light btn-block border mt-2 update-wishlist" data-action="add" data-product="{{ product.productID }}"> | |
<span class="text"> Add to Wishlist</span> | |
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('load',function () { | |
console.log('Loaded') | |
let wislistBtns = document.querySelectorAll('.update-wishlist') | |
if (wislistBtns) { | |
for (let i = 0; i < wislistBtns.length; i++) { | |
wislistBtns[i].addEventListener('click', function () { | |
const productID = this.dataset.product | |
const action = this.dataset.action | |
console.log('productID:', productID, 'Action:', action) | |
if (user === 'AnonymousUser') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updateUserWishlist(productID,action){ | |
console.log('user:',user,' is Authenticated, sending data') | |
let url= '/api/update_wishlist/' | |
fetch(url,{ | |
method:'PUT', | |
headers:{ | |
'Content-Type':'application/json', | |
'X-CSRFToken':csrftoken, | |
}, | |
body:JSON.stringify({'productID':productID, 'action':action}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Application definition | |
INSTALLED_APPS = [ | |
'rest_framework', | |
'serverapi.apps.ServerapiConfig', | |
'otherapp', | |
'otherapp2', | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# serverapi\urls.py | |
from django.urls import path | |
from serverapi import views | |
appname = 'serverapi' | |
urlpatterns = [ | |
path('update_wishlist/', views.updateWishlist, name='updateWishlist'), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# yourproject\urls.py | |
# add your other necessary imports | |
urlspatterns = [ | |
re_path('^api/', include(('serverapi.urls', 'serverapi'), namespace='api')), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# serverapi\view.py | |
from rest_framework.decorators import api_view | |
from django.http import JsonResponse | |
@api_view(['PUT']) | |
def updateWishlist(request): | |
data = json.loads(request.body) | |
productID = data['productID'] | |
action = data['action'] | |
print('ProductID:', productID) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let user = '{{ request.user }}' | |
function getToken(name) { | |
let cookieValue = null; | |
if (document.cookie && document.cookie !== '') { | |
const cookies = document.cookie.split(';'); | |
for (let i = 0; i < cookies.length; i++) { | |
const cookie = cookies[i].trim(); | |
// Does this cookie string begin with the name we want? | |
if (cookie.substring(0, name.length + 1) === (name + '=')) { | |
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_precision_recall_vs_threshold(precisions, recalls, thresholds, metric_name=None, metric_perc=None): | |
plt.figure(figsize=(15, 10)) | |
plt.plot(thresholds, precisions[:-1], 'b--', label='Precision') | |
plt.plot(thresholds, recalls[:-1], 'g-', label='Recall') | |
plt.xlabel('Threshold', fontsize=15) | |
plt.axis([-50000, 50000, 0, 1]) | |
plt.legend(loc='best', fontsize=16) | |
if metric_name=='precision': | |
metric = precisions |
OlderNewer