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 @@ ...@@ -76,7 +76,7 @@
{% if auction_bids %} {% if auction_bids %}
{% for bid in auction_bids %} {% for bid in auction_bids %}
<li><img src="" alt=""> <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> &nbsp | &nbsp </p>
<p>{{bid.bidtime | timesince}} ago </p> <p>{{bid.bidtime | timesince}} ago </p>
......
...@@ -38,8 +38,7 @@ ...@@ -38,8 +38,7 @@
<li><a href="/">Home</a></li> <li><a href="/">Home</a></li>
<li><a href="#">About</a></li> <li><a href="#">About</a></li>
<li><a href="#">Help</a></li> <li><a href="#">Help</a></li>
<li><a href="/profile">My Profile</a></li> <li><a href="{% url 'profileid' request.user.id %}">My Profile</a></li>
<li><a href="/store">My Store</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li> <li><a href="{% url 'logout' %}">Logout</a></li>
</ul> </ul>
</nav> </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 ...@@ -21,9 +21,9 @@ from django.core.exceptions import ValidationError
class PlaceBidForm(forms.ModelForm): class PlaceBidForm(forms.ModelForm):
class Meta: class Meta:
model = AuctionBid model = AuctionBid
fields = ['amount', 'boodleuserid', 'auctionid'] fields = ['amount', 'userid', 'auctionid']
widgets = {'auctionid': forms.HiddenInput(), widgets = {'auctionid': forms.HiddenInput(),
'boodleuserid': forms.HiddenInput() 'userid': forms.HiddenInput()
} }
def clean(self): def clean(self):
...@@ -118,13 +118,12 @@ class CreateStoreForm(forms.ModelForm): ...@@ -118,13 +118,12 @@ class CreateStoreForm(forms.ModelForm):
class editBoodleUserForm(forms.ModelForm): class editBoodleUserForm(forms.ModelForm):
class Meta: class Meta:
model = BoodleUser model = AuthUser
fields = ['displayname', 'username', 'userid'] fields = ['username', 'id']
widgets = {'userid': forms.HiddenInput()} widgets = {'id': forms.HiddenInput()}
labels = { labels = {
'username': _('User Name'), 'username': _('User Name')
'displayname': _('Display Name')
} }
class CreateUserForm(UserCreationForm): class CreateUserForm(UserCreationForm):
......
...@@ -26,7 +26,7 @@ class AuctionBid(models.Model): ...@@ -26,7 +26,7 @@ class AuctionBid(models.Model):
amount = models.DecimalField(max_digits=15, decimal_places=4) amount = models.DecimalField(max_digits=15, decimal_places=4)
bidtime = models.DateTimeField(blank=True, null=True) bidtime = models.DateTimeField(blank=True, null=True)
auctionid = models.ForeignKey(Auction, models.DO_NOTHING, db_column='auctionid') 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: class Meta:
managed = False managed = False
...@@ -99,20 +99,6 @@ class AuthUserUserPermissions(models.Model): ...@@ -99,20 +99,6 @@ class AuthUserUserPermissions(models.Model):
unique_together = (('user', 'permission'),) 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): class DjangoAdminLog(models.Model):
action_time = models.DateTimeField() action_time = models.DateTimeField()
object_id = models.TextField(blank=True, null=True) object_id = models.TextField(blank=True, null=True)
...@@ -168,7 +154,7 @@ class Item(models.Model): ...@@ -168,7 +154,7 @@ class Item(models.Model):
class Meta: class Meta:
managed = False managed = False
db_table = 'item' db_table = 'item'
def __str__(self): def __str__(self):
return '%s' % (self.itemname) return '%s' % (self.itemname)
...@@ -178,11 +164,8 @@ class Store(models.Model): ...@@ -178,11 +164,8 @@ class Store(models.Model):
storeid = models.AutoField(primary_key=True) storeid = models.AutoField(primary_key=True)
storename = models.CharField(max_length=255) storename = models.CharField(max_length=255)
storedesc = models.CharField(max_length=700) 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: class Meta:
managed = False managed = False
db_table = 'store' db_table = 'store'
def __str__(self):
return '%s' % (self.storeid)
\ No newline at end of file
...@@ -8,7 +8,7 @@ urlpatterns = [ ...@@ -8,7 +8,7 @@ urlpatterns = [
path('auction', auction, name='auction'), path('auction', auction, name='auction'),
path('auction/<int:pk>/',auction, name='auctionid'), path('auction/<int:pk>/',auction, name='auctionid'),
path('error404', error404, name='error404'), 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('store/<int:pk>', mystore, name='storeid'),
path('additem', addItem, name='additem'), path('additem', addItem, name='additem'),
path('additem/<int:pk>', addItem, name='additemid'), path('additem/<int:pk>', addItem, name='additemid'),
...@@ -17,7 +17,7 @@ urlpatterns = [ ...@@ -17,7 +17,7 @@ urlpatterns = [
path('startauction', startAuction, name='startauction'), path('startauction', startAuction, name='startauction'),
path('startauction/<int:pk>', startAuction, name='startauctionid'), path('startauction/<int:pk>', startAuction, name='startauctionid'),
# this is tempuser profile # this is tempuser profile
path('profile', tempProfile, name='profile'), # path('profile', tempProfile, name='profile'),
path('profile/<int:pk>', profile, name='profileid'), path('profile/<int:pk>', profile, name='profileid'),
path('editstore/<int:pk>', editStore, name='editstoreid'), path('editstore/<int:pk>', editStore, name='editstoreid'),
path('editProfile/<int:pk>', editProfile, name='editProfile'), path('editProfile/<int:pk>', editProfile, name='editProfile'),
......
...@@ -26,7 +26,12 @@ def registerPage(request): ...@@ -26,7 +26,12 @@ def registerPage(request):
if form.is_valid(): if form.is_valid():
form.save() form.save()
user_name = form.cleaned_data.get('username') user_name = form.cleaned_data.get('username')
password = form.cleaned_data.get('password1')
messages.success(request, 'Account was create for ' + user_name) 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') return redirect('login')
...@@ -34,6 +39,7 @@ def registerPage(request): ...@@ -34,6 +39,7 @@ def registerPage(request):
return render(request, 'boodlesite/templates/registration/register.html', context) return render(request, 'boodlesite/templates/registration/register.html', context)
def loginPage(request): def loginPage(request):
# dont want a logged in user to see this # dont want a logged in user to see this
if request.user.is_authenticated: if request.user.is_authenticated:
return redirect('/') return redirect('/')
...@@ -90,23 +96,24 @@ def auction(request,pk): ...@@ -90,23 +96,24 @@ def auction(request,pk):
highest_bid = auction_item.floorprice highest_bid = auction_item.floorprice
## ⭐ the user that is logged in ## ⭐ 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: if auction_bids:
highest_bid = auction_bids[0].amount highest_bid = auction_bids[0].amount
# PLACE BID FORM AND ADD TO FAVES FORM # 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': 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(): if form.is_valid():
try: try:
amount = form.cleaned_data['amount'] amount = form.cleaned_data['amount']
# saves the bid by auctionid, amount, bidtime, boodleuserid # saves the bid by auctionid, amount, bidtime, boodleuserid
new_bid = AuctionBid( new_bid = AuctionBid(
amount=amount, bidtime=datetime.now(), amount=amount, bidtime=datetime.now(),
auctionid=auction, boodleuserid=users) auctionid=auction, userid=users)
new_bid.save() new_bid.save()
return redirect(f"/auction/{pk}") return redirect(f"/auction/{pk}")
except Exception as e: except Exception as e:
...@@ -120,7 +127,7 @@ def auction(request,pk): ...@@ -120,7 +127,7 @@ def auction(request,pk):
'highest_bid': highest_bid, 'highest_bid': highest_bid,
'auction_title': auction.title, 'auction_title': auction.title,
'auction_end': auction.auctionend, 'auction_end': auction.auctionend,
'user_profile': userid, 'user_profile': users,
'form' : form, 'form' : form,
} }
...@@ -135,18 +142,6 @@ def auction(request,pk): ...@@ -135,18 +142,6 @@ def auction(request,pk):
def error404(request): def error404(request):
return render(request, "boodlesite/templates/error404/notstarted_error404.html") 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') @login_required(login_url='login')
def mystore(request, pk): def mystore(request, pk):
...@@ -231,8 +226,8 @@ def startAuction(request, pk): ...@@ -231,8 +226,8 @@ def startAuction(request, pk):
# get items under this store # get items under this store
store_items = Item.objects.filter(storeid=pk) store_items = Item.objects.filter(storeid=pk)
# Current userid, change as per ⭐ whoever is logged in # Current userid, change as per ⭐ whoever is logged in
user = BoodleUser.objects.get(userid=3) user = AuthUser.objects.get(id=request.user.id)
userid = user.userid userid = user.id
# temp: all auctions # temp: all auctions
all_auctions = Auction.objects.all() all_auctions = Auction.objects.all()
...@@ -263,27 +258,13 @@ def startAuction(request, pk): ...@@ -263,27 +258,13 @@ def startAuction(request, pk):
return render(request, "boodlesite/templates/startauction.html", context) 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') @login_required(login_url='login')
def profile(request, pk): 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 #auction bid user id = 3 --> bids user made --> know auctions g
## ⭐ the user that is logged in ## ⭐ 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') auctions_of_user = Auction.objects.all().distinct('auctionid')
ids_of_auction = [] ids_of_auction = []
...@@ -300,14 +281,14 @@ def profile(request, pk): ...@@ -300,14 +281,14 @@ def profile(request, pk):
auctions = Auction.objects.all() auctions = Auction.objects.all()
# 🔥Current Store, pk here is the storeid # 🔥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}) 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 current_storeid = None
for i in current_store: for i in current_store:
current_storeid = i current_storeid = i.storeid
if request.method == 'POST': if request.method == 'POST':
form = CreateStoreForm(request.POST, initial={'userid':pk}) form = CreateStoreForm(request.POST, initial={'userid':pk})
...@@ -318,9 +299,9 @@ def profile(request, pk): ...@@ -318,9 +299,9 @@ def profile(request, pk):
# 🔥 # 🔥
context = { context = {
'displayname': current_user.displayname, 'displayname': current_user.username,
'username': current_user.username, 'username': current_user.username,
'user': current_user.userid, 'user': current_user.id,
'store': current_storeid, 'store': current_storeid,
'bidsByUser' : bids_by_user, 'bidsByUser' : bids_by_user,
'auctions_of_user': auctions_of_user, 'auctions_of_user': auctions_of_user,
...@@ -354,8 +335,8 @@ def editStore(request, pk): ...@@ -354,8 +335,8 @@ def editStore(request, pk):
@login_required(login_url='login') @login_required(login_url='login')
def editProfile(request, pk): def editProfile(request, pk):
user= BoodleUser.objects.get(userid=pk) # boodleuser object user= AuthUser.objects.get(id=pk) # authuser object
current_user = user.userid #boodle user id current_user = user.id # auth user id
form = editBoodleUserForm(instance=user) form = editBoodleUserForm(instance=user)
if request.method == 'POST': 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