Skip to content

Commit

Permalink
Bch address (#2095)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak5598 authored May 14, 2024
1 parent 9cdbd70 commit 746db8b
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 34 deletions.
11 changes: 10 additions & 1 deletion website/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ class WinnerAdmin(admin.ModelAdmin):


class BidAdmin(admin.ModelAdmin):
list_display = ("issue_url", "user", "pr_link", "amount", "status", "created", "modified")
list_display = (
"user",
"issue_url",
"pr_link",
"amount",
"bch_address",
"status",
"created",
"modified",
)


class WalletAdmin(admin.ModelAdmin):
Expand Down
11 changes: 10 additions & 1 deletion website/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ class Meta:
class BidForm(forms.ModelForm):
class Meta:
model = Bid
fields = ["issue_url", "user", "created", "modified", "amount", "status", "pr_link"]
fields = [
"user",
"issue_url",
"created",
"modified",
"amount",
"status",
"pr_link",
"bch_address",
]
17 changes: 17 additions & 0 deletions website/migrations/0093_bid_bch_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.0.2 on 2024-05-14 05:44

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("website", "0092_merge_0091_bid_0091_remove_company_company_id"),
]

operations = [
migrations.AddField(
model_name="bid",
name="bch_address",
field=models.CharField(blank=True, max_length=45, null=True),
),
]
3 changes: 2 additions & 1 deletion website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,14 @@ def __str__(self):


class Bid(models.Model):
issue_url = models.URLField()
user = models.CharField(default="Add user", max_length=30, null=True, blank=True)
issue_url = models.URLField()
created = models.DateTimeField(default=timezone.now)
modified = models.DateTimeField(default=timezone.now)
amount = models.IntegerField()
status = models.CharField(default="Open", max_length=10)
pr_link = models.URLField(blank=True, null=True)
bch_address = models.CharField(blank=True, null=True, max_length=45)

# def save(self, *args, **kwargs):
# if (
Expand Down
14 changes: 4 additions & 10 deletions website/templates/bidding.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
font-weight: bold;
}

