Skip to content

Commit

Permalink
Merge pull request #96 from spline2hg/profilepage
Browse files Browse the repository at this point in the history
Profilepage
  • Loading branch information
nfoert authored Oct 25, 2024
2 parents 518d2d1 + d496ab4 commit 236404b
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cardie/authentication/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from .models import Profile, User

from django.core.exceptions import ValidationError


class UserUpdateForm(forms.ModelForm):
Expand All @@ -17,3 +17,14 @@ class ProfileUpdateForm(forms.ModelForm):
class Meta:
model = Profile
fields = ['profile_image', 'bio']

def clean_profile_image(self):
image = self.cleaned_data.get('profile_image', False)
if image:
if image.size > 2 * 1024 * 1024:
raise ValidationError(
"Image size is too large! Please upload an image smaller than 2MB."
)
return image
else:
raise ValidationError("Couldn't read uploaded image")
30 changes: 30 additions & 0 deletions cardie/authentication/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,36 @@ <h2 class="ui_text_subheader_left">Account Actions</h2>
@change="handleFileChange"
accept="image/*"
style="display: none;">

<!-- New Error Display Section -->
<div class="error-container">
<!-- Form-wide errors -->
{% if p_form.non_field_errors %}
<div class="error-message" x-init="setTimeout(() => $el.remove(), 5000)">
{% for error in p_form.non_field_errors %}
<div class="error-item">
<i class="ph-bold ph-x-circle"></i>
<span>{{ error }}</span>
</div>
{% endfor %}
</div>
{% endif %}

<!-- Field-specific errors -->
{% for field in p_form %}
{% if field.errors %}
{% for error in field.errors %}
<div class="error-message" x-init="setTimeout(() => $el.remove(), 5000)">
<div class="error-item">
<i class="ph-bold ph-x-circle"></i>
<span>{{ error }}</span>
</div>
</div>
{% endfor %}
{% endif %}
{% endfor %}

</div>
</div>
</div>
</form>
Expand Down
58 changes: 58 additions & 0 deletions cardie/static/main/profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,62 @@ body {
border-bottom: 1px solid var(--card-border);
padding: 10px 0;
}
}

.error-container {
margin-top: 1rem;
width: 100%;
display: flex;
flex-direction: column;
gap: 0.5rem;
}

.error-message {
background-color: #EF4444;
border: 1px solid #DC2626;
border-radius: 0.375rem;
padding: 0.75rem;
margin-top: 0.5rem;
animation: slideIn 0.3s ease-out;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.error-item {
display: flex;
align-items: center;
gap: 0.75rem;
color: white;
font-size: 1rem;
font-weight: 500;
}

.error-item i {
font-size: 1.5rem;
color: white;
}

@keyframes slideIn {
from {
transform: translateY(-10px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}

@keyframes slideOut {
from {
transform: translateY(0);
opacity: 1;
}
to {
transform: translateY(-10px);
opacity: 0;
}
}

.error-message.hiding {
animation: slideOut 0.3s ease-in forwards;
}

0 comments on commit 236404b

Please sign in to comment.