Made the site user-specific.

Only the logged in user has the ability to bid on items, make their own store, and start auctions.
Removed temp html files.
Co-authored-by: 's avatarpinkboheme <pinkboheme@users.noreply.github.com>
Co-authored-by: 's avatarChristine <cdeeerrr@users.noreply.github.com>
parent d36c3c35
......@@ -76,7 +76,7 @@
{% if auction_bids %}
{% for bid in auction_bids %}
<li><img src="" alt="">
<p>{{bid.boodleuserid.displayname}} offered {{ bid.amount }}</p>
<p>{{bid.userid.username}} offered {{ bid.amount }}</p>
<p> &nbsp | &nbsp </p>
<p>{{bid.bidtime | timesince}} ago </p>
......
......@@ -38,8 +38,7 @@
<li><a href="/">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Help</a></li>
<li><a href="/profile">My Profile</a></li>
<li><a href="/store">My Store</a></li>
<li><a href="{% url 'profileid' request.user.id %}">My Profile</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
</ul>
</nav>
......
{% extends 'boodlesite\templates\base.html' %}
{% load static %}
{% block title %}My Profile{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<h2>This is a temp page to access userid 1 (and not thru the navbar)</h2>
<p>Remove this page once nav bar is personalized that it
accesses the logged in user's profile</p>
<h1 text-align="center">Link to My Profile: <a href="{% url 'profileid' user_one.userid %}">{{ user_one.userid }}</a></h1>
<h1 text-align="center">Link to My OTHER Profile: <a href="{% url 'profileid' user_two.userid %}">{{user_two.userid}}</a></h1>
{% endblock %}
\ No newline at end of file
{% extends 'boodlesite\templates\base.html' %}
{% load static %}
{% block title %}My Store{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<h2>This is a temp page to access storeid 1 (and not thru the navbar)</h2>
<p>Remove this page once nav bar is personalized that it accesses the logged in user's store</p>
<h1 text-align="center">Link to My Store: <a href="{% url 'storeid' current_store.storeid %}">{{ current_store.storename }}</a></h1>
{% endblock %}
\ No newline at end of file
......@@ -21,9 +21,9 @@ from django.core.exceptions import ValidationError
class PlaceBidForm(forms.ModelForm):
class Meta:
model = AuctionBid
fields = ['amount', 'boodleuserid', 'auctionid']
fields = ['amount', 'userid', 'auctionid']
widgets = {'auctionid': forms.HiddenInput(),
'boodleuserid': forms.HiddenInput()
'userid': forms.HiddenInput()
}
def clean(self):
......@@ -118,13 +118,12 @@ class CreateStoreForm(forms.ModelForm):
class editBoodleUserForm(forms.ModelForm):
class Meta:
model = BoodleUser
fields = ['displayname', 'username', 'userid']
widgets = {'userid': forms.HiddenInput()}
model = AuthUser
fields = ['username', 'id']
widgets = {'id': forms.HiddenInput()}
labels = {
'username': _('User Name'),
'displayname': _('Display Name')
'username': _('User Name')
}
class CreateUserForm(UserCreationForm):
......
......@@ -26,7 +26,7 @@ class AuctionBid(models.Model):
amount = models.DecimalField(max_digits=15, decimal_places=4)
bidtime = models.DateTimeField(blank=True, null=True)
auctionid = models.ForeignKey(Auction, models.DO_NOTHING, db_column='auctionid')
boodleuserid = models.ForeignKey('BoodleUser', models.DO_NOTHING, db_column='boodleuserid')
userid = models.ForeignKey('AuthUser', models.DO_NOTHING, db_column='userid')
class Meta:
managed = False
......@@ -99,20 +99,6 @@ class AuthUserUserPermissions(models.Model):
unique_together = (('user', 'permission'),)
class BoodleUser(models.Model):
userid = models.AutoField(primary_key=True)
displayname = models.CharField(max_length=255)
pword = models.CharField(max_length=255)
username = models.CharField(max_length=255)
class Meta:
managed = False
db_table = 'boodleuser'
def __str__(self):
return '%s' % (self.userid)
class DjangoAdminLog(models.Model):
action_time = models.DateTimeField()
object_id = models.TextField(blank=True, null=True)
......@@ -178,11 +164,8 @@ class Store(models.Model):
storeid = models.AutoField(primary_key=True)
storename = models.CharField(max_length=255)
storedesc = models.CharField(max_length=700)
userid = models.ForeignKey(BoodleUser, models.DO_NOTHING, db_column='userid', blank=True, null=True)
userid = models.ForeignKey(AuthUser, models.DO_NOTHING, db_column='userid', blank=True, null=True)
class Meta:
managed = False
db_table = 'store'
def __str__(self):
return '%s' % (self.storeid)
\ No newline at end of file
......@@ -8,7 +8,7 @@ urlpatterns = [
path('auction', auction, name='auction'),
path('auction/<int:pk>/',auction, name='auctionid'),
path('error404', error404, name='error404'),
path('store', tempstore, name='store'), # this is tempstore
# path('store', tempstore, name='store'), # this is tempstore
path('store/<int:pk>', mystore, name='storeid'),
path('additem', addItem, name='additem'),
path('additem/<int:pk>', addItem, name='additemid'),
......@@ -17,7 +17,7 @@ urlpatterns = [
path('startauction', startAuction, name='startauction'),
path('startauction/<int:pk>', startAuction, name='startauctionid'),
# this is tempuser profile
path('profile', tempProfile, name='profile'),
# path('profile', tempProfile, name='profile'),
path('profile/<int:pk>', profile, name='profileid'),
path('editstore/<int:pk>', editStore, name='editstoreid'),
path('editProfile/<int:pk>', editProfile, name='editProfile'),
......
......@@ -26,7 +26,12 @@ def registerPage(request):
if form.is_valid():
form.save()
user_name = form.cleaned_data.get('username')
password = form.cleaned_data.get('password1')
messages.success(request, 'Account was create for ' + user_name)
# boodleuser_inst = BoodleUser.objects.create(displayname=user_name, pword=password, username=user_name)
# boodleuser_inst.save()
return redirect('login')
......@@ -34,6 +39,7 @@ def registerPage(request):
return render(request, 'boodlesite/templates/registration/register.html', context)
def loginPage(request):
# dont want a logged in user to see this
if request.user.is_authenticated:
return redirect('/')
......@@ -90,23 +96,24 @@ def auction(request,pk):
highest_bid = auction_item.floorprice
## ⭐ the user that is logged in
users = BoodleUser.objects.get(userid=3)
userid = users.userid
users = AuthUser.objects.get(id=request.user.id)
userid = users.id
if auction_bids:
highest_bid = auction_bids[0].amount
# PLACE BID FORM AND ADD TO FAVES FORM
form = PlaceBidForm(initial={'auctionid':auction, 'boodleuserid':users})
form = PlaceBidForm(initial={'auctionid':auction, 'userid':userid})
if request.method == 'POST':
form = PlaceBidForm(request.POST,initial={'auctionid':auction, 'boodleuserid':users})
form = PlaceBidForm(request.POST,initial={'auctionid':auction, 'userid':userid})
if form.is_valid():
try:
amount = form.cleaned_data['amount']
# saves the bid by auctionid, amount, bidtime, boodleuserid
new_bid = AuctionBid(
amount=amount, bidtime=datetime.now(),
auctionid=auction, boodleuserid=users)
auctionid=auction, userid=users)
new_bid.save()
return redirect(f"/auction/{pk}")
except Exception as e:
......@@ -120,7 +127,7 @@ def auction(request,pk):
'highest_bid': highest_bid,
'auction_title': auction.title,
'auction_end': auction.auctionend,
'user_profile': userid,
'user_profile': users,
'form' : form,
}
......@@ -135,18 +142,6 @@ def auction(request,pk):
def error404(request):
return render(request, "boodlesite/templates/error404/notstarted_error404.html")
@login_required(login_url='login')
def tempstore(request): # temp view
#### Access to store 1 [ edit accordingly when it becomes accessible thru a user ] ####
current_store = Store.objects.get(storeid=1)
context = {
'current_store':current_store #### used for navbar, access to store 1
}
return render(request, "boodlesite/templates/tempstore.html", context)
@login_required(login_url='login')
def mystore(request, pk):
......@@ -231,8 +226,8 @@ def startAuction(request, pk):
# get items under this store
store_items = Item.objects.filter(storeid=pk)
# Current userid, change as per ⭐ whoever is logged in
user = BoodleUser.objects.get(userid=3)
userid = user.userid
user = AuthUser.objects.get(id=request.user.id)
userid = user.id
# temp: all auctions
all_auctions = Auction.objects.all()
......@@ -263,27 +258,13 @@ def startAuction(request, pk):
return render(request, "boodlesite/templates/startauction.html", context)
@login_required(login_url='login')
def tempProfile(request): # temp view
#### Access to store 1 [ edit accordingly when it becomes accessible thru a user ] ####
user_one =BoodleUser.objects.get(userid=1) # shrek
user_two = BoodleUser.objects.get(userid=3) ## tony
context = {
'user_one':user_one, #### used for navbar, access to user1
'user_two':user_two, #### used for navbar, access to user1
}
return render(request, "boodlesite/templates/tempprofile.html", context)
@login_required(login_url='login')
def profile(request, pk):
current_user = BoodleUser.objects.get(pk=pk)
current_user = AuthUser.objects.get(pk=pk)
#auction bid user id = 3 --> bids user made --> know auctions g
## ⭐ the user that is logged in
bids_by_user = AuctionBid.objects.filter(boodleuserid=3).distinct('auctionid')
bids_by_user = AuctionBid.objects.filter(userid=pk).distinct('auctionid')
auctions_of_user = Auction.objects.all().distinct('auctionid')
ids_of_auction = []
......@@ -300,14 +281,14 @@ def profile(request, pk):
auctions = Auction.objects.all()
# 🔥Current Store, pk here is the storeid
current_user = BoodleUser.objects.get(pk=pk)
current_user = AuthUser.objects.get(pk=pk)
form = CreateStoreForm(initial={'userid':pk})
current_store = Store.objects.filter(userid=current_user.userid)
current_store = Store.objects.filter(userid=current_user.id)
current_storeid = None
for i in current_store:
current_storeid = i
current_storeid = i.storeid
if request.method == 'POST':
form = CreateStoreForm(request.POST, initial={'userid':pk})
......@@ -318,9 +299,9 @@ def profile(request, pk):
# 🔥
context = {
'displayname': current_user.displayname,
'displayname': current_user.username,
'username': current_user.username,
'user': current_user.userid,
'user': current_user.id,
'store': current_storeid,
'bidsByUser' : bids_by_user,
'auctions_of_user': auctions_of_user,
......@@ -354,8 +335,8 @@ def editStore(request, pk):
@login_required(login_url='login')
def editProfile(request, pk):
user= BoodleUser.objects.get(userid=pk) # boodleuser object
current_user = user.userid #boodle user id
user= AuthUser.objects.get(id=pk) # authuser object
current_user = user.id # auth user id
form = editBoodleUserForm(instance=user)
if request.method == 'POST':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment