Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
344b11e
add BaseContentModel.lang = M2M(Language) for filtering
mindey Jan 16, 2016
41e6003
simplified IndexView, made only the items created this week to appear…
mindey Jan 16, 2016
22cea42
fix - editing of content object should update its own language transl…
mindey Jan 16, 2016
614d1cd
post_save for Translation
mindey Jan 16, 2016
d8f851b
translation post_save, post_delete to add/remove BaseContentModel.lan…
mindey Jan 16, 2016
9cfd714
since saving the original object fields do not propagate to translati…
mindey Jan 16, 2016
7f9bca9
fix links from enumeration of sub-objects, in their templates
mindey Jan 16, 2016
0114a68
remove the info about how many hours ago smth was commented to avoid …
mindey Jan 16, 2016
34e5958
add hour_value to index
mindey Jan 16, 2016
1aad7c7
kwargs to context
mindey Jan 16, 2016
36b33ce
made INBOX be multilingual by default, so that messages shared with s…
mindey Jan 16, 2016
488f9e7
add translations, and make public Needs visible as public letters
mindey Jan 16, 2016
d966672
remove the private content from public index, even for logged in user
mindey Jan 16, 2016
ecb15f9
added basic horizontal scroll buttons
mindey Jan 16, 2016
8a17121
adapted for Django 1.9 change for Chinese language code: https://gith…
mindey Jan 17, 2016
ba7d98e
basic search by name in original language
mindey Jan 17, 2016
5c8da1f
Merge pull request #207 from WeFindX/index-search
mindey Jan 18, 2016
37b227e
Prefill sharing settings to child objects in Need-To-Work hierarchy -…
mindey Jan 18, 2016
0d2124c
privacy: don't show titles of private child items in detail views.
mindey Jan 18, 2016
c90160d
privacy: hide parent object title of private objects.
mindey Jan 18, 2016
8ffeb01
remove definition-create from the main url index '/', and assigne Ind…
mindey Jan 20, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion src/apps/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ def __init__(self, *args, **kwargs):
])
)
self.helper.layout.append(Submit('save', _('Create')))
self.fields['name'] = forms.CharField()
self.fields['content'] = forms.CharField(widget=MarkdownWidget())
self.fields['summary'] = forms.CharField()
self.fields['description'] = forms.CharField(widget=MarkdownWidget())
self.fields['reason'] = forms.CharField(widget=MarkdownWidget())
self.fields['objective'] = forms.CharField(widget=MarkdownWidget())
self.fields['situation'] = forms.CharField(widget=MarkdownWidget())
self.fields['deliverable'] = forms.CharField(widget=MarkdownWidget())
self.fields['investables'] = forms.CharField()
self.fields['deliverables'] = forms.CharField()

class Meta:
model = Translation
Expand All @@ -81,7 +91,7 @@ def __init__(self, *args, **kwargs):
self.helper.layout.append(Submit('save', _('Update')))
self.fields['name'] = forms.CharField()
self.fields['content'] = forms.CharField(widget=MarkdownWidget())
self.fields['summary'] = forms.CharField(widget=MarkdownWidget())
self.fields['summary'] = forms.CharField()
self.fields['description'] = forms.CharField(widget=MarkdownWidget())
self.fields['reason'] = forms.CharField(widget=MarkdownWidget())
self.fields['objective'] = forms.CharField(widget=MarkdownWidget())
Expand Down Expand Up @@ -243,6 +253,7 @@ def __init__(self, *args, **kwargs):
self.helper.layout.append(Submit('save', _('Update')))

self.fields['name'].label = 'Description'
self.fields['name'].widget.attrs['readonly'] = True

self.fields['language'] = forms.ModelChoiceField(
widget=ModelSelect2Widget(
Expand All @@ -260,6 +271,7 @@ def __init__(self, *args, **kwargs):
queryset=User.objects.all(), required=False)

self.fields['language'].label = _('<b>Input Language</b> (the language you used to compose this post) ')
self.fields['content'].widget.attrs['readonly'] = True

class Meta:
model = Need
Expand Down Expand Up @@ -350,6 +362,10 @@ def __init__(self, *args, **kwargs):
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting a problem of the past)')
self.initial['personal'] = True

if need_instance:
self.initial['sharewith'] = need_instance.sharewith.all
self.initial['personal'] = need_instance.personal

try:
language = Language.objects.get(language_code=request.LANGUAGE_CODE)
self.initial['language'] = language
Expand Down Expand Up @@ -388,6 +404,7 @@ def __init__(self, *args, **kwargs):
self.helper.layout.append(Submit('save', _('Update')))

self.fields['name'].label = 'Description'
self.fields['name'].widget.attrs['readonly'] = True
self.fields['need'] = forms.ModelChoiceField(queryset=Need.objects.all())

self.fields['type'] = forms.ModelChoiceField(
Expand Down Expand Up @@ -428,6 +445,7 @@ def __init__(self, *args, **kwargs):
self.fields['url'].label = _('<b>Origin:</b> (of the source)')
self.fields['url'].widget.attrs.update({'placeholder': _('http://')})
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting a problem of the past)')
self.fields['reason'].widget.attrs['readonly'] = True