#issueLinkInput,
#bid_amount,
#user {
#issueLinkInput, #bid_amount {
width: 100%;
padding: 8px;
margin-bottom: 10px;
Expand Down Expand Up @@ -89,9 +87,7 @@
.then(data => {
if ('current_bid' in data) {
const currentBid = data.current_bid;
const time_left = data.time_left;
const status = data.status;
document.getElementById('BidDisplay').innerHTML = `Current Bid: ${currentBid} <br> Time Left: <span id="timer">${formatTime(time_left)}</span> <br> Status : ${status}`;
document.getElementById('BidDisplay').innerHTML = `Current Bid: ${currentBid} <br>`;
const bidAmountInput = document.getElementById('bid_amount');
bidAmountInput.setAttribute('max', currentBid - 1);

Expand Down Expand Up @@ -157,13 +153,11 @@
<p id="invalidUrlMessage">Please enter a valid GitHub link</p>
<p id="BidDisplay"></p>
<br>
<label>Github UserName:</label>
<input type="text" id="user" name="user" required>
<br>
<label id="bidamount">New Bid:</label>
<input type="number" id="bid_amount" name="bid_amount" required min="1">
<br>
<button type="submit" id="submitBid">Submit Bid</button>
<button type="submit" id="submitBid" onclick="OnSubmit()">Submit Bid</button>
<p type="hidden" id="verifycode"></p>
</form>
</div>
<div id="Link_pr">
Expand Down
32 changes: 22 additions & 10 deletions website/templates/submit_pr.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

label {
#label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}

#issue_link,
#user,#bid_amount {
#bch_label, #pr_label {
display: none;
}

#issue_link, #bid_amount {
width: 100%;
padding: 8px;
margin-bottom: 10px;
Expand All @@ -46,8 +49,14 @@
#BidDisplay {
margin-bottom: 10px;
}
#pr_link{
#pr_link,#bch_address {
display: none;
width: 100%;
padding: 8px;
margin-bottom: 10px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 3px;
}
#Link_bid {
text-align: center;
Expand Down Expand Up @@ -91,22 +100,24 @@
.then(data => {
if('current_bid' in data) {
const currentBid = data.current_bid;
const date = data.date;
const user = data.user;
const status = data.status;
if(status === "Selected") {
document.getElementById('pr_label').style.display = "block";
document.getElementById('bch_label').style.display = "block";
document.getElementById('pr_link').style.display = "block";
document.getElementById('bch_address').style.display = "block";
}
else if (status === "Submitted") {
document.getElementById('pr_label').style.display = "block";
document.getElementById('pr_label').textContent="PR is submitted , Please contact your repository head ";
}
else{
document.getElementById('pr_label').style.display = "block";
document.getElementById('pr_link').style.display = "none";
document.getElementById('pr_label').textContent="Bid is not selected : Status is Open/Closed";
}
document.getElementById('user').value = user;
document.getElementById('bid_amount').value = currentBid;
document.getElementById('BidDisplay').innerHTML = `User: ${user} <br> CurrentBid: ${currentBid} <br> Bid Date: ${date} <br> Status: ${status}`;
document.getElementById('BidDisplay').innerHTML = `CurrentBid: ${currentBid} <br>`;
}
else{
document.getElementById('BidDisplay').innerHTML = 'No current bid';
Expand All @@ -133,13 +144,14 @@
<div>
<form id="submit_pr"action="{% url 'submit_pr' %}" method="post">
{% csrf_token %}
<label>Issue Link</label>
<label id="label">Issue Link</label>
<input type="text" name="issue_link" id="issue_link">
<button id="fetch" type="button" onclick="fetchData()">Fetch data</button>
<p id="invalidUrlMessage">Please enter a valid GitHub link</p>
<p id="BidDisplay"></p>
<input type="hidden" name="user" id="user">
<input type="hidden" name="bid_amount" id="bid_amount">
<label id="bch_label">Add you BCH Address</label>
<input type="text" name="bch_address" id="bch_address" required>
<label id="pr_label">Link to your Pull Request</label>
<input type="text" name="pr_link" id="pr_link" required>
<button type="submit" id="submit">Submit</button>
Expand Down
25 changes: 14 additions & 11 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4405,50 +4405,50 @@ def deletions(request):


def generate_bid_image(request, bid_amount):
image = Image.new("RGB", (100, 50), color="white")
image = Image.new("RGB", (300, 100), color="white")
draw = ImageDraw.Draw(image)

font = ImageFont.load_default()
draw.text((10, 10), f"Bid: ${bid_amount}", fill="black", font=font)

draw.text((10, 10), f"Bid Amount: ${bid_amount}", fill="black", font=font)
byte_io = io.BytesIO()
image.save(byte_io, format="PNG")
byte_io.seek(0)

return HttpResponse(byte_io, content_type="image/png")


@login_required
def SaveBiddingData(request):
if request.method == "POST":
user = request.user.username
url = request.POST.get("issue_url")
amount = request.POST.get("bid_amount")
user = request.POST.get("user")
current_time = datetime.now(timezone.utc)
bid = Bid(
user=user,
issue_url=url,
amount=amount,
created=current_time,
modified=current_time,
user=user,
)
bid.save()
return render(request, "bidding.html")
bid_link = f"https://blt.owasp.org/generate_bid_image/{amount}/"
return JsonResponse({"Paste this in GitHub Issue Comments:": bid_link})

return render(request, "bidding.html")


def fetch_current_bid(request):
if request.method == "POST":
unique_issue_links = Bid.objects.values_list("issue_url", flat=True).distinct()
data = json.loads(request.body)
issue_url = data.get("issue_url")
bid = Bid.objects.filter(issue_url=issue_url).order_by("-created").first()
if bid is not None:
return JsonResponse(
{
"issueLinks": list(unique_issue_links),
"current_bid": bid.amount,
"time_left": (bid.created - datetime.now(timezone.utc)).total_seconds() + 86400,
"date": bid.created,
"user": bid.user,
"status": bid.status,
}
)
Expand All @@ -4458,22 +4458,25 @@ def fetch_current_bid(request):
return JsonResponse({"error": "Method not allowed"}, status=405)


@login_required
def submit_pr(request):
if request.method == "POST":
user = request.user.username
pr_link = request.POST.get("pr_link")
user = request.POST.get("user")
amount = request.POST.get("bid_amount")
issue_url = request.POST.get("issue_link")
status = "Submitted"
current_time = datetime.now(timezone.utc)
bch_address = request.POST.get("bch_address")
bid = Bid(
pr_link=pr_link,
user=user,
pr_link=pr_link,
amount=amount,
issue_url=issue_url,
status=status,
created=current_time,
modified=current_time,
bch_address=bch_address,
)
bid.save()
return render(request, "submit_pr.html")
Expand Down

0 comments on commit 746db8b

Please sign in to comment.