Skip to content

Commit

Permalink
Merge pull request #25 from alissatroiano/shop-int
Browse files Browse the repository at this point in the history
Update artwork model and shop views, so users can donate AI artwork to the shop
  • Loading branch information
alissatroiano authored Aug 24, 2023
2 parents 83f73fb + 409f8bb commit 0101420
Show file tree
Hide file tree
Showing 41 changed files with 427 additions and 154 deletions.
2 changes: 1 addition & 1 deletion cart/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from shop.models import Product


# Create your views here.

def view_cart(request):
Expand All @@ -18,6 +17,7 @@ def add_to_cart(request, item_id):
""" A view to add a quantity of a specific store product to the user's shopping cart """

product = get_object_or_404(Product, pk=item_id)

quantity = int(request.POST.get('quantity'))
redirect_url = request.POST.get('redirect_url')
dimension = None
Expand Down
4 changes: 2 additions & 2 deletions checkout/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from . import views
from .webhooks import webhook

Expand All @@ -8,4 +8,4 @@
path('checkout_success/<order_number>', views.checkout_success, name='checkout_success'),
path('wh/', webhook, name='webhook'),
path('cache_checkout_data/', views.cache_checkout_data, name='cache_checkout_data'),
]
]
Binary file modified db.sqlite3
Binary file not shown.
2 changes: 1 addition & 1 deletion hugo/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class StyleAdmin(admin.ModelAdmin):
@admin.register(Artwork)
class ArtworkAdmin(admin.ModelAdmin):
fields = [
'title', 'user', 'artwork_description', 'image_url', 'image', 'style', 'is_downloadable', 'is_public'
'title', 'user', 'artwork_description', 'image_url', 'image', 'style', 'is_downloadable', 'is_public', 'for_sale'
]
13 changes: 13 additions & 0 deletions hugo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,16 @@ def __init__(self, *args, **kwargs):
for field_name, field in self.fields.items():
field.widget.attrs['class'] = 'border-1 rounded shadow-sm'
field.widget.attrs['required'] = False


class AddToStoreForm(forms.ModelForm):
class Meta:
model = Artwork
fields = ['price']

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

for field_name, field in self.fields.items():
field.widget.attrs['class'] = 'border-1 rounded shadow-sm'
field.widget.attrs['required'] = False
18 changes: 18 additions & 0 deletions hugo/migrations/0007_artwork_for_sale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.2 on 2023-08-22 23:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('hugo', '0006_artwork_is_public'),
]

operations = [
migrations.AddField(
model_name='artwork',
name='for_sale',
field=models.BooleanField(default=False),
),
]
18 changes: 18 additions & 0 deletions hugo/migrations/0008_artwork_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.2 on 2023-08-23 00:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('hugo', '0007_artwork_for_sale'),
]

operations = [
migrations.AddField(
model_name='artwork',
name='price',
field=models.DecimalField(decimal_places=2, default=0, max_digits=8),
),
]
5 changes: 4 additions & 1 deletion hugo/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.db import models
from django.contrib.auth.models import User


class Style(models.Model):
name = models.CharField(max_length=254)
friendly_name = models.CharField(max_length=254, null=True, blank=True)
Expand All @@ -27,6 +26,10 @@ class Artwork(models.Model):
style = models.ForeignKey('Style', null=True, blank=True,on_delete=models.SET_NULL)
is_public = models.BooleanField(default=False)
is_downloadable = models.BooleanField(default=False)
for_sale = models.BooleanField(default=False)
price = models.DecimalField(
decimal_places=2, max_digits=8, null=False, default=0)