class Meta:
model = Goal
Expand Down Expand Up @@ -487,6 +505,8 @@ def __init__(self, *args, **kwargs):
self.fields['url'].label = _('<b>Origin:</b> (of the source)')
self.fields['url'].widget.attrs.update({'placeholder': _('http://')})
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting a historical work)')
self.fields['name'].widget.attrs['readonly'] = True
self.fields['description'].widget.attrs['readonly'] = True

class Meta:
model = Work
Expand Down Expand Up @@ -515,6 +535,7 @@ class Meta:
class WorkCreateForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
task_instance = kwargs.pop('task_instance')
request = kwargs.pop('request')
super(WorkCreateForm, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -554,6 +575,10 @@ def __init__(self, *args, **kwargs):
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting a historical work)')
self.initial['personal'] = True

if task_instance:
self.initial['sharewith'] = task_instance.sharewith.all
self.initial['personal'] = task_instance.personal

try:
language = Language.objects.get(language_code=request.LANGUAGE_CODE)
self.initial['language'] = language
Expand Down Expand Up @@ -622,6 +647,9 @@ def __init__(self, *args, **kwargs):
self.fields['url'].label = _('<b>Origin:</b> (of the source)')
self.fields['url'].widget.attrs.update({'placeholder': _('http://')})
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting an idea of the past)')
self.fields['name'].widget.attrs['readonly'] = True
self.fields['summary'].widget.attrs['readonly'] = True
self.fields['description'].widget.attrs['readonly'] = True

class Meta:
model = Idea
Expand Down Expand Up @@ -701,6 +729,10 @@ def __init__(self, *args, **kwargs):
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting an idea of the past)')
self.initial['personal'] = True

if goal_instance:
self.initial['sharewith'] = goal_instance.sharewith.all
self.initial['personal'] = goal_instance.personal

try:
language = Language.objects.get(language_code=request.LANGUAGE_CODE)
self.initial['language'] = language
Expand Down Expand Up @@ -763,6 +795,8 @@ def __init__(self, *args, **kwargs):
self.fields['url'].label = _('<b>Origin:</b> (of the source)')
self.fields['url'].widget.attrs.update({'placeholder': _('http://')})
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting a milestone of the past)')
self.fields['name'].widget.attrs['readonly'] = True
self.fields['objective'].widget.attrs['readonly'] = True

class Meta:
model = Step
Expand Down Expand Up @@ -793,6 +827,7 @@ class Meta:
class StepCreateForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
plan_instance = kwargs.pop('plan_instance')
request = kwargs.pop('request')
super(StepCreateForm, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -830,6 +865,10 @@ def __init__(self, *args, **kwargs):
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting a milestone of the past)')
self.initial['personal'] = True

if plan_instance:
self.initial['sharewith'] = plan_instance.sharewith.all
self.initial['personal'] = plan_instance.personal

try:
language = Language.objects.get(language_code=request.LANGUAGE_CODE)
self.initial['language'] = language
Expand Down Expand Up @@ -896,6 +935,8 @@ def __init__(self, *args, **kwargs):
self.fields['url'].label = _('<b>Origin:</b> (of the source)')
self.fields['url'].widget.attrs.update({'placeholder': _('http://')})
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting a historical task)')
self.fields['name'].widget.attrs['readonly'] = True
self.fields['description'].widget.attrs['readonly'] = True

class Meta:
model = Task
Expand All @@ -921,6 +962,7 @@ class Meta:
class TaskCreateForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
step_instance = kwargs.pop('step_instance')
request = kwargs.pop('request')
super(TaskCreateForm, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -952,6 +994,10 @@ def __init__(self, *args, **kwargs):
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting a historical task)')
self.initial['personal'] = True

if step_instance:
self.initial['sharewith'] = step_instance.sharewith.all
self.initial['personal'] = step_instance.personal

try:
language = Language.objects.get(language_code=request.LANGUAGE_CODE)
self.initial['language'] = language
Expand Down Expand Up @@ -1130,6 +1176,9 @@ def __init__(self, *args, **kwargs):
self.fields['url'].label = _('<b>Origin:</b> (of the source)')
self.fields['url'].widget.attrs.update({'placeholder': _('http://')})
self.fields['is_historical'].label = _('<b>This is a history</b> (check if you are documenting a project of the past)')
self.fields['name'].widget.attrs['readonly'] = True
self.fields['situation'].widget.attrs['readonly'] = True
self.fields['deliverable'].widget.attrs['readonly'] = True


class Meta:
Expand Down Expand Up @@ -1238,6 +1287,10 @@ def __init__(self, *args, **kwargs):
#self.fields['plain_equity'].label = _('Plain equity')
self.initial['personal'] = True

if idea_instance:
self.initial['sharewith'] = idea_instance.sharewith.all
self.initial['personal'] = idea_instance.personal

try:
language = Language.objects.get(language_code=request.LANGUAGE_CODE)
self.initial['language'] = language
Expand Down
36 changes: 36 additions & 0 deletions src/apps/core/management/commands/update_content_lang_m2m.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.core.management import BaseCommand
from django.contrib.contenttypes.models import ContentType

