Basic file upload
This commit is contained in:
parent
53b0c87906
commit
be6c515163
9
pflaenzli/forms.py
Normal file
9
pflaenzli/forms.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django import forms
|
||||
|
||||
from .models import User, Offer
|
||||
|
||||
|
||||
class CreateOfferForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Offer
|
||||
fields = ['title', 'description', 'zipcode', 'image']
|
41
pflaenzli/migrations/0001_initial.py
Normal file
41
pflaenzli/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
# Generated by Django 4.1.7 on 2023-02-19 12:38
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Offer",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("title", models.CharField(max_length=50)),
|
||||
("description", models.TextField(max_length=5000)),
|
||||
("zipcode", models.IntegerField(blank=True, default=0)),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
45
pflaenzli/migrations/0002_offer_created_wish.py
Normal file
45
pflaenzli/migrations/0002_offer_created_wish.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
# Generated by Django 4.1.7 on 2023-02-19 22:03
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
("pflaenzli", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="offer",
|
||||
name="created",
|
||||
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="Wish",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("created", models.DateTimeField(default=django.utils.timezone.now)),
|
||||
("title", models.CharField(max_length=200)),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
19
pflaenzli/migrations/0003_offer_image.py
Normal file
19
pflaenzli/migrations/0003_offer_image.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 4.1.7 on 2023-02-19 22:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("pflaenzli", "0002_offer_created_wish"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="offer",
|
||||
name="image",
|
||||
field=models.ImageField(default="placeholder.png", upload_to="uplaods"),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -1,3 +1,18 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils import timezone
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Offer(models.Model):
|
||||
created = models.DateTimeField(default=timezone.now)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
title = models.CharField(max_length=50)
|
||||
description = models.TextField(max_length=5000)
|
||||
zipcode = models.IntegerField(blank=True, default=0)
|
||||
image = models.ImageField(upload_to="uploads/")
|
||||
|
||||
|
||||
class Wish(models.Model):
|
||||
created = models.DateTimeField(default=timezone.now)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
title = models.CharField(max_length=200)
|
||||
|
|
BIN
pflaenzli/static/home.jpg
Normal file
BIN
pflaenzli/static/home.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 MiB |
BIN
pflaenzli/static/home2.jpg
Normal file
BIN
pflaenzli/static/home2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 MiB |
BIN
pflaenzli/static/home3.jpg
Normal file
BIN
pflaenzli/static/home3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 MiB |
BIN
pflaenzli/static/home4.jpg
Normal file
BIN
pflaenzli/static/home4.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 5 MiB |
|
@ -1,17 +0,0 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
{% block title %}New Offer{% endblock %}
|
||||
{% block javascripts %}{{ encore_entry_script_tags('fileUpload') }}{% endblock %}
|
||||
{% block content %}
|
||||
{% for message in app.flashes('error') %}
|
||||
<div class="alert alert-error" role="alert">{{ message }}</div>
|
||||
{% endfor %}
|
||||
<h1 class="mb-3">Add new offer</h1>
|
||||
{{ form_start(offer_form) }}
|
||||
{{ form_row(offer_form.title) }}
|
||||
{{ form_row(offer_form.zipCode) }}
|
||||
{{ form_row(offer_form.description) }}
|
||||
{{ form_row(offer_form.photo, {
|
||||
label: 'Choose file'
|
||||
}) }}
|
||||
{{ form_end(offer_form) }}
|
||||
{% endblock %}
|
|
@ -1,95 +0,0 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
{% block title %}Offer: {{ offer.title }}{% endblock %}
|
||||
{% block meta %}
|
||||
<meta name="description"
|
||||
content="{{ offer.byuser }} offers {{ offer.title }}!">
|
||||
<meta name="author" content="{{ offer.byUser }}">
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
{% for message in app.flashes('error') %}
|
||||
<div class="alert alert-danger" role="alert">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% for message in app.flashes('success') %}
|
||||
<div class="alert alert-success" role="success">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% if offer.byUser == user %}<div class="alert alert-info" role="alert">This is your offer!</div>{% endif %}
|
||||
<div class="show-offer-container d-flex flex-wrap">
|
||||
<div class="show-img-container">
|
||||
<img class="mb-3 img-fluid rounded"
|
||||
alt="Generic placeholder image"
|
||||
src="{{ asset('uploads/photos/' ~ offer.photofilename) }}">
|
||||
</div>
|
||||
<div class="show-offer-info w-50">
|
||||
<h1 class="mb-3">{{ offer.title }}</h1>
|
||||
<div class="mb-3 d-flex">
|
||||
<p class="pr-3">
|
||||
<i class="fas fa-user"></i>
|
||||
{% if offer.byUser == user %}
|
||||
Me
|
||||
{% else %}
|
||||
{{ offer.byUser }}
|
||||
{% endif %}
|
||||
</p>
|
||||
<p class="pr-3">
|
||||
<i class="fas fa-map-marker-alt"></i> {{ offer.zipCode }}
|
||||
</p>
|
||||
{% if distance > 0 %}
|
||||
<p class="pr-3">
|
||||
<i class="fas fa-map-signs mr-1"></i>ca. {{ distance }} km
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<h3>Description</h3>
|
||||
<p>{{ offer.description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% if offer.byUser == user %}
|
||||
<a href="{{ path('edit_offer', {'urlId': offer.urlId}) }}"
|
||||
class="btn btn-info mb-3"><i class="fas fa-pen"></i></a>
|
||||
<button type="button"
|
||||
class="btn btn-danger mb-3"
|
||||
data-toggle="modal"
|
||||
data-target="#exampleModal">
|
||||
<i class="fas fa-trash-alt"></i>
|
||||
</button>
|
||||
<!-- Modal -->
|
||||
<div class="modal fade"
|
||||
id="exampleModal"
|
||||
tabindex="-1"
|
||||
role="dialog"
|
||||
aria-labelledby="exampleModalLabel"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Warning</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">Are you sure you want to delete this offer?</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<a type="button"
|
||||
class="btn btn-danger"
|
||||
href="{{ path('delete_offer', {'urlId': offer.urlId}) }}">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<h3>Wishes</h3>
|
||||
<p>{{ offer.byUser }} would like some of the following in return:</p>
|
||||
<div class="mb-3">
|
||||
{% if wishes == [] %}
|
||||
<div class="alert alert-warning" role="alert">There are currently no wishes!</div>
|
||||
{% else %}
|
||||
<ul class="list-group">
|
||||
{% for wish in wishes %}<li class="list-group-item">{{ wish.title }}</li>{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
<a class="btn btn-pfl mb-3"
|
||||
href="{{ path('trade', {'urlId': offer.urlId}) }}">Offer trade</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -51,7 +51,7 @@
|
|||
<a class="nav-link" href="{% url 'index' %}"><i class="fa-solid fa-seedling"></i><span class="ms-2">Offers</span></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'index' %}"><i class="fa-solid fa-square-plus"></i><span class="ms-2">New Offer</span></a>
|
||||
<a class="nav-link" href="{% url 'create_offer' %}"><i class="fa-solid fa-square-plus"></i><span class="ms-2">New Offer</span></a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
{% block meta %}<meta name="description" content="{{ page_description }}">{% endblock %}
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
<form method="post" enctype="multipart/form-data" class="mb-5">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<button type="submit" class="btn btn-pfl">{{ button_label }}</button>
|
|
@ -1,58 +1,87 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
{% block title %}Offers{% endblock %}
|
||||
{% extends 'base.html' %}
|
||||
{% block title %}Offer: {{ offer.title }}{% endblock %}
|
||||
{% block meta %}
|
||||
<meta name="description"
|
||||
content="{{ offer.user.username }} offers {{ offer.title }}!">
|
||||
<meta name="author" content="{{ offer.user.username }}">
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
{% for message in app.flashes('success') %}
|
||||
<div class="alert alert-success" role="alert">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% for message in app.flashes('error') %}
|
||||
<div class="alert alert-danger" role="alert">{{ message }}</div>
|
||||
{% endfor %}
|
||||
<div class="mb-5">
|
||||
<a class="btn btn-pfl"
|
||||
data-toggle="collapse"
|
||||
href="#collapseExample"
|
||||
role="button"
|
||||
aria-expanded="false"
|
||||
aria-controls="collapseExample">
|
||||
<div class="btn btn-pfl">
|
||||
<i class="fas fa-filter mr-3"></i>Filter<i class="fas fa-chevron-down ml-3 dropdown-collapse"></i>
|
||||
{% if offer.user == request.user %}<div class="alert alert-info" role="alert">This is your offer!</div>{% endif %}
|
||||
<div class="show-offer-container d-flex flex-wrap">
|
||||
<div class="show-img-container">
|
||||
<img class="mb-3 img-fluid rounded"
|
||||
alt="Generic placeholder image"
|
||||
src="{{ offer.image.url }}">
|
||||
</div>
|
||||
<div class="show-offer-info w-50">
|
||||
<h1 class="mb-3">{{ offer.title }}</h1>
|
||||
<div class="mb-3 d-flex">
|
||||
<p class="pr-3">
|
||||
<i class="fas fa-user"></i>
|
||||
{% if offer.user == user %}
|
||||
Me
|
||||
{% else %}
|
||||
{{ offer.user.username }}
|
||||
{% endif %}
|
||||
</p>
|
||||
<p class="pr-3">
|
||||
<i class="fas fa-map-marker-alt"></i> {{ offer.zipcode }}
|
||||
</p>
|
||||
{% if distance > 0 %}
|
||||
<p class="pr-3">
|
||||
<i class="fas fa-map-signs mr-1"></i>ca. {{ distance }} km
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</a>
|
||||
<div class="collapse" id="collapseExample">{{ form(filter_form, {attr: {novalidate: 'novalidate' }}) }}</div>
|
||||
<h3>Description</h3>
|
||||
<p>{{ offer.description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<h1>Offers</h1>
|
||||
{% if offers|length > 0 %}
|
||||
<div class="card-deck d-flex justify-content-around justify-content-sm-around justify-content-md-between flex-wrap">
|
||||
{% for offer in offers %}
|
||||
<div class="mb-5">
|
||||
<div class="card offer h-100">
|
||||
<a href="{{ path('show_offer', {'urlId': offer.urlId }) }}">
|
||||
{% if offer.photoFilename %}
|
||||
<img class="card-img-top offer-img"
|
||||
src="{{ asset('uploads/photos/' ~ offer.photofilename) }}"/>
|
||||
{% else %}
|
||||
<img class="card-img-top offer-img" src="{{ asset('placeholder.jpg') }}" />
|
||||
{% endif %}
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ offer.title }}</h5>
|
||||
</div>
|
||||
</a>
|
||||
<div class="card-footer offer-footer">
|
||||
<a class="user-link"
|
||||
href="{{ path('user_public', { 'urlId': offer.byuser.urlId }) }}">
|
||||
<p class="username">
|
||||
<i class="fas fa-user mt-3"></i> {{ offer.byUser }}
|
||||
</p>
|
||||
</a>
|
||||
<p class="zip">
|
||||
<i class="fas fa-map-marker-alt mt-3"></i> {{ offer.zipCode }}
|
||||
</p>
|
||||
</div>
|
||||
{% if offer.user == user %}
|
||||
<a href="{% url 'offer_edit' offer.id %}" class="btn btn-info mb-3"><i class="fas fa-pen"></i></a>
|
||||
<button type="button"
|
||||
class="btn btn-danger mb-3"
|
||||
data-toggle="modal"
|
||||
data-target="#exampleModal">
|
||||
<i class="fas fa-trash-alt"></i>
|
||||
</button>
|
||||
<!-- Modal -->
|
||||
<div class="modal fade"
|
||||
id="exampleModal"
|
||||
tabindex="-1"
|
||||
role="dialog"
|
||||
aria-labelledby="exampleModalLabel"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Warning</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">Are you sure you want to delete this offer?</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<a type="button"
|
||||
class="btn btn-danger"
|
||||
href="{% url 'offer_delete' offer.id %}">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="alert alert-warning" role="alert">There are no active offers with the current filter.</div>
|
||||
<h3>Wishes</h3>
|
||||
<p>{{ offer.user.username }} would like some of the following in return:</p>
|
||||
<div class="mb-3">
|
||||
{% if wishes %}
|
||||
<div class="alert alert-warning" role="alert">There are currently no wishes!</div>
|
||||
{% else %}
|
||||
<ul class="list-group">
|
||||
{% for wish in wishes %}<li class="list-group-item">{{ wish.title }}</li>{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
<a class="btn btn-pfl mb-3" href="{% url 'trade' offer.id %}">Offer trade</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
52
pflaenzli/templates/offer/search.html
Normal file
52
pflaenzli/templates/offer/search.html
Normal file
|
@ -0,0 +1,52 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block title %}Offers{% endblock %}
|
||||
{% block content %}
|
||||
<div class="mb-5">
|
||||
<a class="btn btn-pfl"
|
||||
data-toggle="collapse"
|
||||
href="#collapseExample"
|
||||
role="button"
|
||||
aria-expanded="false"
|
||||
aria-controls="collapseExample">
|
||||
<div class="btn btn-pfl">
|
||||
<i class="fas fa-filter mr-3"></i>Filter<i class="fas fa-chevron-down ml-3 dropdown-collapse"></i>
|
||||
</div>
|
||||
</a>
|
||||
<div class="collapse" id="collapseExample">{{ form(filter_form, {attr: {novalidate: 'novalidate' }}) }}</div>
|
||||
</div>
|
||||
<h1>Offers</h1>
|
||||
{% if offers|length > 0 %}
|
||||
<div class="card-deck d-flex justify-content-around justify-content-sm-around justify-content-md-between flex-wrap">
|
||||
{% for offer in offers %}
|
||||
<div class="mb-5">
|
||||
<div class="card offer h-100">
|
||||
<a href="{{ path('show_offer', {'urlId': offer.urlId }) }}">
|
||||
{% if offer.photoFilename %}
|
||||
<img class="card-img-top offer-img"
|
||||
src="{{ asset('uploads/photos/' ~ offer.photofilename) }}"/>
|
||||
{% else %}
|
||||
<img class="card-img-top offer-img" src="{{ asset('placeholder.jpg') }}" />
|
||||
{% endif %}
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ offer.title }}</h5>
|
||||
</div>
|
||||
</a>
|
||||
<div class="card-footer offer-footer">
|
||||
<a class="user-link"
|
||||
href="{{ path('user_public', { 'urlId': offer.byuser.urlId }) }}">
|
||||
<p class="username">
|
||||
<i class="fas fa-user mt-3"></i> {{ offer.byUser }}
|
||||
</p>
|
||||
</a>
|
||||
<p class="zip">
|
||||
<i class="fas fa-map-marker-alt mt-3"></i> {{ offer.zipCode }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="alert alert-warning" role="alert">There are no active offers with the current filter.</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
18
pflaenzli/urls.py
Normal file
18
pflaenzli/urls.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.urls import path, include
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
path("offer/create/", views.create_offer, name="create_offer"),
|
||||
path("offer/<int:offer_id>/", views.offer_detail, name="offer_detail"),
|
||||
path("offer/<int:offer_id>/delete", views.offer_delete, name="offer_delete"),
|
||||
path("offer/<int:offer_id>/edit", views.offer_edit, name="offer_edit"),
|
||||
path("offer/<int:offer_id>/trade", views.offer_trade, name="offer_trade"),
|
||||
path('accounts/login/', auth_views.LoginView.as_view(template_name='registration/login.html')),
|
||||
path('accounts/profile/', auth_views.LoginView.as_view(template_name='user/detail.html')),
|
||||
path('accounts/', include('django.contrib.auth.urls')),
|
||||
]
|
|
@ -1,3 +1,62 @@
|
|||
from django.shortcuts import render
|
||||
import os
|
||||
import pathlib
|
||||
import uuid
|
||||
from django.core.files.storage import default_storage
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.utils import timezone
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
# Create your views here.
|
||||
from .forms import CreateOfferForm
|
||||
from .models import Offer, Wish
|
||||
|
||||
|
||||
def index(request):
|
||||
return render(request, "app/index.html")
|
||||
|
||||
|
||||
@login_required
|
||||
def create_offer(request):
|
||||
if request.method == "POST":
|
||||
print(request.POST)
|
||||
form = CreateOfferForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
offer = form.save(commit=False)
|
||||
offer.image.name = generate_unique_filename(request.FILES['image'].name)
|
||||
offer.user = request.user
|
||||
offer.save()
|
||||
messages.success(request, "Offer uploaded successfully!")
|
||||
return redirect("offer_detail", offer.id)
|
||||
else:
|
||||
form = CreateOfferForm()
|
||||
|
||||
return render(request, "basic_form.html", {"form": form, "button_label": "Create"})
|
||||
|
||||
|
||||
@login_required
|
||||
def offer_detail(request, offer_id):
|
||||
offer = get_object_or_404(Offer, id=offer_id)
|
||||
|
||||
return render(request, "offer/detail.html", {"offer": offer, "wishes": ["Monstera", "Tradescantia"]})
|
||||
|
||||
|
||||
def generate_unique_filename(filename):
|
||||
file_type = pathlib.Path(filename).suffix
|
||||
new_filename = default_storage.get_available_name(uuid.uuid4())
|
||||
|
||||
return f'{new_filename}{file_type}'
|
||||
|
||||
|
||||
@login_required
|
||||
def offer_delete(request, offer_id):
|
||||
return 0
|
||||
|
||||
|
||||
@login_required
|
||||
def offer_edit(request, offer_id):
|
||||
return 0
|
||||
|
||||
|
||||
@login_required
|
||||
def offer_trade(request, offer_id):
|
||||
return 0
|
||||
|
|
|
@ -10,6 +10,7 @@ For the full list of settings and their values, see
|
|||
https://docs.djangoproject.com/en/4.1/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
|
@ -31,12 +32,16 @@ ALLOWED_HOSTS = []
|
|||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"pflaenzli",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"fontawesomefree",
|
||||
"crispy_forms",
|
||||
"crispy_bootstrap5",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -47,6 +52,7 @@ MIDDLEWARE = [
|
|||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = "pflaenzli_django.urls"
|
||||
|
@ -105,7 +111,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
TIME_ZONE = "UTC"
|
||||
TIME_ZONE = "Europe/Zurich"
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
|
@ -116,8 +122,13 @@ USE_TZ = True
|
|||
# https://docs.djangoproject.com/en/4.1/howto/static-files/
|
||||
|
||||
STATIC_URL = "static/"
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
||||
MEDIA_URL = "media/"
|
||||
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
CRISPY_TEMPLATE_PACK = 'bootstrap5'
|
||||
|
|
|
@ -13,9 +13,16 @@ Including another URLconf
|
|||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.urls import include, path
|
||||
from django.conf.urls.static import static
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('', include('pflaenzli.urls')),
|
||||
path("admin/", admin.site.urls),
|
||||
|
||||
]
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
Loading…
Reference in a new issue