Commit 7a9fe988 authored by Christine Dela Rosa's avatar Christine Dela Rosa

Merge branch 'mate_devbranch' into xtine

parents a0a5b25b 259563cd
......@@ -215,7 +215,7 @@ nav a {
}
.cards p {}
/*.cards p {} */
/* cards end */
......@@ -380,3 +380,16 @@ nav a {
border: 2px solid black;
padding: 1rem;
}
/* ?USER'S PROFILE */
.profile-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.profile-element {
margin-top: .5rem;
margin-bottom: .5rem;
}
\ No newline at end of file
......@@ -76,7 +76,7 @@
{% if auction_bids %}
{% for bid in auction_bids %}
<li><img src="" alt="">
<p>User offered <span id="bid-amount">₱{{ bid.amount }}</span></p>
<p>{{bid.boodleuserid.displayname}} offered {{ bid.amount }}</p>
<p> &nbsp | &nbsp </p>
<p>{{bid.bidtime | timesince}} ago </p>
......
......@@ -39,7 +39,7 @@
<li><a href="/">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Help</a></li>
<li><a href="#">My Profile</a></li>
<li><a href="/profile">My Profile</a></li>
<li><a href="/store">My Store</a></li>
</ul>
</nav>
......
......@@ -97,8 +97,7 @@
{% else %}
<p> No auctions currently happening.</p>
{% endif %}
</div>
</div>
</div>
<div class="header-container">
......
{% extends 'boodlesite\templates\base.html' %}
{% load static %}
{% block title %}Profile{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<div class="profile-container">
<div class="username-section displayname profile-element">
<h2>This is {{ displayname }}'s profile</h2>
</div>
<div class-"user-img userimage profile-element">
<img src="https://minimaltoolkit.com/images/randomdata/female/64.jpg" alt="profile-image">
</div>
<div class "username profile-element">
<h4> {{ username }} </h4>
</div>
<div class="btn-group profile-element" role="group" aria-label="Basic example">
<button type="button" class="btn btn-primary">My Store</button>
<button type="button" class="btn btn-primary">Edit Profile</button>
</div>
</div>
<!--Change auctions_now, auction to like favorites, favorite-->
<h2> Items {{displayname}} bid on </h2>
<div class="event-container">
{% if auctionsOfUser %}
{% for id in idsOfAuction %}
<div class="event">
<img src="http://via.placeholder.com/640x360" alt="">
<div class="event-text">
<a href="{% url 'auctionid' id.auctionid %}">
<h3>{{ id.title }}</h3>
</a>
<p>{{ id.auctionend }}</p>
</div>
{% comment %} <form action="" method="POST">
{% csrf_token %}
<input type="submit" name="remove-auction" value="remove auction">
</form> {% endcomment %}
</div>
{% endfor %}
{% else %}
<h3> No Favorites.</h3>
{% endif %}
</div>
</div>
{% endblock %}
{% 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
......@@ -18,8 +18,10 @@ from django.core.exceptions import ValidationError
class PlaceBidForm(forms.ModelForm):
class Meta:
model = AuctionBid
fields = ['amount','auctionid']
widgets = {'auctionid': forms.HiddenInput()}
fields = ['amount', 'boodleuserid', 'auctionid']
widgets = {'auctionid': forms.HiddenInput(),
'boodleuserid': forms.HiddenInput()
}
def clean(self):
super().clean()
......@@ -27,7 +29,6 @@ class PlaceBidForm(forms.ModelForm):
auction = self.cleaned_data.get('auctionid')
auction_item = Item.objects.get(auction=auction)
auction_bids = AuctionBid.objects.filter(auctionid=auction)
if not auction_bids:
......
# Generated by Django 4.0.3 on 2022-04-05 08:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0002_auctionbid_authgroup_authgrouppermissions_and_more'),
]
operations = [
migrations.CreateModel(
name='Boodleuser',
fields=[
('userid', models.AutoField(primary_key=True, serialize=False)),
('displayname', models.CharField(max_length=255)),
('pword', models.CharField(max_length=255)),
('username', models.CharField(max_length=255)),
],
options={
'db_table': 'boodleuser',
'managed': False,
},
),
migrations.CreateModel(
name='Store',
fields=[
('storeid', models.AutoField(primary_key=True, serialize=False)),
('storename', models.CharField(max_length=255)),
('storedesc', models.CharField(max_length=700)),
],
options={
'db_table': 'store',
'managed': False,
},
),
migrations.CreateModel(
name='Userfavorites',
fields=[
('favoriteid', models.AutoField(primary_key=True, serialize=False)),
],
options={
'db_table': 'userfavorites',
'managed': False,
},
),
]
......@@ -20,19 +20,23 @@ class Auction(models.Model):
managed = False
db_table = 'auction'
def __str__(self):
return f' {self.auctionid}'
# return f'{type(self.title)} {type(self.auctionid)}'
class AuctionBid(models.Model):
bidno = models.AutoField(primary_key=True)
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')
class Meta:
managed = False
db_table = 'auctionbid'
def __str__(self):
return '%d' % (self.amount)
# def __str__(self):
# return self.boodleuserid
class AuthGroup(models.Model):
......@@ -101,6 +105,17 @@ 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'
class DjangoAdminLog(models.Model):
action_time = models.DateTimeField()
object_id = models.TextField(blank=True, null=True)
......
......@@ -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'),
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'),
......@@ -16,5 +16,7 @@ urlpatterns = [
path('jsi18n', JavaScriptCatalog.as_view(), name='js-catlog'),
path('startauction', startAuction, name='startauction'),
path('startauction/<int:pk>', startAuction, name='startauctionid'),
# this is tempuser profile
path('profile', tempProfile, name='profile'),
path('profile/<int:pk>', profile, name='profileid'),
]
\ No newline at end of file
......@@ -21,7 +21,7 @@ def homepage(request):
# Filter by auctions scheduled at most a week from now
week_range = datetime.now() + timedelta(days=7)
auctions_soon = Auction.objects.filter(auctionstart__lt=week_range).exclude(auctionstart__lte=datetime.now())
for auction in auctions_soon: #
for auction in auctions_soon:
print(auction)
context = {
......@@ -31,33 +31,39 @@ def homepage(request):
return render(request, "boodlesite/templates/index.html",context)
def auction(request, pk):
def auction(request,pk):
# Current auction ID
auction = Auction.objects.get(pk=pk)
# Item for auction
auction_item = auction.itemid
auction_item = auction.itemid # this is the itemfk thru auction
# Auction bids
auction_bids = AuctionBid.objects.filter(auctionid=pk).order_by('-bidtime')
highest_bid = auction_item.floorprice
# who you are logged in as
users = BoodleUser.objects.get(userid=3)
userid = users.userid
if auction_bids:
highest_bid = auction_bids[0].amount
form = PlaceBidForm(initial={'auctionid':auction})
# PLACE BID FORM AND ADD TO FAVES FORM
form = PlaceBidForm(initial={'auctionid':auction, 'boodleuserid':users})
if request.method == 'POST':
form = PlaceBidForm(request.POST,initial={'auctionid':auction})
form = PlaceBidForm(request.POST,initial={'auctionid':auction, 'boodleuserid':users})
if form.is_valid():
try:
amount = form.cleaned_data['amount']
new_bid = AuctionBid(amount=amount,bidtime=datetime.now(),auctionid=auction)
# saves the bid by auctionid, amount, bidtime, boodleuserid
new_bid = AuctionBid(
amount=amount, bidtime=datetime.now(),
auctionid=auction, boodleuserid=users)
new_bid.save()
return redirect(f"/auction/{pk}")
except Exception as e:
print("Error:", e)
context = {
'item_name':auction_item.itemname,
'item_specs': auction_item.itemspecs,
......@@ -66,13 +72,13 @@ def auction(request, pk):
'highest_bid': highest_bid,
'auction_title': auction.title,
'auction_end': auction.auctionend,
'user_profile': userid,
'form' : form,
}
if auction.auctionend < datetime.now():
return HttpResponse("This auction has already passed.")
elif auction.auctionstart > datetime.now():
#return HttpResponse("This auction has not yet started.")
return render(request, "boodlesite/templates/error404/notstarted_error404.html")
else:
return render(request, "boodlesite/templates/auction.html",context)
......@@ -87,7 +93,6 @@ def tempstore(request): # temp view
context = {
'current_store':current_store #### used for navbar, access to store 1
}
return render(request, "boodlesite/templates/tempstore.html", context)
......@@ -201,3 +206,66 @@ def startAuction(request, pk):
}
return render(request, "boodlesite/templates/startauction.html", context)
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)
user_two = BoodleUser.objects.get(userid=3)
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)
def profile(request, pk):
current_user = BoodleUser.objects.get(pk=pk)
#auction bid user id = 3 --> bids user made --> know auctions g
bidsByUser = AuctionBid.objects.filter(boodleuserid=3).distinct('auctionid')
auctionsOfUser = Auction.objects.all().distinct('auctionid')
# for auction in auctionsOfUser:
# print(auction)
# print(auction.title)
# print(auction.auctionid)
#Is of auctions (FK) in AuctionBid objects
idsOfAuction = []
for bid in bidsByUser:
for auction in auctionsOfUser:
if bid.auctionid == auction:
idsOfAuction.append(bid.auctionid)
# print(auction.title)
# print(bid.auctionid)
# print("===============") #divider between auctions :3
print("These are the distinct auction IDs: ", idsOfAuction)
#💫auctionsOfUser = Auction.objects.all().distinct('auctionid')
# get existing auctions for user's bids
auctions = Auction.objects.all()
# for auction in auctionsOfUser:
# print(auction)
# for bid in bidsByUser:
# for auction in auctionsOfUser:
# if bid.auctionid == auction:
for i in idsOfAuction:
print(i)
context = {
'displayname': current_user.displayname,
'username':current_user.username,
'bidsByUser' : bidsByUser,
'auctionsOfUser': auctionsOfUser,
'auctions': auctions,
'idsOfAuction': idsOfAuction,
}
return render(request, "boodlesite/templates/profile.html", context)
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