Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat. Added a display message in sign in page #107

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
Binary file modified newsaggregator/core/__pycache__/admin.cpython-312.pyc
Binary file not shown.
Binary file modified newsaggregator/core/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file modified newsaggregator/core/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified newsaggregator/core/__pycache__/views.cpython-312.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 5.0.6 on 2024-06-02 08:25

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0002_contact'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AddField(
model_name='headline',
name='average_rating',
field=models.FloatField(blank=True, default=0, null=True),
),
migrations.AddField(
model_name='headline',
name='rating_count',
field=models.IntegerField(default=0),
),
migrations.AlterField(
model_name='contact',
name='phone',
field=models.IntegerField(blank=True),
),
migrations.CreateModel(
name='Rating',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('rating', models.IntegerField(blank=True, choices=[(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5')], null=True)),
('headline', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.headline')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion newsaggregator/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Contact(models.Model):
name = models.CharField(max_length=255)
email = models.EmailField(validators=[EmailValidator()])
phone = models.IntegerField(max_length=10, blank=True)
phone = models.IntegerField(blank=True)
message= models.TextField(max_length=20, blank=True)


Expand Down
18 changes: 9 additions & 9 deletions newsaggregator/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,18 @@ def privacy(request):
return render(request, "core/privacy.html", context)


# @login_required(login_url='userauths:sign-in')
# def view_bookmarks(request):
# # Get the list of bookmarked headlines for the current user
# bookmarks = Bookmark.objects.filter(user=request.user).select_related('headline')
@login_required(login_url='userauths:sign-in')
def view_bookmarks(request):
# Get the list of bookmarked headlines for the current user
bookmarks = Bookmark.objects.filter(user=request.user).select_related('headline')

# if bookmarks.exists():
# context = {'bookmarks': bookmarks}
# else:
# context = {'message': 'You have no bookmarks yet.'}
if bookmarks.exists():
context = {'bookmarks': bookmarks}
else:
context = {'message': 'You have no bookmarks yet.'}


# return render(request, 'core/bookmarks.html', context)
return render(request, 'core/bookmarks.html', context)
def view_bookmarks(request):
if request.user.is_authenticated:
# Get the list of bookmarked headlines for the current user
Expand Down
Binary file modified newsaggregator/db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file modified newsaggregator/newsaggregator/__pycache__/urls.cpython-312.pyc
Binary file not shown.
7 changes: 4 additions & 3 deletions newsaggregator/templates/components/swiperjs.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

{% load static %}
<!-- Link Swiper's CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" />
Expand Down Expand Up @@ -38,7 +39,7 @@
<!-- Swiper -->
<div class="swiper mySwiper">
<div class="swiper-wrapper">
{% for record in object_list %}
<!--{% for record in object_list %}-->
<div class="col-12 col-md-6 col-lg-4 mb-4 newscard swiper-slide">
<div class="row">
<div class="col-md-12 swiper-image">
Expand All @@ -55,7 +56,7 @@

</div>
</div>
{% endfor %}
<!--{% endfor %}-->
</div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
Expand Down Expand Up @@ -83,4 +84,4 @@
prevEl: ".swiper-button-prev",
},
});
</script>
</script>
17 changes: 16 additions & 1 deletion newsaggregator/templates/userauths/sign-in.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,22 @@
<img src="../../static/assets/images/news.png" width="80px" alt="News logo" class="logo-light">
<img src="../../static/assets/images/news.png" width="80px" alt="News logo" class="logo-dark">
</div>


{% for message in messages %}
{% if message.level == "success" %}
<div class="alert alert-success">
{{ message }}
</div>

{% else %}
<div class="alert alert-danger" role="alert">
{{ message }}
</div>
{% endif %}
{% endfor %}



<form method="POST">
{% csrf_token %}
<div class="signin-form" id="signin-form">
Expand Down
Binary file modified newsaggregator/userauths/__pycache__/views.cpython-312.pyc
Binary file not shown.
12 changes: 8 additions & 4 deletions newsaggregator/userauths/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def register_view(request):
return render(request, 'userauths/sign-up.html', context)

def login_view(request):

if request.user.is_authenticated:
messages.warning(request,f"Hey, You are already Logged in")
return redirect('core:index')
Expand All @@ -41,20 +42,23 @@ def login_view(request):
user=User.object.get(email=email)
except:
messages.warning(request,f"User with {email} does not exist")


user=authenticate(request,email=email,password=password)

if user is not None:
login(request,user)
messages.success(request,"Your are logged in.")
login(request,user)
return redirect("core:index")

else:
messages.warning(request,"User Does not exist, create an accounnt")
messages.warning(request,"User Does not exist, create an account")

return render(request,"userauths/sign-in.html")


def logout_view(request):

logout(request)
messages.success(request, "You Logged-Out, successfully")
return redirect("userauths:sign-in")

return redirect("userauths:sign-in",)
Loading