from core.models import Translation
from core.models import Need, Goal, Idea, Plan, Step, Task, Work
from core.models import Language

class Command(BaseCommand):
help = 'update BaseContentModel.lang based on existing translations for each of content item'


def handle(self, *args, **options):
content_types = ContentType.objects.get_for_models(Need, Goal, Idea, Plan, Step, Task, Work)

for model, content_type in content_types.items():
for instance in model.objects.all():

translations = Translation.objects.filter(
content_type=content_type,
object_id=instance.pk
)

tr_languages = [translation.language
for translation in translations]

# add translations
if translations:
for translation in translations:
instance.lang.add(translation.language)

# remove translations
for language in instance.lang.all():
if language not in tr_languages:
instance.lang.remove(language)

instance.save()
50 changes: 50 additions & 0 deletions src/apps/core/migrations/0023_auto_20160115_1150.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-01-15 19:50
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0022_auto_20160102_0830'),
]

operations = [
migrations.AddField(
model_name='goal',
name='lang',
field=models.ManyToManyField(blank=True, related_name='_goal_lang_+', to='core.Language'),
),
migrations.AddField(
model_name='idea',
name='lang',
field=models.ManyToManyField(blank=True, related_name='_idea_lang_+', to='core.Language'),
),
migrations.AddField(
model_name='need',
name='lang',
field=models.ManyToManyField(blank=True, related_name='_need_lang_+', to='core.Language'),
),
migrations.AddField(
model_name='plan',
name='lang',
field=models.ManyToManyField(blank=True, related_name='_plan_lang_+', to='core.Language'),
),
migrations.AddField(
model_name='step',
name='lang',
field=models.ManyToManyField(blank=True, related_name='_step_lang_+', to='core.Language'),
),
migrations.AddField(
model_name='task',
name='lang',
field=models.ManyToManyField(blank=True, related_name='_task_lang_+', to='core.Language'),
),
migrations.AddField(
model_name='work',
name='lang',
field=models.ManyToManyField(blank=True, related_name='_work_lang_+', to='core.Language'),
),
]
20 changes: 20 additions & 0 deletions src/apps/core/migrations/0024_auto_20160117_0139.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-01-17 09:39
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0023_auto_20160115_1150'),
]

operations = [
migrations.AlterField(
model_name='language',
name='language_code',
field=models.CharField(max_length=8),
),
]
13 changes: 12 additions & 1 deletion src/apps/core/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
from django.conf import settings
from django_markdown.models import MarkdownField
from django.db.models.signals import post_save
from django.db.models.signals import post_delete
from hours.models import HourValue
from ..signals import _content_type_post_save
from ..signals import _translation_post_save
from ..signals import _translation_post_delete


class BaseContentModel(models.Model):
Expand Down Expand Up @@ -85,6 +88,12 @@ class BaseContentModel(models.Model):
null=True,
)

lang = models.ManyToManyField(
'Language',
blank=True,
related_name='+',
)

total_donated = models.DecimalField(
default=0.,
decimal_places=8,
Expand Down Expand Up @@ -731,7 +740,7 @@ class Language(models.Model):
http_accept_language = models.CharField(max_length=255, blank=True,
null=True)
omegawiki_language_id = models.PositiveIntegerField(null=True, blank=True)
language_code = models.CharField(max_length=5)
language_code = models.CharField(max_length=8)

def __unicode__(self):
try:
Expand All @@ -746,3 +755,5 @@ def __unicode__(self):
post_save.connect(_content_type_post_save, sender=Step)
post_save.connect(_content_type_post_save, sender=Task)
post_save.connect(_content_type_post_save, sender=Work)
post_save.connect(_translation_post_save, sender=Translation)
post_delete.connect(_translation_post_delete, sender=Translation)
32 changes: 23 additions & 9 deletions src/apps/core/signals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
def _translation_post_save(sender, instance, created, *args, **kwargs):
"""
Do after translation save
"""
# Copy fields to parent content object, if language match
if instance.language == instance.content_object.language:
ignored_fields = ['language', 'language_id', 'id']
for field in instance._meta.get_all_field_names():
if field in instance.content_object._meta.get_all_field_names():
if field in ignored_fields:
continue
if getattr(instance.content_object, field) != getattr(instance, field):
setattr(instance.content_object, field, getattr(instance, field))

# Save the translation language to object itself for faster filtering
instance.content_object.lang.add(instance.language)
instance.content_object.save()

def _translation_post_delete(sender, instance, *args, **kwargs):
# Remove the translation language upon deletion of translation
instance.content_object.lang.remove(instance.language)
instance.content_object.save()

def _content_type_post_save(sender, instance, created, *args, **kwargs):
"""
Create default translation
Expand Down Expand Up @@ -26,12 +49,3 @@ def _content_type_post_save(sender, instance, created, *args, **kwargs):
setattr(translation, field, getattr(instance, field))

translation.save()
else:
translations = Translation.objects.filter(
content_type=content_type, object_id=instance.id
)

if translations.count == 1:
for field in fields:
setattr(translations[0], field, getattr(instance, field))
translations[0].save()
Loading