Skip to content

Commit

Permalink
Major CSS määrittely, media filujen parempi käsittely ja oikea tiedos…
Browse files Browse the repository at this point in the history
…tosijainti
  • Loading branch information
Teemu-Kostamo committed Apr 23, 2024
1 parent de7e2d2 commit 7779eef
Show file tree
Hide file tree
Showing 31 changed files with 251 additions and 99 deletions.
File renamed without changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2024-04-22 12:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lainatehdas', '0020_item_item_avail'),
]

operations = [
migrations.AlterField(
model_name='reservation',
name='date_reserved',
field=models.DateField(),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.3 on 2024-04-23 14:46

import lainatehdas.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lainatehdas', '0021_alter_reservation_date_reserved'),
]

operations = [
migrations.AlterField(
model_name='item',
name='item_img',
field=models.ImageField(default='media/placeholder.jpg', upload_to='media/', validators=[lainatehdas.models.validate_image_dimensions]),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.3 on 2024-04-23 14:51

import lainatehdas.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lainatehdas', '0022_alter_item_item_img'),
]

operations = [
migrations.AlterField(
model_name='item',
name='item_img',
field=models.ImageField(default='images/placeholder.jpg', upload_to='images/', validators=[lainatehdas.models.validate_image_dimensions]),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.3 on 2024-04-23 15:12

import lainatehdas.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lainatehdas', '0023_alter_item_item_img'),
]

operations = [
migrations.AlterField(
model_name='item',
name='item_img',
field=models.ImageField(default='images/placeholder.jpg', upload_to='MEDIA_URL', validators=[lainatehdas.models.validate_image_dimensions]),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.3 on 2024-04-23 15:34

import lainatehdas.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lainatehdas', '0024_alter_item_item_img'),
]

operations = [
migrations.AlterField(
model_name='item',
name='item_img',
field=models.ImageField(upload_to='', validators=[lainatehdas.models.validate_image_dimensions]),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.3 on 2024-04-23 15:42

import lainatehdas.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lainatehdas', '0025_alter_item_item_img'),
]

operations = [
migrations.AlterField(
model_name='item',
name='item_img',
field=models.ImageField(upload_to='images/', validators=[lainatehdas.models.validate_image_dimensions]),
),
]
10 changes: 8 additions & 2 deletions lainatehtailijat/lainatehdas/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from django.db import models
from django.contrib.auth.models import User
from datetime import timedelta, date
from django.core.exceptions import ValidationError

# Create your models here.

def validate_image_dimensions(image):
if image.width < 326 or image.height < 326:
raise ValidationError("Image dimensions must be at least 326x326 pixels.")

class Item(models.Model):
item_choices = {
"Leik" : "Ruohonleikkuri",
Expand All @@ -24,7 +29,7 @@ class Item(models.Model):
item_desc = models.CharField(max_length= 500, verbose_name="Description")
item_type = models.CharField(max_length=4, choices=item_choices, verbose_name="Type")
item_avail = models.CharField(max_length=2, choices=item_avail_choices, default="Va")
item_img = models.ImageField(upload_to='media/', default='media/placeholder.jpg')
item_img = models.ImageField(upload_to= 'images/', validators=[validate_image_dimensions])
def __str__(self) -> str:
return self.item_name

Expand All @@ -34,6 +39,7 @@ def __str__(self):

user = models.ForeignKey(User, on_delete=models.CASCADE)
item = models.ForeignKey(Item, on_delete=models.CASCADE)
date_reserved = models.DateField(auto_now_add=True)
#date_reserved = models.DateField(auto_now_add=True)
date_reserved = models.DateField()
date_returned = models.DateField(null=True, blank=True)

Empty file.
Binary file removed lainatehtailijat/lainatehdas/static/media/harava.jpg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions lainatehtailijat/lainatehdas/templates/lainatehdas/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
<nav class="py-6 px-6 flex justify-between items-center border-b border-gray-300 bg-gray-400">
{% if request.user.is_authenticated %}
{% if request.path == '/main/' %}
<a href="{% url 'lainatehdas:reservations'%}" class="px-6 py-3 text-lg font-semibold bg-green-500 text-white rounded-xl hover:bg-green-700">Omat varaukset</a>
<a href="{% url 'lainatehdas:reservations'%}" class="px-4 py-2 md:px-6 md:py-3 text-base md:text-lg font-semibold bg-green-500 text-white rounded-xl hover:bg-green-700">Omat varaukset</a>
{% else %}
<a href="{% url 'lainatehdas:main'%}" class="px-6 py-3 text-lg font-semibold bg-green-500 text-white rounded-xl hover:bg-green-700">Välineet</a>
<a href="{% url 'lainatehdas:main'%}" class="px-4 py-2 md:px-6 md:py-3 text-base md:text-lg font-semibold bg-green-500 text-white rounded-xl hover:bg-green-700">Välineet</a>

{% endif %}
<form id="logout-form" action="{% url 'lainatehdas:logout' %}" method="post">
{% csrf_token %}
<button type="submit" class="px-6 py-3 text-lg font-semibold bg-red-500 text-white rounded-xl hover:bg-blue-700">Kirjaudu ulos</button>
<button type="submit" class="px-4 py-2 md:px-6 md:py-3 text-base md:text-lg font-semibold bg-red-500 text-white rounded-xl hover:bg-blue-700">Kirjaudu ulos</button>
</form>
{% else %}
<a href="/" class="text-xl font-semibold text-white">Tervetuloa!</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h2 class="text-3xl font-bold text-gray-900 mb-4">{{ item.item_name }}</h2>
</form>
{% elif item.item_avail == "Vr" %}
{% for reservation in reservation_list %}
{% if reservation.date_returned == null and reservation.user_id == request.user.id %}
{% if reservation.item_id == item.id and reservation.date_returned == null and reservation.user_id == request.user.id %}
<form method="POST" action="{% url 'lainatehdas:update_return_date' reservation.id reservation.item.id %}">
{% csrf_token %}
<button type="submit" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-md">Palauta</button>
Expand Down
8 changes: 4 additions & 4 deletions lainatehtailijat/lainatehdas/templates/lainatehdas/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ <h1 class="text-3xl font-bold mb-8">Välineet</h1>
<li class="bg-gray-200 rounded-lg hover:shadow-lg transition-transform transform hover:-translate-y-2">
<a href="{% url 'lainatehdas:detail' item.id %}" class="block p-4">
<h2 class="text-xl font-bold text-gray-900 mb-2">{{ item.item_name|capfirst }}</h2>
<div class="aspect-w-4 aspect-h-5 mb-4">
<img src="{% static item.item_img %}" class="object-cover rounded-lg" alt="{{ item.item_name }}">
</div>
<div class="aspect-w-4 aspect-h-5 mb-4 bg-gray-200 rounded-lg flex items-center justify-center min-w-0 min-h-0">
<img src="{{MEDIA_URL}}{{item.item_img}}" class="object-cover rounded-lg min-w-0 min-h-0" alt="{{ item.item_name }}">
</div>
<div>
{% if item.item_avail == "Va" %}
<form method="POST" action="{% url 'lainatehdas:create_new_reservation' item.id %}">
Expand All @@ -27,7 +27,7 @@ <h2 class="text-xl font-bold text-gray-900 mb-2">{{ item.item_name|capfirst }}</
</form>
{% elif item.item_avail == "Vr" %}
{% for reservation in reservation_list %}
{% if reservation.date_returned == null and reservation.user_id == request.user.id %}
{% if reservation.item_id == item.id and reservation.date_returned == null and reservation.user_id == request.user.id %}
<form method="POST" action="{% url 'lainatehdas:update_return_date' reservation.id reservation.item.id %}">
{% csrf_token %}
<button type="submit" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-md">Palauta</button>
Expand Down
Loading

0 comments on commit 7779eef

Please sign in to comment.