Skip to content

Commit

Permalink
[#473] Again, Merge branch 'develop' into feature/473_gallery_error
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Jul 1, 2014
2 parents 25fc316 + f6d1d85 commit ae14c94
Show file tree
Hide file tree
Showing 21 changed files with 1,245 additions and 812 deletions.
2 changes: 2 additions & 0 deletions akvo/api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .focus_area import FocusAreaResource
from .goal import GoalResource, IATIGoalResource
from .invoice import InvoiceResource
from .keyword import KeywordResource
from .link import LinkResource
from .location import (
IATIProjectLocationResource, OrganisationLocationResource, OrganisationMapLocationResource,
Expand Down Expand Up @@ -44,6 +45,7 @@
'IATIProjectLocationResource',
'IATIProjectResource',
'InvoiceResource',
'KeywordResource',
'LinkResource',
'OrganisationResource',
'OrganisationLocationResource',
Expand Down
18 changes: 18 additions & 0 deletions akvo/api/resources/keyword.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-

# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.


from akvo.rsr.models import Keyword

from .resources import ConditionalFullResource


class KeywordResource(ConditionalFullResource):
class Meta:
allowed_methods = ['get']
queryset = Keyword.objects.all()
resource_name = 'keyword'
fields = ['id', 'label',]
4 changes: 3 additions & 1 deletion akvo/api/resources/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from akvo.api.serializers import IATISerializer

from akvo.rsr.models import (
Project, Benchmarkname, Category, Goal, Partnership, BudgetItem, ProjectLocation, Benchmark
Project, Benchmarkname, Category, Goal, Partnership, BudgetItem, ProjectLocation, Benchmark, Keyword
)
from akvo.utils import RSR_LIMITED_CHANGE

Expand Down Expand Up @@ -105,6 +105,7 @@ def obj_update(self, bundle, skip_errors=False, **kwargs):
ProjectLocation.objects.filter(location_target=bundle.obj).delete()
Partnership.objects.filter(project=bundle.obj).delete()
Benchmark.objects.filter(project=bundle.obj).delete()
Keyword.objects.filter(project=bundle.obj).delete()
bundle.obj.categories.clear()

self.authorized_update_detail(self.get_object_list(bundle.request), bundle)
Expand Down Expand Up @@ -239,6 +240,7 @@ class ProjectResource(ConditionalFullResource):
budget_items = ConditionalFullToManyField('akvo.api.resources.BudgetItemResource', 'budget_items')
categories = ConditionalFullToManyField('akvo.api.resources.CategoryResource', 'categories')
goals = ConditionalFullToManyField('akvo.api.resources.GoalResource', 'goals')
keywords = ConditionalFullToManyField('akvo.api.resources.KeywordResource', 'keywords')
invoices = ConditionalFullToManyField('akvo.api.resources.InvoiceResource', 'invoices')
links = ConditionalFullToManyField('akvo.api.resources.LinkResource', 'links')
locations = ConditionalFullToManyField('akvo.api.resources.ProjectLocationResource', 'locations')
Expand Down
51 changes: 25 additions & 26 deletions akvo/rsr/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,9 @@ def get_readonly_fields(self, request, obj=None):
admin.site.register(get_model('rsr', 'country'), CountryAdmin)


class RSR_LocationFormFormSet(forms.models.BaseInlineFormSet):
def clean(self):
if self.forms:
# keep track of how many non-deleted forms we have and how many primary locations are ticked
form_count = primary_count = 0
for form in self.forms:
if form.is_valid() and not form.cleaned_data.get('DELETE', False):
form_count += 1
try:
primary_count += 1 if form.cleaned_data['primary'] else 0
except:
pass
# if we have any forms left there must be exactly 1 primary location
if form_count > 0 and not primary_count == 1:
self._non_form_errors = ErrorList([
_(u'The project must have exactly one filled in primary location if any locations at all are to be included')
])


class OrganisationLocationInline(admin.StackedInline):
model = get_model('rsr', 'organisationlocation')
extra = 0
formset = RSR_LocationFormFormSet


class InternalOrganisationIDAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -376,13 +356,12 @@ def get_formset(self, request, *args, **kwargs):
class ProjectLocationInline(admin.StackedInline):
model = get_model('rsr', 'projectlocation')
extra = 0
formset = RSR_LocationFormFormSet


class ProjectAdmin(TimestampsAdminDisplayMixin, admin.ModelAdmin):
model = get_model('rsr', 'project')
inlines = (
GoalInline, ProjectLocationInline, BudgetItemAdminInLine, BenchmarkInline, PartnershipInline, LinkInline,
GoalInline, ProjectLocationInline, BudgetItemAdminInLine, BenchmarkInline, PartnershipInline, LinkInline
)
save_as = True

Expand Down Expand Up @@ -441,11 +420,17 @@ class ProjectAdmin(TimestampsAdminDisplayMixin, admin.ModelAdmin):
),
'fields': ('notes',),
}),
(_(u'Keywords'), {
'description': u'<p style="margin-left:0; padding-left:0; margin-top:1em; width:75%%;">%s</p>' % _(
u'Add keywords belonging to your project. These keywords must be existing already in Akvo RSR. If you want to use a keyword that does not exist in the system, please contact support@akvo.org.'
),
'fields': ('keywords',),
}),
)

list_display = ('id', 'title', 'status', 'project_plan_summary', 'latest_update', 'show_current_image', 'is_published',)
filter_horizontal = ('keywords',)
list_display = ('id', 'title', 'status', 'project_plan_summary', 'latest_update', 'show_current_image', 'is_published', 'show_keywords')
search_fields = ('title', 'status', 'project_plan_summary', 'partnerships__internal_id')
list_filter = ('currency', 'status', )
list_filter = ('currency', 'status', 'keywords',)
# created_at and last_modified_at MUST be readonly since they have the auto_now/_add attributes
readonly_fields = ('budget', 'funds', 'funds_needed', 'created_at', 'last_modified_at',)

Expand Down Expand Up @@ -821,8 +806,16 @@ class PartnerSiteAdmin(TimestampsAdminDisplayMixin, admin.ModelAdmin):
dict(fields=('about_box', 'about_image', 'custom_css', 'custom_logo', 'custom_favicon',))),
(u'Languages and translation', dict(fields=('default_language', 'ui_translation', 'google_translation',))),
(u'Social', dict(fields=('twitter_button', 'facebook_button', 'facebook_app_id',))),
(_(u'Projects'), {
'description': u'<p style="margin-left:0; padding-left:0; margin-top:1em; width:75%%;">%s</p>' % _(
u'Choose what projects will be shown on your partnersite. By selecting one or more keywords below, only projects matching that keyword will be shown on the partnersite.'
),
'fields': ('partner_projects', 'keywords'),
}),
)
list_display = '__unicode__', 'full_domain', 'enabled',
filter_horizontal = ('keywords',)
list_display = ('__unicode__', 'full_domain', 'enabled', 'show_keywords')
list_filter = ('enabled', 'keywords')
# created_at and last_modified_at MUST be readonly since they have the auto_now/_add attributes
readonly_fields = ('created_at', 'last_modified_at',)

Expand Down Expand Up @@ -888,3 +881,9 @@ def has_change_permission(self, request, obj=None):
return False

admin.site.register(get_model('rsr', 'partnersite'), PartnerSiteAdmin)

class KeywordAdmin(admin.ModelAdmin):
model = get_model('rsr', 'Keyword')
list_display = ('label',)

admin.site.register(get_model('rsr', 'Keyword'), KeywordAdmin)
Loading

0 comments on commit ae14c94

Please sign in to comment.