Country id
This commit is contained in:
parent
1bd3cc9170
commit
43531d88dc
24
apps/comment/migrations/0003_auto_20191015_0704.py
Normal file
24
apps/comment/migrations/0003_auto_20191015_0704.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-15 07:04
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('location', '0012_data_migrate'),
|
||||||
|
('comment', '0002_comment_language'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='comment',
|
||||||
|
name='language',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='comment',
|
||||||
|
name='country',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='location.Country', verbose_name='Country'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -7,6 +7,8 @@ from account.models import User
|
||||||
from utils.models import ProjectBaseMixin
|
from utils.models import ProjectBaseMixin
|
||||||
from utils.querysets import ContentTypeQuerySetMixin
|
from utils.querysets import ContentTypeQuerySetMixin
|
||||||
from translation.models import Language
|
from translation.models import Language
|
||||||
|
from location.models import Country
|
||||||
|
|
||||||
|
|
||||||
class CommentQuerySet(ContentTypeQuerySetMixin):
|
class CommentQuerySet(ContentTypeQuerySetMixin):
|
||||||
"""QuerySets for Comment model."""
|
"""QuerySets for Comment model."""
|
||||||
|
|
@ -41,7 +43,11 @@ class Comment(ProjectBaseMixin):
|
||||||
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||||
|
|
||||||
objects = CommentQuerySet.as_manager()
|
objects = CommentQuerySet.as_manager()
|
||||||
language = models.ForeignKey(Language, verbose_name=_('Locale'), on_delete=models.SET_NULL, null=True)
|
country = models.ForeignKey(Country, verbose_name=_('Country'),
|
||||||
|
on_delete=models.SET_NULL, null=True)
|
||||||
|
# language = models.ForeignKey(Language, verbose_name=_('Locale'),
|
||||||
|
# on_delete=models.SET_NULL, null=True
|
||||||
|
# )
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class"""
|
"""Meta class"""
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ class IsCountryAdmin(IsGuest):
|
||||||
# Read permissions are allowed to any request.
|
# Read permissions are allowed to any request.
|
||||||
|
|
||||||
# Must have role
|
# Must have role
|
||||||
role = Role.objects.filter(role=Role.COUNTRY_ADMIN).first() # 'Country admin'
|
role = Role.objects.filter(role=Role.COUNTRY_ADMIN, country_id=obj.country_id).first() # 'Country admin'
|
||||||
is_access = UserRole.objects.filter(user=request.user, role=role).exists()
|
is_access = UserRole.objects.filter(user=request.user, role=role).exists()
|
||||||
|
|
||||||
if super().has_object_permission(request, view, obj) and is_access:
|
if super().has_object_permission(request, view, obj) and is_access:
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class BasePermissionTests(APITestCase):
|
||||||
user=self.user_test["user"],
|
user=self.user_test["user"],
|
||||||
object_id= self.country_ru.pk,
|
object_id= self.country_ru.pk,
|
||||||
content_type_id=content_type.id,
|
content_type_id=content_type.id,
|
||||||
language=self.lang
|
country=self.country_ru
|
||||||
)
|
)
|
||||||
self.comment.save()
|
self.comment.save()
|
||||||
self.url = reverse('back:comment:comment-crud', kwargs={"id": self.comment.id})
|
self.url = reverse('back:comment:comment-crud', kwargs={"id": self.comment.id})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user