Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
agusmakmun committed Nov 18, 2020
1 parent d763ade commit 1c0727e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion apps/blog/forms/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PostForm(forms.ModelForm):

def save(self, commit=True):
instance = super().save(commit=False)
instance.slug = generate_unique_slug(self.Meta.model, instance.title)
instance.slug = generate_unique_slug(self.Meta.model, instance.title, instance)
if commit:
instance.save()
return instance
Expand Down
14 changes: 10 additions & 4 deletions apps/blog/utils/slug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
from django.utils.text import slugify


def generate_unique_slug(klass, field):
def generate_unique_slug(klass, field, instance=None):
"""
return unique slug if origin slug is exist.
eg: `foo-bar` => `foo-bar-1`
:param `klass` is Class model.
:param `field` is specific field for title.
:param `instance` is instance object for excluding specific object.
"""
origin_slug = slugify(field)
unique_slug = origin_slug
numb = 1
while klass.objects.filter(slug=unique_slug).exists():
unique_slug = '%s-%d' % (origin_slug, numb)
numb += 1
if instance is not None:
while klass.objects.filter(slug=unique_slug).exclude(id=instance.id).exists():
unique_slug = '%s-%d' % (origin_slug, numb)
numb += 1
else:
while klass.objects.filter(slug=unique_slug).exists():
unique_slug = '%s-%d' % (origin_slug, numb)
numb += 1
return unique_slug
14 changes: 7 additions & 7 deletions locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-10-11 11:18+0700\n"
"POT-Creation-Date: 2020-11-18 19:11+0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: SUMMON AGUS <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -323,27 +323,27 @@ msgstr ""
msgid "Tags"
msgstr ""

#: apps/blog/views/addons.py:33
#: apps/blog/views/addons.py:31
msgid "`object_id` and `content_type` must filled!"
msgstr ""

#: apps/blog/views/addons.py:37
#: apps/blog/views/addons.py:35
msgid "`object_id` should be integer!"
msgstr ""

#: apps/blog/views/addons.py:41
#: apps/blog/views/addons.py:39
msgid "You must login to mark as favorite!"
msgstr ""

#: apps/blog/views/addons.py:47
#: apps/blog/views/addons.py:45
msgid "This `content_type` doesn't exist!"
msgstr ""

#: apps/blog/views/addons.py:56
#: apps/blog/views/addons.py:54
msgid "The post marked as favorite!"
msgstr ""

#: apps/blog/views/addons.py:59
#: apps/blog/views/addons.py:57
msgid "The post removed from favorite!"
msgstr ""

Expand Down
14 changes: 7 additions & 7 deletions locale/id/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-10-11 11:19+0700\n"
"POT-Creation-Date: 2020-11-18 19:11+0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: SUMMON AGUS <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -323,27 +323,27 @@ msgstr "Tag"
msgid "Tags"
msgstr "Tag"

#: apps/blog/views/addons.py:33
#: apps/blog/views/addons.py:31
msgid "`object_id` and `content_type` must filled!"
msgstr "`object_id` dan `content_type` harus diisi!"

#: apps/blog/views/addons.py:37
#: apps/blog/views/addons.py:35
msgid "`object_id` should be integer!"
msgstr "`object_id` harus berupa angka!"

#: apps/blog/views/addons.py:41
#: apps/blog/views/addons.py:39
msgid "You must login to mark as favorite!"
msgstr "Anda harus login untuk menandai sebagai favorit!"

#: apps/blog/views/addons.py:47
#: apps/blog/views/addons.py:45
msgid "This `content_type` doesn't exist!"
msgstr "`content_type` ini tidak ada!"

#: apps/blog/views/addons.py:56
#: apps/blog/views/addons.py:54
msgid "The post marked as favorite!"
msgstr "Postingan ditandai sebagai favorit!"

#: apps/blog/views/addons.py:59
#: apps/blog/views/addons.py:57
msgid "The post removed from favorite!"
msgstr "Postingan dihapus dari favorit!"

Expand Down
2 changes: 1 addition & 1 deletion templates/apps/blog/page/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

{% block content %}
<div class="container p-3">
<h5><a class="no-underline" href="">{{ page_title }}</a></h5>
<h5 class="mt-5 pt-4"><a class="no-underline" href="">{{ page_title }}</a></h5>
<div class="mt-4 row row-content">
<div class="col-md-8">
<div class="martor-preview">
Expand Down
2 changes: 1 addition & 1 deletion templates/apps/product/list_private.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<nav class="navbar navbar-light bg-light mt-3">
<form class="form-inline" method="get">{% csrf_token %}
<input name="q" class="form-control mr-sm-2 text-sm" type="search" {% if request.GET.q %}value="{{ request.GET.q }}" placeholder="{% trans 'Search...' %}" aria-label="Search" required>
<input name="q" class="form-control mr-sm-2 text-sm" type="search" {% if request.GET.q %}value="{{ request.GET.q }}"{% endif %} placeholder="{% trans 'Search...' %}" aria-label="Search" required>
<button class="btn bg-gradient-default text-normal" type="submit">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-search" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M10.442 10.442a1 1 0 0 1 1.415 0l3.85 3.85a1 1 0 0 1-1.414 1.415l-3.85-3.85a1 1 0 0 1 0-1.415z"/>
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@

<body>
{% include "includes/navbar.html" %}
{% include "includes/messages.html" %}

<div class="main-container">
{% include "includes/messages.html" %}
{% block content %}{% endblock %}
</div>

Expand Down

0 comments on commit 1c0727e

Please sign in to comment.