Skip to content

Commit f1ba445

Browse files
author
roniahmadi
committed
update
1 parent c0ec2a3 commit f1ba445

37 files changed

+411
-167
lines changed

apidata/serializers/produks_serializer.py

+47-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.db.models import Avg
22
from django.urls import reverse
33
from rest_framework import serializers
4+
from frontend.view_helper import translater
45

56
from produk.models import (
67
GambarProduk,
@@ -16,24 +17,61 @@
1617

1718

1819
class KategoriSerializer(serializers.HyperlinkedModelSerializer):
20+
nama = serializers.SerializerMethodField()
21+
1922
class Meta:
2023
model = Kategori
2124
fields = ["url", "kode", "icon", "nama"]
2225

26+
def get_nama(self, obj):
27+
user = self.context["users"]
28+
languanges_code = user.languages.code if user.languages else "id"
29+
translate_text = translater(
30+
translate_to=languanges_code,
31+
page=obj.nama,
32+
values=obj.nama
33+
)
34+
return translate_text
35+
2336

2437
class TipeProdukSerializer(serializers.HyperlinkedModelSerializer):
38+
nama = serializers.SerializerMethodField()
39+
2540
class Meta:
2641
model = TipeProduk
2742
fields = ["url", "nama"]
2843

44+
def get_nama(self, obj):
45+
user = self.context["users"]
46+
languanges_code = user.languages.code if user.languages else "id"
47+
translate_text = translater(
48+
translate_to=languanges_code,
49+
page=obj.nama,
50+
values=obj.nama
51+
)
52+
return translate_text
53+
2954

3055
class WarnaProdukSerializer(serializers.HyperlinkedModelSerializer):
56+
nama = serializers.SerializerMethodField()
57+
3158
class Meta:
3259
model = WarnaProduk
3360
fields = ["url", "nama"]
3461

62+
def get_nama(self, obj):
63+
user = self.context["users"]
64+
languanges_code = user.languages.code if user.languages else "id"
65+
translate_text = translater(
66+
translate_to=languanges_code,
67+
page=obj.nama,
68+
values=obj.nama
69+
)
70+
return translate_text
71+
3572

3673
class GambarProdukSerializer(serializers.HyperlinkedModelSerializer):
74+
3775
class Meta:
3876
model = GambarProduk
3977
fields = ["gambar", "nama"]
@@ -48,6 +86,8 @@ class ProdukSerializer(serializers.HyperlinkedModelSerializer):
4886
count_star = serializers.SerializerMethodField()
4987
produk_detail_url = serializers.SerializerMethodField()
5088

89+
nama = serializers.SerializerMethodField()
90+
5191
class Meta:
5292
model = Produk
5393
fields = [
@@ -72,6 +112,12 @@ class Meta:
72112
"produk_detail_url",
73113
]
74114

115+
def get_nama(self, obj):
116+
user = self.context["users"]
117+
user_lang = user.languages.code if user.languages else "id"
118+
print(translater(translate_to=user_lang, page=obj.nama, values=obj.nama))
119+
return translater(translate_to=user_lang, page=obj.nama, values=obj.nama)
120+
75121
def get_count_star(self, obj):
76122
countstar = (
77123
UlasanCart.objects.filter(produkitem_id=obj.id).aggregate(Avg("produk"))[
@@ -86,7 +132,7 @@ def get_produk_detail_url(self, obj):
86132
return urldetail
87133

88134
def get_gambar(self, obj):
89-
gambars = GambarProduk.objects.filter(produk__pk=obj.pk).order_by("-pk")
135+
gambars = GambarProduk.objects.filter(produk__pk=obj.pk, gambar__isnull=False).order_by("-pk")
90136
return GambarProdukSerializer(gambars, many=True).data
91137

92138
def get_store(self, obj):

apidata/urls.py

+5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@
3232
router.register(r"storeaddres", UserStoreAddressViewset)
3333
router.register(r"ulasanproduk", UlasanViewSet)
3434

35+
produk_list = ProdukViewSet.as_view({
36+
'get': 'list',
37+
})
38+
3539
# Wire up our API using automatic URL routing.
3640
# Additionally, we include login URLs for the browsable API.
3741
urlpatterns = [
3842
path("", include(router.urls)),
43+
path("produk", produk_list, name="produks"),
3944
path("login", UserAuthToken.as_view()),
4045
path("register", RegisterUserAPIView.as_view()),
4146
path("me", MeViewSet.as_view()),

apidata/viewsets/produks_viewset.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ class ProdukViewSet(viewsets.ModelViewSet):
3939
"""
4040
API endpoint that allows users to be viewed or edited.
4141
"""
42-
4342
filter_backends = [DjangoFilterBackend]
44-
filterset_fields = ["kategori"]
43+
filterset_fields = ["kategori", "negara"]
4544
queryset = Produk.objects.all()
4645
serializer_class = ProdukSerializer
4746
http_method_names = ["get", "head", "option"]
47+
48+
def get_serializer_context(self):
49+
context = super().get_serializer_context()
50+
context["users"] = self.request.user
51+
return context

config_json/google-json.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"apiKey": "AIzaSyC0lUXHwQdTFXz8KkC5D7zy-t47RrkIvsY",
3+
"authDomain": "geraipi-indonesia.firebaseapp.com",
4+
"projectId": "geraipi-indonesia",
5+
"storageBucket": "geraipi-indonesia.appspot.com",
6+
"messagingSenderId": "981139646267",
7+
"appId": "1:981139646267:web:53cc230affb50210a5391e",
8+
"measurementId": "G-F368X3MB4J"
9+
}

frontend/admin.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from django.contrib import admin
22

3-
from frontend.models import Banner, ContentTranslate
3+
from frontend.models import Banner, ContentTranslate, Pengumuman
44

55
# Register your models here.
66
admin.site.register(Banner)
77
admin.site.register(ContentTranslate)
8+
admin.site.register(Pengumuman)

frontend/management/__init__.py

Whitespace-only changes.

frontend/management/commands/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django.core.management.base import BaseCommand
2+
from deep_translator import (GoogleTranslator)
3+
from profiles.models import LangSupport
4+
5+
6+
class Command(BaseCommand):
7+
help = "Import and insert langsupport"
8+
9+
def handle(self, *args, **options):
10+
LangSupport.objects.all().delete()
11+
translate_lang = GoogleTranslator().get_supported_languages(as_dict=True)
12+
for tl in translate_lang:
13+
lang_codes = translate_lang[tl]
14+
langs = tl
15+
print(tl)
16+
LangSupport.objects.create(code=lang_codes, alias=langs)
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated by Django 4.1.2 on 2024-03-03 04:25
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("frontend", "0004_alter_contenttranslate_tag_data"),
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name="Pengumuman",
15+
fields=[
16+
(
17+
"id",
18+
models.BigAutoField(
19+
auto_created=True,
20+
primary_key=True,
21+
serialize=False,
22+
verbose_name="ID",
23+
),
24+
),
25+
("text_pengumuman", models.TextField(blank=True, null=True)),
26+
("is_active", models.BooleanField(default=True)),
27+
],
28+
options={
29+
"verbose_name": "Pengumuman Website",
30+
"verbose_name_plural": "Pengumuman Website",
31+
},
32+
),
33+
]

frontend/models.py

+12
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ class Meta:
2424

2525
def __str__(self):
2626
return self.tag_data or "-"
27+
28+
29+
class Pengumuman(models.Model):
30+
text_pengumuman = models.TextField(blank=True, null=True)
31+
is_active = models.BooleanField(default=True)
32+
33+
class Meta:
34+
verbose_name = "Pengumuman Website"
35+
verbose_name_plural = "Pengumuman Website"
36+
37+
def __str__(self):
38+
return self.text_pengumuman

frontend/templates/checkout/home_beli.html

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends 'layout.html' %}
2-
{% load static %}
2+
{% load static translater %}
33
{% block content %}
44
<div class="mt-3 mb-4">
55
<form action="" method="post">
@@ -12,13 +12,13 @@
1212
</div>
1313
{% endif %}
1414
<div class="flex justify-center mx-3">
15-
<h4> Checkout {{ cart_item.produk.nama }}</h4>
15+
<h4> {% translater user.languages.code "Checkout" "Checkout" %} {{ cart_item.produk.nama }}</h4>
1616
</div>
1717
<div id="checkout-id">
1818
<div class="my-3 border rounded-lg p-3 shadow-lg">
1919
<div class="border rounded flex flex-row my-2 bg-slate-200">
2020
<div class="p-3">
21-
Alamat : <br />
21+
{% translater user.languages.code "Alamat" "Alamat" %} : <br />
2222
{{ alamat.address }} - {{ alamat.zipcode }} - RT {{ alamat.rt }} - RW {{ alamat.rw }} - {{ alamat.province.nama }} - {{ alamat.regency.name }} - {{ alamat.distric.name }}
2323
</div>
2424
</div>
@@ -31,7 +31,7 @@ <h4> Checkout {{ cart_item.produk.nama }}</h4>
3131
{% endif %}
3232
</div>
3333
<div class="flex flex-col px-2">
34-
<strong class="">{{ produk.nama }}</strong>
34+
<strong class="">{% translater user.languages.code produk.nama produk.nama %}</strong>
3535
<strong>
3636
<h4 class="">{{ produk.harga }} 𝛑</h4>
3737
</strong>
@@ -41,11 +41,11 @@ <h4 class="">{{ produk.harga }} 𝛑</h4>
4141
</div>
4242
<div class="my-3">
4343
<div class="border rounded bg-slate-200 flex justify-between px-3 flex-col shadow-lg">
44-
<div class="text-center text-sm font-bold">TOTAL PEMBAYARAN</div>
44+
<div class="text-center text-sm font-bold">{% translater user.languages.code "TOTAL PEMBAYARAN" "TOTAL PEMBAYARAN" %}</div>
4545
<div class="flex flex-col gap-0">
4646
<div class="flex flex-row justify-between">
4747
<span>
48-
Harga
48+
{% translater user.languages.code "Harga" "Harga" %}
4949
</span>
5050
<span>
5151
{{ produk.harga }} Pi
@@ -61,7 +61,7 @@ <h4 class="">{{ produk.harga }} 𝛑</h4>
6161
</div>
6262
<div class="flex flex-row justify-between">
6363
<span>
64-
Jumlah Total
64+
{% translater user.languages.code "Jumlah Total" "Jumlah Total" %}
6565
</span>
6666
<span class="jumlah_ppn">
6767
{{ total_pajak }}
@@ -75,7 +75,7 @@ <h4 class="">{{ produk.harga }} 𝛑</h4>
7575
<button type="submit" class="p-2 text-center w-screen bg-slate-200 rounded no-underline text-black">Checkout</button>
7676
{% endif %}
7777
</div>
78-
<p class="my-3"><strong>Note:</strong> Barang yang sudah dibeli Tidak Bisa dikembalikan lagi</p>
78+
<p class="my-3"><strong>{% translater user.languages.code "Note" "Note" %}:</strong>{% translater user.languages.code "Barang yang sudah dibeli Tidak Bisa dikembalikan lagi" "Barang yang sudah dibeli Tidak Bisa dikembalikan lagi" %} </p>
7979
</div>
8080
</form>
8181
</div>

