summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2023-11-10 10:56:32 -0500
committerluxagraf <sng@luxagraf.net>2023-11-10 10:56:32 -0500
commitda500a836a753a5d7eb286aba30d2660a0a7e7fd (patch)
tree275244edff40d424bfdac2c35f3f7c7c473611ed
parent6fd1d244ed604df14de86a33c3298cca5da510c6 (diff)
Deals: brought up to speed with BF deals tables
-rw-r--r--app/deals/admin.py10
-rw-r--r--app/deals/migrations/0018_reideal_alter_mydeal_body.py34
-rw-r--r--app/deals/migrations/0019_reideal_generate_deal.py18
-rw-r--r--app/deals/migrations/0020_mydeal_added.py18
-rw-r--r--app/deals/migrations/0021_deal_added_to_article.py18
-rw-r--r--app/deals/migrations/0022_alter_deal_added_to_article.py18
-rw-r--r--app/deals/migrations/0023_remove_deal_added_to_article_deal_deal_end_date_and_more.py27
-rw-r--r--app/deals/models.py116
-rw-r--r--app/deals/templates/deals/mydeal_list.html2
-rw-r--r--app/deals/templates/deals/reideal_list.html60
-rw-r--r--app/deals/urls.py5
-rw-r--r--app/deals/views.py13
12 files changed, 324 insertions, 15 deletions
diff --git a/app/deals/admin.py b/app/deals/admin.py
index 3686309..f4c6009 100644
--- a/app/deals/admin.py
+++ b/app/deals/admin.py
@@ -4,7 +4,7 @@ from django.contrib.gis.admin import OSMGeoAdmin
from django.contrib.contenttypes.admin import GenericStackedInline
from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter, ChoiceDropdownFilter
-from .models import Deal, Brand, MyDeal
+from .models import Deal, Brand, MyDeal, REIDeal
@admin.register(Deal)
@@ -42,3 +42,11 @@ class MyDealAdmin(OSMGeoAdmin):
}
),
)
+
+
+@admin.register(REIDeal)
+class DealAdmin(OSMGeoAdmin):
+ list_display = ('title', 'rei_link', 'brand_str', 'category', 'deal_price', 'original_price', 'generate_deal' )
+ search_fields = ['brand_str', 'title', ]
+ list_filter = ('category', 'brand_str',)
+ list_editable = ('generate_deal',)
diff --git a/app/deals/migrations/0018_reideal_alter_mydeal_body.py b/app/deals/migrations/0018_reideal_alter_mydeal_body.py
new file mode 100644
index 0000000..627e54f
--- /dev/null
+++ b/app/deals/migrations/0018_reideal_alter_mydeal_body.py
@@ -0,0 +1,34 @@
+# Generated by Django 4.2.2 on 2023-08-22 14:22
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('deals', '0017_mydeal_blurb'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='REIDeal',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('brand_str', models.CharField(max_length=200)),
+ ('category', models.CharField(max_length=200)),
+ ('title', models.CharField(blank=True, max_length=200, null=True)),
+ ('deal_price', models.CharField(max_length=20, null=True)),
+ ('original_price', models.CharField(max_length=20, null=True)),
+ ('discount_percent_str', models.CharField(max_length=20, null=True)),
+ ('url', models.CharField(max_length=200)),
+ ],
+ options={
+ 'ordering': ('title',),
+ },
+ ),
+ migrations.AlterField(
+ model_name='mydeal',
+ name='body',
+ field=models.TextField(blank=True, null=True),
+ ),
+ ]
diff --git a/app/deals/migrations/0019_reideal_generate_deal.py b/app/deals/migrations/0019_reideal_generate_deal.py
new file mode 100644
index 0000000..7c0e849
--- /dev/null
+++ b/app/deals/migrations/0019_reideal_generate_deal.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.2 on 2023-08-22 14:30
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('deals', '0018_reideal_alter_mydeal_body'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='reideal',
+ name='generate_deal',
+ field=models.BooleanField(default=False),
+ ),
+ ]
diff --git a/app/deals/migrations/0020_mydeal_added.py b/app/deals/migrations/0020_mydeal_added.py
new file mode 100644
index 0000000..678c7db
--- /dev/null
+++ b/app/deals/migrations/0020_mydeal_added.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.2 on 2023-10-06 13:19
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('deals', '0019_reideal_generate_deal'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='mydeal',
+ name='added',
+ field=models.BooleanField(default=False),
+ ),
+ ]
diff --git a/app/deals/migrations/0021_deal_added_to_article.py b/app/deals/migrations/0021_deal_added_to_article.py
new file mode 100644
index 0000000..0c8d9ee
--- /dev/null
+++ b/app/deals/migrations/0021_deal_added_to_article.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.2 on 2023-10-09 18:02
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('deals', '0020_mydeal_added'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='deal',
+ name='added_to_article',
+ field=models.BooleanField(default=True),
+ ),
+ ]
diff --git a/app/deals/migrations/0022_alter_deal_added_to_article.py b/app/deals/migrations/0022_alter_deal_added_to_article.py
new file mode 100644
index 0000000..0a66baa
--- /dev/null
+++ b/app/deals/migrations/0022_alter_deal_added_to_article.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.2 on 2023-10-09 18:02
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('deals', '0021_deal_added_to_article'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='deal',
+ name='added_to_article',
+ field=models.BooleanField(default=False),
+ ),
+ ]
diff --git a/app/deals/migrations/0023_remove_deal_added_to_article_deal_deal_end_date_and_more.py b/app/deals/migrations/0023_remove_deal_added_to_article_deal_deal_end_date_and_more.py
new file mode 100644
index 0000000..dadaebf
--- /dev/null
+++ b/app/deals/migrations/0023_remove_deal_added_to_article_deal_deal_end_date_and_more.py
@@ -0,0 +1,27 @@
+# Generated by Django 4.2.7 on 2023-11-10 14:55
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('deals', '0022_alter_deal_added_to_article'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='deal',
+ name='added_to_article',
+ ),
+ migrations.AddField(
+ model_name='deal',
+ name='deal_end_date',
+ field=models.DateTimeField(null=True),
+ ),
+ migrations.AddField(
+ model_name='deal',
+ name='deal_start_date',
+ field=models.DateTimeField(null=True),
+ ),
+ ]
diff --git a/app/deals/models.py b/app/deals/models.py
index a4fd875..4f38cd1 100644
--- a/app/deals/models.py
+++ b/app/deals/models.py
@@ -30,6 +30,8 @@ class Deal(models.Model):
discount_percent_str = models.CharField(max_length=20, null=True)
discount_percent = models.FloatField(null=True)
url = models.CharField(max_length=200)
+ deal_start_date = models.DateTimeField(null=True)
+ deal_end_date = models.DateTimeField(null=True)
class Meta:
ordering = ('title',)
@@ -62,6 +64,39 @@ class Deal(models.Model):
admin_link.short_description = 'Link'
+class REIDeal(models.Model):
+ brand_str = models.CharField(max_length=200)
+ category = models.CharField(max_length=200)
+ title = models.CharField(max_length=200, blank=True, null=True)
+ deal_price = models.CharField(max_length=20, null=True)
+ original_price = models.CharField(max_length=20, null=True)
+ discount_percent_str = models.CharField(max_length=20, null=True)
+ url = models.CharField(max_length=200)
+ generate_deal = models.BooleanField(default=False)
+
+ class Meta:
+ ordering = ('title',)
+
+
+ def get_deal_price_pretty(self):
+ try:
+ return "{:.0f}".format(Decimal(self.deal_price))
+ except:
+ return None
+
+ def dollars_off(self):
+ try:
+ return "{:.0f}".format(Decimal(self.original_price) - Decimal(self.deal_price))
+ except:
+ return None
+
+ def rei_link(self):
+ return format_html('<a target="_blank" href="https://%s">REI</a>' % (self.url))
+ admin_link.short_description = 'Link'
+
+ def __str__(self):
+ return self.title
+
class MyDeal(models.Model):
title = models.CharField(max_length=200, blank=True, null=True)
@@ -76,6 +111,7 @@ class MyDeal(models.Model):
tertiary_url = models.CharField(max_length=200, blank=True, null=True)
body = models.TextField(null=True, blank=True)
blurb = models.TextField(null=True)
+ added = models.BooleanField(default=False)
class Meta:
ordering = ('title',)
@@ -98,6 +134,9 @@ class MyDeal(models.Model):
admin_link.short_description = 'Link'
"""
+for deal in Deal.objects.all():
+ if deal.promo_type == "Lightning Deal":
+ deal.delete()
with open(path) as f:
reader = csv.reader(f)
@@ -116,6 +155,7 @@ with open(path) as f:
import csv
+from datetime import datetime
path = "pdelectronicsdata.csv"
with open(path) as f:
reader = csv.reader(f)
@@ -123,21 +163,23 @@ with open(path) as f:
for row in reader:
if count > 0:
print(row)
- if row[4] == "Y":
+ if row[21] == "Y":
prime = True
else:
prime = False
_, created = Deal.objects.get_or_create(
asin=row[0],
- category=row[1],
- brand_str=row[2],
- title=row[3],
+ category=row[8],
+ brand_str=row[10],
+ title=row[1],
prime_only=prime,
- promo_type=row[5],
- deal_price= row[9],
- original_price = row[10],
- discount_percent_str=row[12],
- url=row[13],
+ promo_type=row[23],
+ deal_price= row[29],
+ original_price = row[30],
+ discount_percent_str=row[35],
+ url=row[42],
+ deal_start_date=datetime.strptime(row[24], "%m/%d/%Y")
+ deal_end_date=datetime.strptime(row[25], "%m/%d/%Y")
)
count = count+1
@@ -254,11 +296,39 @@ with open(path) as f:
lookup_title = stitle,
asin = asin,
retailer = retailer,
- url = str(row[2].strip())
+ url = str(row[2].strip()),
+ body = row[4]
+ )
+ count = count+1
+
+
+
+import csv
+path = "rei.csv"
+with open(path) as f:
+ reader = csv.reader(f)
+ count = 0
+ for row in reader:
+ if count > 0:
+ print(row)
+ try:
+
+ if row[4] == "Y":
+ prime = True
+ else:
+ prime = False
+ _, created = Deal.objects.get_or_create(
+ asin=row[0],
+ category=row[1],
+ brand_str=row[2],
+ title=row[3],
+ prime_only=prime,
+ promo_type=row[5],
+ deal_price= row[9],
+ original_price = row[10],
+ discount_percent_str=row[12],
+ url=row[13],
)
- if not created:
- d.body = row[4]
- d.save()
count = count+1
@@ -294,3 +364,23 @@ driver.get("http://www.python.org")
"""
+
+"""
+
+REI Importer
+
+
+with open(path) as f:
+ reader = csv.reader(f)
+ count = 0
+ for row in reader:
+ _, created = REIDeal.objects.get_or_create(
+ category=row[3],
+ brand_str=row[5],
+ title=row[8],
+ deal_price= row[12],
+ original_price = row[11],
+ discount_percent_=row[13],
+ url=row[15],
+ )
+"""
diff --git a/app/deals/templates/deals/mydeal_list.html b/app/deals/templates/deals/mydeal_list.html
index 07a29eb..04a1a51 100644
--- a/app/deals/templates/deals/mydeal_list.html
+++ b/app/deals/templates/deals/mydeal_list.html
@@ -37,6 +37,7 @@ body {
<a class="button" href="#" onclick="CopyToClipboard('markdown');return false;">Copy Markdown</a>
<textarea id="markdown" style="min-width: 85rem; height: 45rem;">
{% for object in object_list %}
+
#### [{{object.title|title}}]({{object.url}})
+++button-group
@@ -47,6 +48,7 @@ body {
{{object.body}}
+
{%endfor%}
</textarea>
diff --git a/app/deals/templates/deals/reideal_list.html b/app/deals/templates/deals/reideal_list.html
new file mode 100644
index 0000000..91f8722
--- /dev/null
+++ b/app/deals/templates/deals/reideal_list.html
@@ -0,0 +1,60 @@
+{% load humanize %}
+<html>
+ <head>
+<style>
+body {
+ padding-top: 30px;
+}
+.button {
+ color: white;
+ padding: 1rem;
+ text-decoration: none;
+ background-color: #2ea44f;
+ border: 1px solid rgba(27, 31, 35, .15);
+ border-radius: 6px;
+ box-shadow: rgba(27, 31, 35, .1) 0 1px 0;
+ box-sizing: border-box;
+ color: #fff;
+ cursor: pointer;
+ display: inline-block;
+ font-family: -apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
+ font-size: 14px;
+ font-weight: 600;
+ line-height: 20px;
+ padding: 6px 16px;
+ position: relative;
+ text-align: center;
+ text-decoration: none;
+ user-select: none;
+ -webkit-user-select: none;
+ touch-action: manipulation;
+ vertical-align: middle;
+ white-space: nowrap;
+}
+</style>
+</head>
+<body>
+ <p>number of deals: {{deals_count}}</p>
+<textarea>
+{% for object in object_list %}
+#### [{{object.brand_str|title}} {{object.title|title}} for ${{object.get_deal_price_pretty|intcomma}} (${{object.dollars_off}} off)]({{object.url}})
+
++++button-group
+
+[REI]({{object.url}} "REI"){: target="_blank"}
+
++++
+{% endfor %}
+</textarea>
+
+ {% for object in object_list %}
+ <h4><a href="{{object.url}}">{{object.brand_str|title}} {{object.title|title}} for ${{object.get_deal_price_pretty|intcomma}} (${{object.dollars_off}} off)</a></h4>
+
++++button-group
+
+[REI]({{object.url}} "REI"){: target="_blank"}
+
++++
+ {% endfor %}
+</body>
+</html>
diff --git a/app/deals/urls.py b/app/deals/urls.py
index 277e1c4..1ff9495 100644
--- a/app/deals/urls.py
+++ b/app/deals/urls.py
@@ -5,6 +5,11 @@ from . import views
app_name = "deals"
urlpatterns = [
+ #path(
+ #pathr'<reideals>',
+ #pathviews.REIDealListView.as_view(),
+ #pathname="detail"
+ #),
path(
r'deal',
views.GenerateDealCodeView.as_view(),
diff --git a/app/deals/views.py b/app/deals/views.py
index bf0a4c8..8bd01e3 100644
--- a/app/deals/views.py
+++ b/app/deals/views.py
@@ -1,7 +1,7 @@
from django.views.generic import DetailView, ListView
from django.views.generic.base import TemplateView
-from .models import Deal, MyDeal
+from .models import Deal, MyDeal, REIDeal
class DealDetailView(DetailView):
@@ -9,6 +9,7 @@ class DealDetailView(DetailView):
class MyDealListView(ListView):
model = MyDeal
+ queryset = MyDeal.objects.filter(added=False)
class MyDealLapListView(ListView):
model = MyDeal
@@ -17,3 +18,13 @@ class MyDealLapListView(ListView):
class GenerateDealCodeView(TemplateView):
template_name = "deals/deal_code.html"
+
+
+class REIDealListView(ListView):
+ model = REIDeal
+ queryset = REIDeal.objects.filter(generate_deal=True).order_by("category")
+
+ def get_context_data(self, **kwargs):
+ context = super(REIDealListView, self).get_context_data(**kwargs)
+ context['deals_count'] = REIDeal.objects.filter(generate_deal=True).count()
+ return context