diff --git a/coupons/forms.py b/coupons/forms.py index 2316c77..7dde1a9 100644 --- a/coupons/forms.py +++ b/coupons/forms.py @@ -41,7 +41,7 @@ def clean_code(self): raise forms.ValidationError(_("This code is not valid.")) self.coupon = coupon - if self.user is None and coupon.user_limit is not 1: + if self.user is None and coupon.user_limit != 1: # coupons with can be used only once can be used without tracking the user, otherwise there is no chance # of excluding an unknown user from multiple usages. raise forms.ValidationError(_( @@ -56,7 +56,7 @@ def clean_code(self): if user_coupon.redeemed_at is not None: raise forms.ValidationError(_("This code has already been used by your account.")) except CouponUser.DoesNotExist: - if coupon.user_limit is not 0: # zero means no limit of user count + if coupon.user_limit != 0: # zero means no limit of user count # only user bound coupons left and you don't have one if coupon.user_limit is coupon.users.filter(user__isnull=False).count(): raise forms.ValidationError(_("This code is not valid for your account.")) diff --git a/coupons/locale/pl/LC_MESSAGES/django.mo b/coupons/locale/pl/LC_MESSAGES/django.mo new file mode 100644 index 0000000..17fc719 Binary files /dev/null and b/coupons/locale/pl/LC_MESSAGES/django.mo differ diff --git a/coupons/locale/pl/LC_MESSAGES/django.po b/coupons/locale/pl/LC_MESSAGES/django.po new file mode 100644 index 0000000..7ce9944 --- /dev/null +++ b/coupons/locale/pl/LC_MESSAGES/django.po @@ -0,0 +1,159 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-03-22 10:13+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=4; plural=(n==1 ? 0 : (n%10>=2 && n%10<=4) && (n" +"%100<12 || n%100>=14) ? 1 : n!=1 && (n%10>=0 && n%10<=1) || (n%10>=5 && n" +"%10<=9) || (n%100>=12 && n%100<=14) ? 2 : 3);\n" +#: coupons/admin.py:60 +msgid "Your coupons have been generated." +msgstr "Kupony zostały wygenerowane." + +#: coupons/admin.py:76 +msgid "coupons" +msgstr "kupony" + +#: coupons/admin.py:80 +msgid "used" +msgstr "wykorzystane" + +#: coupons/admin.py:84 +msgid "unused" +msgstr "niewykorzystane" + +#: coupons/admin.py:88 +msgid "expired" +msgstr "przedawnione" + +#: coupons/forms.py:9 +msgid "Quantity" +msgstr "Liczba kuponów" + +#: coupons/forms.py:10 coupons/models.py:69 +msgid "Value" +msgstr "Wartość" + +#: coupons/forms.py:11 coupons/models.py:73 +msgid "Type" +msgstr "Typ" + +#: coupons/forms.py:13 coupons/models.py:77 +msgid "Valid until" +msgstr "Data ważności" + +#: coupons/forms.py:14 coupons/models.py:78 +msgid "Leave empty for coupons that never expire" +msgstr "Pozostaw puste dla kuponów bezterminowych" + +#: coupons/forms.py:18 coupons/models.py:79 coupons/models.py:143 +msgid "Campaign" +msgstr "Kampania" + +#: coupons/forms.py:23 +msgid "Coupon code" +msgstr "Kod kuponu" + +#: coupons/forms.py:41 +msgid "This code is not valid." +msgstr "Kod nie jest poprawny." + +#: coupons/forms.py:48 +msgid "" +"The server must provide an user to this form to allow you to use this code. " +"Maybe you need to sign in?" +msgstr "Kod może być użyty tylko przez zalogowanych użytkowników. Zaloguj się, by móc go wykorzystać." + +#: coupons/forms.py:52 coupons/forms.py:64 +msgid "This code has already been used." +msgstr "Kod został już wykorzystany." + +#: coupons/forms.py:57 +msgid "This code has already been used by your account." +msgstr "Kod został już przez ciebie wykorzystany." + +#: coupons/forms.py:62 +msgid "This code is not valid for your account." +msgstr "Kod nie jest ważny dla twojego konta." + +#: coupons/forms.py:66 +msgid "This code is not meant to be used here." +msgstr "Kod nie może być wykorzystany w tym miejscu." + +#: coupons/forms.py:68 +msgid "This code is expired." +msgstr "Termin ważności kodu upłynął." + +#: coupons/models.py:69 +msgid "Arbitrary coupon value" +msgstr "Umowna wartość kuponu" + +#: coupons/models.py:71 coupons/templates/admin/generate_coupons.html:59 +msgid "Code" +msgstr "Kod" + +#: coupons/models.py:72 +msgid "Leaving this field empty will generate a random code." +msgstr "Pozostaw to pole puste, aby automatycznie wygenerować losowy kod." + +#: coupons/models.py:74 +msgid "User limit" +msgstr "Limit użytkowników" + +#: coupons/models.py:75 +msgid "Created at" +msgstr "Data utworzenia" + +#: coupons/models.py:85 +msgid "Coupon" +msgstr "Kupon" + +#: coupons/models.py:86 coupons/templates/admin/generate_coupons.html:36 +msgid "Coupons" +msgstr "Kupony" + +#: coupons/models.py:138 +msgid "Name" +msgstr "Nazwa" + +#: coupons/models.py:139 +msgid "Description" +msgstr "Opis" + +#: coupons/models.py:144 +msgid "Campaigns" +msgstr "Kampanie" + +#: coupons/models.py:153 +msgid "User" +msgstr "Użytkownik" + +#: coupons/models.py:154 +msgid "Redeemed at" +msgstr "Data użycia" + +#: coupons/templates/admin/generate_coupons.html:35 +msgid "Home" +msgstr "Strona główna" + +#: coupons/templates/admin/generate_coupons.html:37 +#: coupons/templates/admin/generate_coupons.html:49 +msgid "Generate coupons" +msgstr "Wygeneruj kupony" + +#: coupons/templates/admin/generate_coupons.html:58 +msgid "Id" +msgstr "Id" diff --git a/coupons/migrations/0001_initial.py b/coupons/migrations/0001_initial.py index 56e2883..dac5a53 100644 --- a/coupons/migrations/0001_initial.py +++ b/coupons/migrations/0001_initial.py @@ -21,7 +21,11 @@ class Migration(migrations.Migration): ('type', models.CharField(max_length=20, verbose_name='Type', choices=[(b'monetary', b'Money based coupon'), (b'percentage', b'Percentage discount'), (b'virtual_currency', b'Virtual currency')])), ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')), ('redeemed_at', models.DateTimeField(null=True, verbose_name='Redeemed at', blank=True)), - ('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, help_text='You may specify a user you want to restrict this coupon to.', null=True, verbose_name='User')), + ('user', models.ForeignKey( + blank=True, to=settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, + help_text='You may specify a user you want to restrict this coupon to.', null=True, verbose_name='User', + )), ], options={ 'ordering': ['created_at'], diff --git a/coupons/migrations/0003_auto_20150416_0617.py b/coupons/migrations/0003_auto_20150416_0617.py index 1b3cce4..97c5d7b 100644 --- a/coupons/migrations/0003_auto_20150416_0617.py +++ b/coupons/migrations/0003_auto_20150416_0617.py @@ -28,7 +28,10 @@ class Migration(migrations.Migration): migrations.AddField( model_name='coupon', name='campaign', - field=models.ForeignKey(related_name=b'coupons', verbose_name='Campaign', blank=True, to='coupons.Campaign', null=True), + field=models.ForeignKey( + related_name='coupons', verbose_name='Campaign', blank=True, to='coupons.Campaign', null=True, + on_delete=models.CASCADE, + ), preserve_default=True, ), migrations.AlterField( diff --git a/coupons/migrations/0004_auto_20151105_1456.py b/coupons/migrations/0004_auto_20151105_1456.py index 5fbbc0e..663a974 100644 --- a/coupons/migrations/0004_auto_20151105_1456.py +++ b/coupons/migrations/0004_auto_20151105_1456.py @@ -33,11 +33,14 @@ class Migration(migrations.Migration): migrations.AddField( model_name='couponuser', name='coupon', - field=models.ForeignKey(related_name='users', to='coupons.Coupon'), + field=models.ForeignKey(related_name='users', to='coupons.Coupon', on_delete=models.CASCADE), ), migrations.AddField( model_name='couponuser', name='user', - field=models.ForeignKey(null=True, to=settings.AUTH_USER_MODEL, blank=True, verbose_name='User'), + field=models.ForeignKey( + null=True, to=settings.AUTH_USER_MODEL, blank=True, verbose_name='User', + on_delete=models.CASCADE, + ), ), ] diff --git a/coupons/models.py b/coupons/models.py index 2b69741..45de179 100644 --- a/coupons/models.py +++ b/coupons/models.py @@ -76,7 +76,13 @@ class Coupon(models.Model): valid_until = models.DateTimeField( _("Valid until"), blank=True, null=True, help_text=_("Leave empty for coupons that never expire")) - campaign = models.ForeignKey('Campaign', verbose_name=_("Campaign"), blank=True, null=True, related_name='coupons') + campaign = models.ForeignKey( + 'Campaign', + on_delete=models.CASCADE, + verbose_name=_("Campaign"), + blank=True, null=True, + related_name='coupons', + ) objects = CouponManager() @@ -101,7 +107,7 @@ def is_redeemed(self): """ Returns true is a coupon is redeemed (completely for all users) otherwise returns false. """ return self.users.filter( redeemed_at__isnull=False - ).count() >= self.user_limit and self.user_limit is not 0 + ).count() >= self.user_limit and self.user_limit != 0 @property def redeemed_at(self): @@ -149,8 +155,18 @@ def __str__(self): @python_2_unicode_compatible class CouponUser(models.Model): - coupon = models.ForeignKey(Coupon, related_name='users') - user = models.ForeignKey(user_model, verbose_name=_("User"), null=True, blank=True) + coupon = models.ForeignKey( + Coupon, + on_delete=models.CASCADE, + related_name='users', + ) + user = models.ForeignKey( + user_model, + on_delete=models.CASCADE, + verbose_name=_("User"), + null=True, + blank=True, + ) redeemed_at = models.DateTimeField(_("Redeemed at"), blank=True, null=True) class Meta: