Skip to content

Commit

Permalink
[#1618] Merge 'develop' into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Jun 22, 2015
2 parents b4fc345 + 7a4156a commit 0a2106a
Show file tree
Hide file tree
Showing 22 changed files with 390 additions and 57 deletions.
26 changes: 15 additions & 11 deletions akvo/rsr/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,31 +1035,33 @@ class PaymentGatewaySelectorAdmin(admin.ModelAdmin):


class PartnerSiteAdmin(TimestampsAdminDisplayMixin, admin.ModelAdmin):

"""Defines the RSR Pages admin."""

fieldsets = (
(u'General', dict(fields=('organisation', 'enabled',))),
(u'HTTP', dict(fields=('hostname', 'cname', 'custom_return_url', 'custom_return_url_text',
'piwik_id',))),
(u'Style and content',
dict(fields=('all_maps', 'about_box', 'about_image', 'custom_css', 'custom_logo',
'custom_favicon',))),
(u'Languages and translation', dict(fields=('default_language', 'ui_translation',
'google_translation',))),
(u'Languages and translation', dict(fields=('google_translation',))),
(u'Social', dict(fields=('twitter_button', 'facebook_button', 'facebook_app_id',))),
(_(u'Project selection'), {
'description': u'{}'.format(
u'<p style="margin-left:0; padding-left:0; margin-top:1em; width:75%%;">'
u'Select the projects to be shown on your Site.'
u'</p>'
u'<p style="margin-left:0; padding-left:0; margin-top:1em; width:75%%;">'
u'The default setting selects all projects associated with the organisation of the Site. '
u'</p>'
u'The default setting selects all projects associated with the organisation of '
u'the Site.</p>'
u'<p style="margin-left:0; padding-left:0; margin-top:1em; width:75%%;">'
u'De-selecting the "Show only projects of partner" check-box shows all projects in RSR. '
u'This is meant to be used with the keywords below, '
u'De-selecting the "Show only projects of partner" check-box shows all projects '
u'in RSR. This is meant to be used with the keywords below, '
u'thus selecting only projects associated with the selected keywords. '
u'<br/>If keywords are added to a Site showing only projects of a partner, '
u'the selection will be further filtered by only showing associated projects with those keywords.'
u'</p>'
u'the selection will be further filtered by only showing associated projects '
u'with those keywords.</p>'
u'<p style="margin-left:0; padding-left:0; margin-top:1em; width:75%%;">'
u'When "Exclude projects with selected keyword is checked" '
u'projects with the chosen keywords are instead excluded from the list.'
Expand All @@ -1075,9 +1077,11 @@ class PartnerSiteAdmin(TimestampsAdminDisplayMixin, admin.ModelAdmin):
readonly_fields = ('created_at', 'last_modified_at',)

def get_fieldsets(self, request, obj=None):
# don't show the notes field unless you are superuser or admin
"""Don't show the notes field unless you are superuser or admin.
# note that this is somewhat fragile as it relies on adding/removing from the _first_
# fieldset
"""
if request.user.is_superuser or request.user.is_admin:
self.fieldsets[0][1]['fields'] = ('organisation', 'enabled', 'notes',)
else:
Expand All @@ -1091,7 +1095,7 @@ def get_form(self, request, obj=None, **kwargs):
)

def get_list_display(self, request):
# see the notes fields in the change list if you are superuser or admin
""""See the notes fields in the change list if you are superuser or admin."""
if request.user.is_superuser or request.user.is_admin:
return list(self.list_display) + ['notes']
return super(PartnerSiteAdmin, self).get_list_display(request)
Expand All @@ -1116,7 +1120,7 @@ def get_queryset(self, request):

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

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

Expand Down
56 changes: 56 additions & 0 deletions akvo/rsr/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
from django.conf import settings
from django.core.exceptions import DisallowedHost
from django.db.models import Q
from django.core.urlresolvers import (is_valid_path, get_resolver, LocaleRegexURLResolver)
from django.shortcuts import redirect
from akvo.rsr.context_processors import extra_context
from akvo.rsr.models import PartnerSite
from django.utils import translation
from django.http import HttpResponseRedirect


def _is_rsr_host(hostname):
Expand All @@ -36,6 +39,59 @@ def _partner_site(netloc):
)


class DefaultLanguageMiddleware(object):

"""A non working (BROKEN) default language middleware.
A try in supporting default languages, but since this will redirect all url_patterns and
not only i18n ones it's broken.
"""

def __init__(self):
"""."""
self._is_language_prefix_patterns_used = False
for url_pattern in get_resolver(None).url_patterns:
if isinstance(url_pattern, LocaleRegexURLResolver):
self._is_language_prefix_patterns_used = True
break

def is_language_prefix_patterns_used(self):
"""."""
return self._is_language_prefix_patterns_used

def is_i18n_path(self, path):
"""."""
from akvo.urls import localised_patterns
print "=> {}".format(localised_patterns)
from django.core.urlresolvers import resolve, Resolver404
try:
resolve(path, localised_patterns)
return True
except Resolver404:
return False
except TypeError, e:
return False
return False

def process_request(self, request):
"""Redirect to selected language."""
if not request.rsr_page:
return None

if self.is_i18n_path(request.path):
print "{} was i18n path".format(request.path)
else:
print "{} was not 18n path".format(request.path)

language_from_path = translation.get_language_from_path(request.path_info)
if not language_from_path:
if request.rsr_page.default_language:
lang = request.rsr_page.default_language
return HttpResponseRedirect('/{}{}'.format(lang, request.path))
return HttpResponseRedirect('/en{}'.format(request.path))
return None


class HostDispatchMiddleware(object):

"""Simple test for middleware testing."""
Expand Down
23 changes: 23 additions & 0 deletions akvo/rsr/migrations/0010_auto_20150615_1149.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import sorl.thumbnail.fields
import akvo.rsr.models.keyword
import akvo.rsr.fields


class Migration(migrations.Migration):

dependencies = [
('rsr', '0009_auto_20150528_1413'),
]

operations = [
migrations.AddField(
model_name='keyword',
name='logo',
field=sorl.thumbnail.fields.ImageField(help_text='Add your keyword logo here. You can only add one logo. The logo will be shown on the project page, but not on Akvo Pages.<br/>The logo should be about 1 MB in size, and should preferably be 75x75 pixels and in PNG or JPG format.', upload_to=akvo.rsr.models.keyword.logo_path, verbose_name='logo', blank=True),
preserve_default=True,
),
]
14 changes: 14 additions & 0 deletions akvo/rsr/models/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,29 @@
# 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.utils import rsr_image_path

from django.db import models
from django.utils.translation import ugettext_lazy as _

from sorl.thumbnail.fields import ImageField

from ..fields import ValidXMLCharField


def logo_path(instance, file_name):
return rsr_image_path(instance, file_name, 'db/keyword/%(instance_pk)s/%(file_name)s')


class Keyword(models.Model):
label = ValidXMLCharField(_(u'label'), max_length=30, unique=True, db_index=True)
logo = ImageField(
_('logo'), blank=True, upload_to=logo_path,
help_text=_(u'Add your keyword logo here. You can only add one logo. '
u'The logo will be shown on the project page, but not on Akvo Pages.<br/>'
u'The logo should be about 1 MB in size, and should preferably be 75x75 '
u'pixels and in PNG or JPG format.'),
)

def __unicode__(self):
return self.label
Expand Down
4 changes: 4 additions & 0 deletions akvo/rsr/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,10 @@ def has_indicators(self):
def check_mandatory_fields(self, version='2.01'):
return check_export_fields(self, version)

def keyword_logos(self):
"""Return the keywords of the project which have a logo."""
return self.keywords.exclude(logo='')

class Meta:
app_label = 'rsr'
verbose_name = _(u'project')
Expand Down
49 changes: 48 additions & 1 deletion akvo/rsr/static/styles-src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ nav.navbar-fixed-top {
background: rgba(32, 32, 36, 0.1) !important; }
.myProjectList tbody tr.isPublished {
background: white !important; }
@media only screen and (min-width: 1200px) {
.myProjectList div.twoColumns.clearfix {
min-width: 170px; } }
.myProjectList div.twoColumns.clearfix > a {
min-width: 70px; }

div.paginationWrap {
clear: both; }

#profile .usrAvatar {
background-color: rgba(32, 32, 36, 0);
Expand Down Expand Up @@ -1489,6 +1497,10 @@ div.textBlock {
margin-bottom: 1em; } }

/* Financial details page */
section.projectFinancial .currentFunders dl > dd {
text-align: right; }
section.projectFinancial .donationBreak {
display: none; }
@media only screen and (max-width: 768px) {
section.projectFinancial {
width: 95%;
Expand All @@ -1500,7 +1512,14 @@ div.textBlock {
@media only screen and (max-width: 992px) {
@media only screen and (min-width: 768px) {
section.projectFinancial .dl-horizontal dt {
width: initial; } } }
width: initial; }
section.projectFinancial .donationBreak {
display: initial;
clear: both; }
section.projectFinancial .currentFunders dd.donation {
float: right; }
section.projectFinancial .currentFunders dt.donation {
clear: both; } } }

/* Project Partners details page */
section.projectPartners .title {
Expand Down Expand Up @@ -1556,6 +1575,34 @@ section.projectPartners .row {
dd.currencyAmount {
margin-left: auto; }

/* Project report page */
@media only screen and (max-width: 768px) {
.projectReport {
max-width: 95%;
margin-left: auto;
margin-right: auto; } }
@media only screen and (min-width: 992px) {
.projectReport table {
table-layout: fixed; }
.projectReport table th {
word-break: break-word; }
@media only screen and (max-width: 1200px) {
.projectReport table th {
width: 90px; } }
@media only screen and (min-width: 1200px) {
.projectReport table th {
width: 120px; } } }

/* Project update page */
.updateText {
white-space: pre-line; }

/* Google translation bar styles */
body.translationBarActive .nav {
padding-top: 39px; }
body.translationBarActive .navbar-brand {
margin-top: 39px; }

/* Cookie */
#cookie-law {
position: fixed;
Expand Down
Loading

0 comments on commit 0a2106a

Please sign in to comment.