Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Fix branch integrity error #38

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dashboard/static/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ body {
}

.message.success {
background-color: #4CAF50;
background-color: #cda45e;
/* Green */
}

Expand Down Expand Up @@ -258,3 +258,8 @@ body {
background-color: #cda45e;
color: white;
}

.alert-success {
background-color: #cda45e;
color: white;
}
40 changes: 24 additions & 16 deletions dashboard/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db import IntegrityError
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib import messages
from django.views import View
Expand Down Expand Up @@ -114,25 +115,32 @@ def post(self, request, branch_id):
request.POST, queryset=opening_hours)

if opening_hour_formset.is_valid():
# Proceed with saving the formset if it's valid
opening_hour_instances = opening_hour_formset.save(commit=False)
for opening_hour_instance in opening_hour_instances:
opening_hour_instance.branch = branch # Set the branch before saving
opening_hour_instance.save()

for obj in opening_hour_formset.deleted_objects:
obj.delete()
messages.success(request, 'Opening hours updated successfully')
return redirect('dashboard:branches.edit', pk=branch_id)
try:
# Save the formset if it's valid
opening_hour_instances = opening_hour_formset.save(
commit=False)
for opening_hour_instance in opening_hour_instances:
opening_hour_instance.branch = branch # Set the branch before saving
opening_hour_instance.save()

for obj in opening_hour_formset.deleted_objects:
obj.delete()

messages.success(request, 'Opening hours updated successfully')
return redirect('dashboard:branches.edit', pk=branch_id)
except IntegrityError as e:
# Handle the integrity error for duplicate days
messages.error(
request, 'A duplicate entry exists for the same day.')
else:
# If formset is invalid, display the formset with errors
print(opening_hour_formset.errors)
messages.error(
request, 'Please correct the days or time errors below.')
return render(request, 'branches/update-opening-hours.html', {
'branch': branch,
'opening_hour_formset': opening_hour_formset,
})
messages.error(request, 'Please correct the errors below.')

return render(request, 'branch/update-opening-hours.html', {
'branch': branch,
'opening_hour_formset': opening_hour_formset,
})


class ViewDeleteBranchView(View):
Expand Down
Binary file removed static/assets/img/event-birthday.jpg
Binary file not shown.
Binary file removed static/assets/img/event-custom.jpg
Binary file not shown.
Binary file removed static/assets/img/event-private.jpg
Binary file not shown.
Binary file removed static/assets/img/events-bg.jpg
Binary file not shown.
Binary file removed static/assets/img/gallery/gallery-1.jpg
Binary file not shown.
Binary file removed static/assets/img/gallery/gallery-2.jpg
Binary file not shown.
Binary file removed static/assets/img/gallery/gallery-3.jpg
Binary file not shown.
Binary file removed static/assets/img/gallery/gallery-4.jpg
Binary file not shown.
Binary file removed static/assets/img/gallery/gallery-5.jpg
Binary file not shown.
Binary file removed static/assets/img/gallery/gallery-6.jpg
Binary file not shown.
Binary file removed static/assets/img/gallery/gallery-7.jpg
Binary file not shown.
Binary file removed static/assets/img/gallery/gallery-8.jpg
Binary file not shown.
Binary file removed static/assets/img/menu/bread-barrel.jpg
Binary file not shown.
Binary file removed static/assets/img/menu/caesar.jpg
Binary file not shown.
Binary file removed static/assets/img/menu/cake.jpg
Binary file not shown.
Binary file removed static/assets/img/menu/greek-salad.jpg
Binary file not shown.
Binary file removed static/assets/img/menu/lobster-bisque.jpg
Binary file not shown.
Binary file removed static/assets/img/menu/lobster-roll.jpg
Binary file not shown.
Binary file removed static/assets/img/menu/mozzarella.jpg
Binary file not shown.
Binary file removed static/assets/img/menu/spinach-salad.jpg
Binary file not shown.
Binary file removed static/assets/img/menu/tuscan-grilled.jpg
Binary file not shown.
Binary file removed static/assets/img/specials-1.png
Binary file not shown.
Binary file removed static/assets/img/specials-2.png
Binary file not shown.
Binary file removed static/assets/img/specials-3.png
Binary file not shown.
Binary file removed static/assets/img/specials-4.png
Binary file not shown.
Binary file removed static/assets/img/specials-5.png
Diff not rendered.
Binary file removed static/assets/img/testimonials/testimonials-1.jpg
Diff not rendered.
Binary file removed static/assets/img/testimonials/testimonials-2.jpg
Diff not rendered.
Binary file removed static/assets/img/testimonials/testimonials-3.jpg
Diff not rendered.
Binary file removed static/assets/img/testimonials/testimonials-4.jpg
Diff not rendered.
Binary file removed static/assets/img/testimonials/testimonials-5.jpg
Diff not rendered.
5 changes: 5 additions & 0 deletions users/static/users.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,8 @@ h2 {
margin-top: 15px;
text-align: center;
}

.alert-success {
background-color: #cda45e;
color: white;
}
29 changes: 29 additions & 0 deletions users/templates/profile-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@

{% load static %}

{% block css_files %}

<link href="{% static 'users.css' %}" rel="stylesheet" />

{% endblock %}

{% block content %}

<section id="menu" class="menu section-bg mt-5">
<div class="container mt-5">

{% if messages %}
<div class="alert alert-success" id="success-message">
{% for message in messages %}
{{ message }}
{% endfor %}
</div>
{% endif %}

<h2 class="mb-4">My Profile</h2>
<div class="row">
<div class="col-md-3">
Expand Down Expand Up @@ -45,3 +60,17 @@ <h2 class="mb-4">My Profile</h2>
</section>

{% endblock %}

{% block script %}

<!--Added Hanifah - Function to remove success message after 5 seconds -->
<script>
setTimeout(function () {
var successMessage = document.getElementById('success-message');
if (successMessage) {
successMessage.parentNode.removeChild(successMessage);
}
}, 5000); // 5000 milliseconds = 5 seconds
</script>
{% endblock %}

1 change: 1 addition & 0 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def post(self, request, *args, **kwargs):
profile_form.save()

# Redirect to a success page
messages.success(request, 'Profile has been updated succesfully')
return redirect(to='users:profile.show')
return render(request, self.template_name, {'form': form, 'profile_form': profile_form})

Expand Down
Loading