Commit 4a7f5edc authored by okhin's avatar okhin 🚴

Moving to a djangobased translatiosn for texts

parent da2b0027
......@@ -11,7 +11,7 @@ class InlineImporter(admin.TabularInline):
model = Importer
class CampaignAdmin(admin.ModelAdmin):
inlines = [InlineContact, Importer]
inlines = [InlineContact, InlineImporter]
def get_queryset(self, request):
qs = super(CampaignAdmin, self).get_queryset(request)
......
......@@ -6,8 +6,6 @@ from picampaign.organization.models import Organization
from picampaign.contact.models import Contact
LANGUAGES = map(lambda k: (k[0], _(k[1])), settings.LANGUAGES)
class Campaign(models.Model):
"""Campaign model, describe what have to be achieved"""
id = models.AutoField(primary_key=True)
......@@ -16,27 +14,21 @@ class Campaign(models.Model):
organization = models.ForeignKey(Organization, related_name='campaigns')
start_date = models.DateField()
end_date = models.DateField()
default_lang = models.CharField(max_length=5,
choices=LANGUAGES,
verbose_name=_('language'))
phone_filter = models.CharField(max_length=20, null=True, blank=True)
def __str__(self):
return self.title
class Argumentary(models.Model):
"""Argumentary in a given language for a campaign"""
"""Argumentary for a campaign"""
id = models.AutoField(primary_key=True)
campaign = models.ForeignKey(Campaign)
lang = models.CharField(max_length=5,
choices=LANGUAGES,
verbose_name=_('language'))
title = models.CharField(max_length=255, verbose_name=_('title'), null=True, blank=True)
text = models.TextField(null=True)
def __str__(self):
args = {'lang': self.lang, 'title': self.campaign.title}
return _('Argumentary in %(lang)s for %(title)s') % args
args = {'title': self.campaign.title}
return _('Argumentary for %(title)s') % args
class CampaignContact(models.Model):
"""List contact related to a campaign with a given weight"""
......
......@@ -9,7 +9,7 @@ class ArgumentarySerializer(serializers.ModelSerializer):
class Meta:
model = Argumentary
fields = ('lang', 'text', 'title')
fields = ('text', 'title')
class PhoneSerializer(serializers.ModelSerializer):
......
......@@ -22,7 +22,6 @@ class ArgumentaryAdminTest(TestCase):
organization=self.organization
)
self.argumentary = Argumentary.objects.create(
lang='en',
text='A pertinent argument',
campaign=self.campaign
)
......
......@@ -15,10 +15,9 @@ class ArgumentaryMethodTests(TestCase):
)
argumentary = Argumentary(
campaign=campaign,
lang='fr',
text='Argument number 1'
)
self.assertEqual(str(argumentary), 'Argumentary in fr for Campaign Title')
self.assertEqual(str(argumentary), 'Argumentary for Campaign Title')
class CampaignMethodTests(TestCase):
def test_str(self):
......
......@@ -19,12 +19,11 @@ class ArgumentarySerializerTest(TestCase):
organization=organization
)
Argumentary.objects.create(
lang='en',
text='A pertinent argument',
title='A title',
campaign = campaign
)
self.assertEqual(ArgumentarySerializer(Argumentary.objects.all(), many=True).data, [OrderedDict([('lang', 'en'), ('text', 'A pertinent argument'), ('title', 'A title')])])
self.assertEqual(ArgumentarySerializer(Argumentary.objects.all(), many=True).data, [OrderedDict([('text', 'A pertinent argument'), ('title', 'A title')])])
class CampaignContactSerializerTest(TestCase):
def test_to_representation(self):
......
......@@ -17,7 +17,6 @@ class ViewSetTest(TestCase):
organization=self.organization
)
self.argumentary = Argumentary.objects.create(
lang='en',
text='A pertinent argument',
title='A title',
campaign=self.campaign
......@@ -53,8 +52,8 @@ class ViewSetTest(TestCase):
client = APIClient()
response = client.get('/campaigns/%(cid)d/arguments/' % {'cid': self.campaign.id}, format='json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'[{"lang":"en","text":"A pertinent argument","title":"A title"}]')
response = client.get('/campaigns/%(cid)d/arguments/%(lang)s/' % {'cid': self.campaign.id, 'lang': self.argumentary.lang}, format='json')
self.assertEqual(response.content, b'[{"text":"A pertinent argument","title":"A title"}]')
response = client.get('/campaigns/%(cid)d/arguments/' % {'cid': self.campaign.id }, format='json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'{"lang":"en","text":"A pertinent argument","title":"A title"}')
self.assertEqual(response.content, b'[{"text":"A pertinent argument","title":"A title"}]')
......@@ -35,8 +35,3 @@ class ArgumentaryViewSet(viewsets.ReadOnlyModelViewSet):
argumentaries = self.queryset.filter(campaign=campaign_pk)
serializer = self.serializer_class(argumentaries.all(), many=True)
return Response(serializer.data)
def retrieve(self, request, pk=None, campaign_pk=None):
argument = self.queryset.get(lang=pk, campaign=campaign_pk)
serializer = self.serializer_class(argument)
return Response(serializer.data)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment