Skip to content

Commit

Permalink
Merge pull request #132 from seanmorley15/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
seanmorley15 authored Jul 18, 2024
2 parents 2434e76 + 5e70130 commit 8e5074e
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 21 deletions.
19 changes: 19 additions & 0 deletions backend/server/adventures/migrations/0009_alter_adventure_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.6 on 2024-07-18 15:06

import django_resized.forms
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('adventures', '0008_collection_description'),
]

operations = [
migrations.AlterField(
model_name='adventure',
name='image',
field=django_resized.forms.ResizedImageField(blank=True, crop=None, force_format='WEBP', keep_meta=True, null=True, quality=75, scale=None, size=[1920, 1080], upload_to='images/'),
),
]
4 changes: 3 additions & 1 deletion backend/server/adventures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.contrib.auth import get_user_model
from django.contrib.postgres.fields import ArrayField
from django.forms import ValidationError
from django_resized import ResizedImageField

ADVENTURE_TYPES = [
('visited', 'Visited'),
Expand All @@ -28,7 +29,7 @@ class Adventure(models.Model):
description = models.TextField(blank=True, null=True)
rating = models.FloatField(blank=True, null=True)
link = models.URLField(blank=True, null=True)
image = models.ImageField(null=True, blank=True, upload_to='images/')
image = ResizedImageField(force_format="WEBP", quality=75, null=True, blank=True, upload_to='images/')
date = models.DateField(blank=True, null=True)
is_public = models.BooleanField(default=False)
longitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
Expand All @@ -41,6 +42,7 @@ def clean(self):
raise ValidationError('Adventures associated with a public collection must be public. Collection: ' + self.trip.name + ' Adventure: ' + self.name)
if self.user_id != self.collection.user_id:
raise ValidationError('Adventures must be associated with collections owned by the same user. Collection owner: ' + self.collection.user_id.username + ' Adventure owner: ' + self.user_id.username)

def __str__(self):
return self.name

Expand Down
5 changes: 5 additions & 0 deletions backend/server/adventures/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def to_representation(self, instance):
representation['image'] = f"{public_url}/media/{instance.image.name}"
return representation

def validate_activity_types(self, value):
if value:
return [activity.lower() for activity in value]
return value

class CollectionSerializer(serializers.ModelSerializer):
adventures = AdventureSerializer(many=True, read_only=True, source='adventure_set')

Expand Down
3 changes: 2 additions & 1 deletion backend/server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ coreapi==2.3.3
python-dotenv
psycopg2-binary
Pillow
whitenoise
whitenoise
django-resized
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.6 on 2024-07-18 15:06

import django_resized.forms
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('users', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='customuser',
name='profile_pic',
field=django_resized.forms.ResizedImageField(blank=True, crop=None, force_format='WEBP', keep_meta=True, null=True, quality=75, scale=None, size=[1920, 1080], upload_to='profile-pics/'),
),
]
3 changes: 2 additions & 1 deletion backend/server/users/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
from django_resized import ResizedImageField

class CustomUser(AbstractUser):
profile_pic = models.ImageField(null=True, blank=True, upload_to='profile-pics/')
profile_pic = ResizedImageField(force_format="WEBP", quality=75, null=True, blank=True, upload_to='profile-pics/')

def __str__(self):
return self.username
2 changes: 1 addition & 1 deletion frontend/src/lib/components/ActivityComplete.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
function addActivity() {
if (inputVal && activities) {
const trimmedInput = inputVal.trim();
const trimmedInput = inputVal.trim().toLocaleLowerCase();
if (trimmedInput && !activities.includes(trimmedInput)) {
activities = [...activities, trimmedInput];
inputVal = '';
Expand Down
54 changes: 37 additions & 17 deletions frontend/src/lib/components/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@
<li>
<button on:click={() => goto('/map')}>Map</button>
</li>
<form class="flex gap-2">
<label class="input input-bordered flex items-center gap-2">
<input type="text" bind:value={query} class="grow" placeholder="Search" />

<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="h-4 w-4 opacity-70"
>
<path
fill-rule="evenodd"
d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z"
clip-rule="evenodd"
/>
</svg>
</label>
<button on:click={searchGo} type="submit" class="btn btn-neutral">Search</button>
</form>
{/if}

{#if !data.user}
Expand Down Expand Up @@ -115,24 +134,25 @@
<li>
<button class="btn btn-neutral" on:click={() => goto('/map')}>Map</button>
</li>
<label class="input input-bordered flex items-center gap-2">
<form>
<form class="flex gap-2">
<label class="input input-bordered flex items-center gap-2">
<input type="text" bind:value={query} class="grow" placeholder="Search" />
</form>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="h-4 w-4 opacity-70"
>
<path
fill-rule="evenodd"
d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z"
clip-rule="evenodd"
/>
</svg>
</label>
<button on:click={searchGo} type="submit" class="btn btn-neutral">Search</button>

<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="h-4 w-4 opacity-70"
>
<path
fill-rule="evenodd"
d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z"
clip-rule="evenodd"
/>
</svg>
</label>
<button on:click={searchGo} type="submit" class="btn btn-neutral">Search</button>
</form>
{/if}

{#if !data.user}
Expand Down

0 comments on commit 8e5074e

Please sign in to comment.