Skip to content

Commit

Permalink
[#1897 #1965] Merge branches
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Feb 2, 2016
2 parents 5e721ba + 68dfe3e commit fc0e923
Show file tree
Hide file tree
Showing 18 changed files with 1,214 additions and 642 deletions.
7 changes: 5 additions & 2 deletions akvo/rest/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from .employment import EmploymentSerializer
from .focus_area import FocusAreaSerializer
from .goal import GoalSerializer
from .indicator import IndicatorPeriodSerializer, IndicatorSerializer
from .indicator import (IndicatorSerializer, IndicatorPeriodSerializer,
IndicatorPeriodDataSerializer, IndicatorPeriodDataCommentSerializer)
from .internal_organisation_id import InternalOrganisationIDSerializer
from .invoice import InvoiceSerializer
from .keyword import KeywordSerializer
Expand Down Expand Up @@ -67,8 +68,10 @@
'EmploymentSerializer',
'FocusAreaSerializer',
'GoalSerializer',
'IndicatorPeriodSerializer',
'IndicatorSerializer',
'IndicatorPeriodSerializer',
'IndicatorPeriodDataSerializer',
'IndicatorPeriodDataCommentSerializer',
'InternalOrganisationIDSerializer',
'InvoiceSerializer',
'KeywordSerializer',
Expand Down
19 changes: 18 additions & 1 deletion akvo/rest/serializers/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.


from akvo.rsr.models import IndicatorPeriod, Indicator
from akvo.rsr.models import (Indicator, IndicatorPeriod, IndicatorPeriodData,
IndicatorPeriodDataComment)

from .rsr_serializer import BaseRSRSerializer

class IndicatorPeriodDataCommentSerializer(BaseRSRSerializer):

class Meta:
model = IndicatorPeriodDataComment


class IndicatorPeriodDataSerializer(BaseRSRSerializer):

comments = IndicatorPeriodDataCommentSerializer(many=True, required=False,
allow_add_remove=True)

class Meta:
model = IndicatorPeriodData


class IndicatorPeriodSerializer(BaseRSRSerializer):

data = IndicatorPeriodDataSerializer(many=True, required=False, allow_add_remove=True)

class Meta:
model = IndicatorPeriod

Expand Down
7 changes: 5 additions & 2 deletions akvo/rest/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from .employment import EmploymentViewSet, approve_employment, set_group
from .focus_area import FocusAreaViewSet
from .goal import GoalViewSet
from .indicator import IndicatorViewSet, IndicatorPeriodViewSet
from .indicator import (IndicatorViewSet, IndicatorPeriodViewSet, IndicatorPeriodDataViewSet,
IndicatorPeriodDataCommentViewSet)
from .internal_organisation_id import InternalOrganisationIDViewSet
from .invoice import InvoiceViewSet
from .keyword import KeywordViewSet
Expand Down Expand Up @@ -83,8 +84,10 @@
'EmploymentViewSet',
'FocusAreaViewSet',
'GoalViewSet',
'IndicatorPeriodViewSet',
'IndicatorViewSet',
'IndicatorPeriodViewSet',
'IndicatorPeriodDataViewSet',
'IndicatorPeriodDataCommentViewSet',
'InternalOrganisationIDViewSet',
'invite_user',
'InvoiceViewSet',
Expand Down
21 changes: 20 additions & 1 deletion akvo/rest/views/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.


from akvo.rsr.models import Indicator, IndicatorPeriod
from akvo.rsr.models import (Indicator, IndicatorPeriod, IndicatorPeriodData,
IndicatorPeriodDataComment)

from ..serializers import IndicatorSerializer, IndicatorPeriodSerializer
from ..viewsets import PublicProjectViewSet
Expand All @@ -27,3 +28,21 @@ class IndicatorPeriodViewSet(PublicProjectViewSet):
serializer_class = IndicatorPeriodSerializer
filter_fields = ('indicator', )
project_relation = 'indicator__result__project__'


class IndicatorPeriodDataViewSet(PublicProjectViewSet):
"""
"""
queryset = IndicatorPeriodData.objects.all()
serializer_class = IndicatorPeriodSerializer
filter_fields = ('period', 'user', 'relative_data', 'status', 'update_method')
project_relation = 'period__indicator__result__project__'


class IndicatorPeriodDataCommentViewSet(PublicProjectViewSet):
"""
"""
queryset = IndicatorPeriodDataComment.objects.all()
serializer_class = IndicatorPeriodSerializer
filter_fields = ('data', 'user')
project_relation = 'period__indicator__result__project__'
19 changes: 19 additions & 0 deletions akvo/rsr/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,3 +1244,22 @@ class ValidationSetAdmin(admin.ModelAdmin):
inlines = (ValidationInline, )

admin.site.register(get_model('rsr', 'ProjectEditorValidationSet'), ValidationSetAdmin)


class IndicatorPeriodDataCommentInline(admin.TabularInline):
model = get_model('rsr', 'IndicatorPeriodDataComment')

def get_extra(self, request, obj=None, **kwargs):
if obj:
return 1 if obj.comments.count() == 0 else 0
else:
return 1


class IndicatorPeriodDataAdmin(admin.ModelAdmin):
model = get_model('rsr', 'IndicatorPeriodData')
list_display = ('period', 'user', 'data', 'relative_data', 'status')
readonly_fields = ('created_at', 'last_modified_at')
inlines = (IndicatorPeriodDataCommentInline, )

admin.site.register(get_model('rsr', 'IndicatorPeriodData'), IndicatorPeriodDataAdmin)
62 changes: 62 additions & 0 deletions akvo/rsr/migrations/0050_auto_20160201_1513.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import sorl.thumbnail.fields
import akvo.rsr.fields
from django.conf import settings
import akvo.rsr.models.indicator


class Migration(migrations.Migration):

dependencies = [
('rsr', '0049_auto_20160128_1605'),
]

operations = [
migrations.CreateModel(
name='IndicatorPeriodData',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created_at', models.DateTimeField(db_index=True, auto_now_add=True, null=True)),
('last_modified_at', models.DateTimeField(db_index=True, auto_now=True, null=True)),
('relative_data', models.BooleanField(default=False, verbose_name='relative data')),
('data', akvo.rsr.fields.ValidXMLCharField(max_length=300, verbose_name='data')),
('status', akvo.rsr.fields.ValidXMLCharField(default=b'D', choices=[(b'D', 'draft'), (b'P', 'pending approval'), (b'R', 'return for revision'), (b'A', 'approved')], max_length=1, blank=True, verbose_name='status', db_index=True)),
('text', akvo.rsr.fields.ValidXMLTextField(verbose_name='text', blank=True)),
('photo', sorl.thumbnail.fields.ImageField(upload_to=akvo.rsr.models.indicator.image_path, verbose_name='photo', blank=True)),
('file', models.FileField(upload_to=akvo.rsr.models.indicator.file_path, verbose_name='file', blank=True)),
('update_method', akvo.rsr.fields.ValidXMLCharField(default=b'W', choices=[(b'W', 'web'), (b'M', 'mobile')], max_length=1, blank=True, verbose_name='update method', db_index=True)),
('period', models.ForeignKey(related_name='data', verbose_name='indicator period', to='rsr.IndicatorPeriod')),
('user', models.ForeignKey(verbose_name='user', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'indicator period data',
'verbose_name_plural': 'indicator period data',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='IndicatorPeriodDataComment',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created_at', models.DateTimeField(db_index=True, auto_now_add=True, null=True)),
('last_modified_at', models.DateTimeField(db_index=True, auto_now=True, null=True)),
('comment', akvo.rsr.fields.ValidXMLTextField(verbose_name='comment', blank=True)),
('data', models.ForeignKey(related_name='comments', verbose_name='indicator period data', to='rsr.IndicatorPeriodData')),
('user', models.ForeignKey(verbose_name='user', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'indicator period data comment',
'verbose_name_plural': 'indicator period data comments',
},
bases=(models.Model,),
),
migrations.AddField(
model_name='indicatorperiod',
name='locked',
field=models.BooleanField(default=True, db_index=True, verbose_name='locked'),
preserve_default=True,
),
]
43 changes: 43 additions & 0 deletions akvo/rsr/migrations/0051_auto_20160201_1534.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


def move_indicator_period_data(apps, schema_editor):
"""
Move the indicator period data from the ProjectUpdate model to the IndicatorPeriodData model
and delete the old indicator 'updates'.
"""
ProjectUpdate = apps.get_model('rsr', 'ProjectUpdate')
IndicatorPeriodData = apps.get_model('rsr', 'IndicatorPeriodData')

indicator_updates = ProjectUpdate.objects.exclude(indicator_period=None)
for update in indicator_updates:
# Create new indicater period data object
IndicatorPeriodData.objects.create(
period=update.indicator_period,
user=update.user,
relative_data=True,
data=str(update.period_update),
text=update.text,
photo=update.photo,
update_method=update.update_method,
created_at=update.created_at,
last_modified_at=update.last_modified_at,
)
# Delete all (old) indicator 'updates'
indicator_updates.delete()


class Migration(migrations.Migration):

dependencies = [
('rsr', '0050_auto_20160201_1513'),
]

operations = [
migrations.RunPython(
move_indicator_period_data
),
]
22 changes: 22 additions & 0 deletions akvo/rsr/migrations/0052_auto_20160201_1556.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('rsr', '0051_auto_20160201_1534'),
]

operations = [
migrations.RemoveField(
model_name='projectupdate',
name='indicator_period',
),
migrations.RemoveField(
model_name='projectupdate',
name='period_update',
),
]
4 changes: 3 additions & 1 deletion akvo/rsr/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from .iati_import import IatiImport
from .iati_import_job import IatiImportJob, CordaidZipIatiImportJob
from .iati_import_log import IatiImportLog
from .indicator import Indicator, IndicatorPeriod
from .indicator import Indicator, IndicatorPeriod, IndicatorPeriodData, IndicatorPeriodDataComment
from .invoice import Invoice
from .internal_organisation_id import InternalOrganisationID
from .keyword import Keyword
Expand Down Expand Up @@ -91,6 +91,8 @@
'IatiImportLog',
'Indicator',
'IndicatorPeriod',
'IndicatorPeriodData',
'IndicatorPeriodDataComment',
'Invoice',
'InternalOrganisationID',
'Keyword',
Expand Down
Loading

0 comments on commit fc0e923

Please sign in to comment.