def get_style(s):
"""
Expand Down
4 changes: 1 addition & 3 deletions hugo/templates/artwork_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
<div class="col-12 col-sm-5">
<h1 class="display-font display-4 mb-2 text-start">{{ artwork.title }}</h1>
<h2 class="text-start body-font">By:
<a class="link-font">
{{ artwork.user }}
</a></h2>
<a href="{% url 'artist_artworks' artwork.user.username %}">{{ artwork.user }}</a></h2>
<div class="mt-3">
<i class="fas fa-quote-left fa-3x my-3 icon-main" id="quote1"></i>
<p class="text-start my-3 body-font"> "{{ artwork.artwork_description }}"</p>
Expand Down
7 changes: 6 additions & 1 deletion hugo/templates/hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h3 class="display-font">
{{ artwork.title }}</h3>
<div class="intro">
<p>by
<a href="#" class="artist-link"> {{ artwork.user }}</a>
<a href="{% url 'artist_artworks' artwork.user.username %}">{{ artwork.user }}</a></p>
</p>
{% if artwork.is_downloadable %}
<small>Downloadable</small>
Expand All @@ -121,6 +121,11 @@ <h3 class="display-font">
<a class="btn display-font" href="{% url 'artwork_detail' artwork.id %}">
VIEW ARTWORK <i class="fas fa-chevron-right"></i></a>
</div>
<div class="view-artist">
<a class="btn display-font" href="{% url 'artist_artworks' artwork.user %}">
<i class="fas fa-chevron-left"></i>
VIEW ARTIST </a>
</div>
{% if artwork.style %}
<div class="mt-lg-4">
<a class="tag-font" href="{% url 'hugo' %}?style={{ artwork.style.name }}">
Expand Down
9 changes: 9 additions & 0 deletions hugo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
email = os.environ["MINDSDB_EMAIL"]
password = os.environ["MINDSDB_PASSWORD"]

from cart.views import add_to_cart

def hugo(request):
artworks = Artwork.objects.all()
Expand Down Expand Up @@ -119,3 +120,11 @@ def add_hugo(request):
context = {'form': form}

return render(request, template, context)

def add_artwork_to_cart(request, artwork_id):
artwork = get_object_or_404(Artwork, id=artwork_id)

# Call the add_to_cart view to add the artwork to the cart
add_to_cart(request, artwork.id, quantity=1)

return redirect('cart:view_cart')
Binary file added media/image_1692748590_oqzvqt.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/image_1692755466_bvmqhy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/image_1692757967_woewfz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/image_1692758043_vkrfdf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/image_1692758483_cnexht.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/image_1692759229_gacczi.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/image_1692760246_jjbwpd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/image_1692815242_grhdns.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/image_1692816216_neprij.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/image_1692817574_ermydk.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/image_1692817670_cthjkz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/kissthegirl.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions profiles/templates/add_to_store.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

{% extends 'base.html' %}
{% load static %}

{% block extra_css %}
<link rel="stylesheet" href="{% static 'profiles/css/profile.css' %}">
{% endblock %}

{% block page_header %}
<div class="container header-container">
<div class="row">
<div class="col"></div>
</div>
</div>
{% endblock %}

{% block content %}
<div class="container pt-5">
<div class="row d-flex p-5">
<div class="col-10 offset-2">
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Add Artwork to Store</button>
</form>
</div>
</div>
</div>

{% endblock %}
40 changes: 40 additions & 0 deletions profiles/templates/profiles/add_to_store.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends 'base.html' %}
{% load static %}

{% block extra_css %}
<link rel="stylesheet" href="{% static 'profiles/css/profile.css' %}">
{% endblock %}

{% block page_header %}
<div class="container header-container">
<div class="row">
<div class="col"></div>
</div>
</div>
{% endblock %}

{% block content %}
<div class="container pt-5">
<div class="row d-flex p-5">
<div class="col-12">
<div class="text-center">
<i class="fas fa-solid fa-hand-holding-heart fa-3x mb-3"></i>
</div>
<h1 class="text-center">Donate Artwork</h1>
<hr class="my-3 my-md-4">
<p class="body-font text-center px-3 px-md-5">Set a price for your creation and add it to our shop! Proceeds from donated artwork will go to "bla bla"</p>
</div>
</div>
<div class="col-10 offset-1 justify-content-center">
<div class="card h-100 p-3 p-md-4 p-lg-5 m-lg-3">
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.price|as_crispy_field }}
<button type="submit">Add Artwork to Store</button>
</form>
</div>
</div>
</div>
</div>

{% endblock %}
22 changes: 22 additions & 0 deletions profiles/templates/profiles/artwork.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,26 @@
{% endblock %}

{% block content %}
<div class="container mt-5">
<div class="row">
<div class="col-12">
<h1>{{ artist.username }}'s Collection</h1>
</div>
</div>
<div class="row d-flex p-3">
{% for artwork in artworks %}
<div class="col-xs-8 col-sm-4">
<div class="card m-2">
<img src="{{ artwork.image.url }}" class="card-img-top img-fluid" alt="{{ artwork.title }}">
<div class="card-body">
<h5 class="card-title">{{ artwork.title }}</h5>
<p class="card-text">{{ artwork.artwork_description }}</p>
<a href="{% url 'artwork_detail' artwork.id %}" class="btn btn-primary">View Artwork</a>
</div>
</div>
</div>
{% endfor %}
</div>
</div>

{% endblock %}
9 changes: 6 additions & 3 deletions profiles/templates/profiles/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ <h3 class="display-font fw-normal mb-0">
<img class="img-fluid" src="{{ artwork.image.url }}" alt="Card image cap">
</a>
{% endif %}
<div class="card-footer bg-light d-flex justify-content-around">
<div class="col text-start">
<div class="card-footer bg-light d-flex justify-content-center">
<div class="col-4 text-start">
<a href="{% url 'edit_artwork' artwork.id %}" class="text-small text-success">Edit</a>
</div>
<div class="col text-end">
<div class="col-4 text-center">
<a href="{% url 'delete_artwork' artwork.id %}" class="text-small text-danger">Delete</a>
</div>
<div class="col-4 text-end">
<a href="{% url 'add_artwork_to_store' artwork.id %}" class="text-small text-info">DONATE</a>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions profiles/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
path('order_history/<order_number>', views.order_history, name='order_history'),
path('edit_artwork/<int:artwork_id>/', views.edit_artwork, name='edit_artwork'),
path('delete_artwork/<int:artwork_id>/', views.delete_artwork, name='delete_artwork'),
path('add_artwork_to_store/<int:artwork_id>/', views.add_artwork_to_store, name='add_artwork_to_store'),
path('artist/<str:username>/', views.artist_artworks, name='artist_artworks'),

]
33 changes: 31 additions & 2 deletions profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pandas as pd
from pandas import DataFrame
from hugo.models import Artwork
from hugo.forms import EditArtworkForm
from hugo.forms import EditArtworkForm, AddToStoreForm


def profile(request):
Expand Down Expand Up @@ -98,4 +98,33 @@ def delete_artwork(request, artwork_id):
context = {
'artwork': artwork,
}
return render(request, template, context)
return render(request, template, context)


def add_artwork_to_store(request, artwork_id):
artwork = get_object_or_404(Artwork, id=artwork_id, user=request.user)

if request.method == 'POST':
form = AddToStoreForm(request.POST, request.FILES, instance=artwork)
if form.is_valid():
artwork = form.save(commit=False)
artwork.user = request.user
artwork.for_sale = True
artwork.save()
return redirect('shop')
else:
form = AddToStoreForm()

context = {'form': form}
return render(request, 'profiles/add_to_store.html', context)


def artist_artworks(request, username):
artist = get_object_or_404(User, username=username)
artworks = Artwork.objects.filter(user=artist)

context = {
'artist': artist,
'artworks': artworks,
}
return render(request, 'profiles/artwork.html', context)
1 change: 1 addition & 0 deletions shop/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ProductAdmin(admin.ModelAdmin):
'label',
'predicted_titles',
'artwork_description',
'style',
]
autocomplete_fields = ['category']
# Add display_final_price to readonly_fields because it is a function not a db field
Expand Down
25 changes: 6 additions & 19 deletions shop/forms.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
from django import forms
from .models import Product, Category

class ArtworkDescriptionForm(forms.ModelForm):
class Meta:
model = Product
fields = ['artwork_description']
labels = {
'artwork_description': 'Artwork Description'
}
widgets = {
'artwork_description': forms.Textarea(attrs={
'rows': 3,
'placeholder': 'Describe your artwork',
'class': 'border-1 rounded shadow-sm'
})
}
from hugo.models import Artwork, Style

class ProductForm(forms.ModelForm):

Expand Down Expand Up @@ -43,7 +29,8 @@ def __init__(self, *args, **kwargs):
else:
field.widget.attrs['required'] = True

class ArtworkForm(forms.Form):
description = forms.CharField(label='Describe your artwork', widget=forms.Textarea)
artwork_description = forms.CharField(label='Artwork Description', widget=forms.Textarea)
predicted_titles = forms.JSONField(label='Predicted Titles', widget=forms.HiddenInput, required=False)
class EditProductForm(forms.ModelForm):

class Meta:
model = Product
fields = 'title', 'price'
Loading

0 comments on commit 0101420

Please sign in to comment.