Skip to content

Commit

Permalink
Adding the read more and edit button
Browse files Browse the repository at this point in the history
  • Loading branch information
orIsrael committed Apr 21, 2022
1 parent 631de78 commit e4e472c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 87 deletions.
2 changes: 1 addition & 1 deletion tips/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
TIPS_PAGE_ROUTE = 'tips/board.html'
TIPS_PAGE_ROUTE = 'tips/index.html'
ADD_TIP_PAGE_ROUTE = 'tips/add_tip.html'
EDIT_TIP_PAGE_ROUTE = 'tips/edit_tip.html'
3 changes: 2 additions & 1 deletion tips/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ def create_tip(category, author, date, text):
return tip

def __str__(self):
return self.text[:50]
preview_tip = self.text[:10] + '...'
return preview_tip
68 changes: 0 additions & 68 deletions tips/templates/tips/board.html

This file was deleted.

18 changes: 4 additions & 14 deletions tips/templates/tips/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>
<body>
<div class="container">
<div class="grid">
<div class="col-md-12 col-lg-12">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Tips</a>
Expand Down Expand Up @@ -69,23 +69,13 @@
<div class="col-xs-12 col-sm-7 col-md-7 col-lg-8">
<div class="caption">
<h3 class="md-heading"><a href="#">{{ tip.author }}</a></h3>
<p> {{ tip.text }}</p>
<a class="btn btn-default" href="#" role="button">Read More</a> </div>
<p> {{ tip }}</p>
<a class="btn btn-default" href="read_more/{{ tip.id }}" role="button">Read More</a> </div>
<a class ="edit" type="button" href="edit_tip/{{ tip.id }}" role="button">Edit</a><br/>
</div>
</div>
</article>
{% endfor %}
<div class="pagination-wrap">
<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
</nav>
</div>
<div class="clearfix"></div>
</div>
</div>
Expand Down
39 changes: 39 additions & 0 deletions tips/templates/tips/read_more.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends "base.html" %} {%load static%} {%block content%}
<div class="container">
<div class="grid">
<article class="post vt-post">
<div class="row">
<div class="col-xs-12 col-sm-5 col-md-5 col-lg-4">
<div class="post-type post-img">
<a href="#"><img src="https://bootdey.com/img/Content/avatar/avatar1.png" class="img-responsive" alt="image post"></a>
</div>
<div class="author-info author-info-2">
<ul class="list-inline">
<li>
<div class="info">
<p>Posted on:</p>
<strong>{{ tip.date}}</strong></div>
</li>
<li>
<div class="info">
<p>Category:</p>
<strong>{{ tip.category }}</strong></div>
</li>
</ul>
</div>
</div>
<div class="col-xs-12 col-sm-7 col-md-7 col-lg-8">
<div class="caption">
<h3 class="md-heading"><a href="#">{{ tip.author }}</a></h3>
<p> {{ tip.text }}</p>
<a class ="edit" type="button" href="edit_tip/{{ tip.id }}" role="button">Edit</a><br/>
</div>
</div>
</div>
</article>
<div class="clearfix"></div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
{% endblock %}
5 changes: 3 additions & 2 deletions tips/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
path('', views.board, name='board'),
path('add_tip/', views.add_tip, name='add_tip'),
path('edit_tip/<int:tip_id>/', views.edit_tip, name='edit_tip'),
path('delete_tip/<int:tip_id>/', views.delete_tip, name='delete_tip'),
path('category/<str:cats>/', views.categories_filter, name='category')
path('category/<str:cats>/', views.categories_filter, name='category'),
path('read_more/<int:tip_id>/', views.read_more_view, name='read_more'),
path('delete_tip/<int:tip_id>/', views.delete_tip, name='delete_tip')
]
6 changes: 5 additions & 1 deletion tips/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ def add_tip(request):
else:
form = TipForm()
return render(request, ADD_TIP_PAGE_ROUTE, {'form': form})
return render(request, 'tips/add_tip.html', {'form': form})


def categories_filter(request, cats):
category_filtered_tips = Tip.objects.filter(category=cats)
return render(request, 'tips/categories.html', {'cats': cats, 'category_filtered_tips': category_filtered_tips})


def read_more_view(request, tip_id):
tip = get_object_or_404(Tip, pk=tip_id)
return render(request, 'tips/read_more.html', {'tip': tip})


def edit_tip(request, tip_id):
tip = get_object_or_404(Tip, pk=tip_id)
form = TipForm(request.POST or None, instance=tip)
Expand Down

0 comments on commit e4e472c

Please sign in to comment.