frontend/templates/home_detail.html frontend/templates/home/detail.html

+9-8
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h3 class="text-xl my-2 font-bold">{% translater user.languages.code "Deskripsi
6565
</td>
6666
</tr>
6767
<tr>
68-
<td>Warna</td>
68+
<td>{%translater user.languages.code "Warna" "Warna"%}</td>
6969
<td>:</td>
7070
<td class="flex flex-wrap gap-2 flex-row">
7171
<span class=" py-[2px] px-2 w-full">
@@ -76,27 +76,27 @@ <h3 class="text-xl my-2 font-bold">{% translater user.languages.code "Deskripsi
7676
</td>
7777
</tr>
7878
<tr>
79-
<td>Stok</td>
79+
<td>{%translater user.languages.code "Stok" "Stok"%}</td>
8080
<td>:</td>
8181
<td class="flex flex-wrap gap-2 flex-row">
8282
<span class=" py-[2px] px-2 w-full">{{ produk.stok_produk }}</span>
8383
</td>
8484
</tr>
8585
<tr>
86-
<td>Lintas Negara ?</td>
86+
<td>{% translater user.languages.code "Lintas Negara ?" "Lintas Negara ?" %}</td>
8787
<td>:</td>
8888
<td class="flex flex-wrap gap-2 flex-row">
8989
<span class=" py-[2px] px-2 w-full">
9090
{% if produk.cross_boarder %}
91-
YA
91+
{%translater user.languages.code "YA" "YA"%}
9292
{% else %}
93-
TIDAK
93+
{%translater user.languages.code "TIDAK" "TIDAK"%}
9494
{% endif %}
9595
</span>
9696
</td>
9797
</tr>
9898
<tr>
99-
<td>Keterangan</td>
99+
<td>{%translater user.languages.code "Keterangan" "Keterangan"%}</td>
100100
<td>:</td>
101101
<td></td>
102102
</tr>
@@ -148,9 +148,10 @@ <h2 class="font-bold">Review</h2>
148148
$.ajax({
149149
url: next,
150150
method:"get",
151-
data:{},
151+
data:{
152+
produk: "{{produk.id}}"
153+
},
152154
success:function(res){
153-
154155
let html = ''
155156
if(res.count > 0){
156157
$.each(res.results, function(index, datas){

0 commit comments

Comments
 (0)