Skip to content
Snippets Groups Projects
Commit d162ba8c authored by Tomáš Čejka's avatar Tomáš Čejka
Browse files

fixed userprofile access and access to settings variables

In the current django, we need to access Profile of a user by userprofile property instead of method.

To use variables from settings in a template, we must "export" them using SETTINGS_EXPORT.
parent b8d68579
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*- vim:fileencoding=utf-8:
# vim: tabstop=4:shiftwidth=4:softtabstop=4:expandtab
# Copyright (C) 2010-2014 GRNET S.A.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django.conf import settings
def settings_vars(context):
# return the value you want as a dictionary.
# you may add multiple values in there.
return {
'VERSION': settings.SW_VERSION,
'BRANDING': settings.BRANDING,
'INSTALLED_APPS': settings.INSTALLED_APPS,
}
...@@ -275,7 +275,7 @@ class Route(models.Model): ...@@ -275,7 +275,7 @@ class Route(models.Model):
logger.info(mail_body, extra=d) logger.info(mail_body, extra=d)
def commit_edit(self, *args, **kwargs): def commit_edit(self, *args, **kwargs):
peers = self.applier.userprofile().peers.all() peers = self.applier.userprofile.peers.all()
username = None username = None
for peer in peers: for peer in peers:
if username: if username:
...@@ -337,7 +337,7 @@ class Route(models.Model): ...@@ -337,7 +337,7 @@ class Route(models.Model):
if "reason" in kwargs: if "reason" in kwargs:
reason = kwargs['reason'] reason = kwargs['reason']
reason_text = 'Reason: %s.' % reason reason_text = 'Reason: %s.' % reason
peers = self.applier.userprofile().peers.all() peers = self.applier.userprofile.peers.all()
for peer in peers: for peer in peers:
if username: if username:
break break
...@@ -621,7 +621,7 @@ class Route(models.Model): ...@@ -621,7 +621,7 @@ class Route(models.Model):
@property @property
def applier_peers(self): def applier_peers(self):
try: try:
peers = self.applier.userprofile().peers.all() peers = self.applier.userprofile.peers.all()
applier_peers = ''.join(('%s, ' % (peer.peer_name)) for peer in peers)[:-2] applier_peers = ''.join(('%s, ' % (peer.peer_name)) for peer in peers)[:-2]
except: except:
applier_peers = None applier_peers = None
......
...@@ -142,7 +142,7 @@ def lock_history_file(wait=1): ...@@ -142,7 +142,7 @@ def lock_history_file(wait=1):
logger.info("lock_history_file(): creating lock dir succeeded") logger.info("lock_history_file(): creating lock dir succeeded")
success=1 success=1
return success return success
except OSError, e: except OSError as e:
logger.error("lock_history_file(): creating lock dir failed: OSError: "+str(e)) logger.error("lock_history_file(): creating lock dir failed: OSError: "+str(e))
success=0 success=0
except Exception as e: except Exception as e:
......
...@@ -488,5 +488,8 @@ STATISTICS_PER_RULE__ADD_INITIAL_ZERO = True ...@@ -488,5 +488,8 @@ STATISTICS_PER_RULE__ADD_INITIAL_ZERO = True
SETTINGS_EXPORT = [ SETTINGS_EXPORT = [
'BRANDING', 'BRANDING',
'SW_VERSION',
'LANGUAGES',
'LANGUAGE_CODE',
] ]
...@@ -38,16 +38,16 @@ ...@@ -38,16 +38,16 @@
<ul class="nav navbar-top-links navbar-right"> <ul class="nav navbar-top-links navbar-right">
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{% trans "Language" %}: {% for lang in LANGUAGES %}{% ifequal LANGUAGE_CODE lang.0 %}{% trans lang.1 %}{% endifequal %}{% endfor %}<b class="caret"></b></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown">{% trans "Language" %}: {% for lang in settings.LANGUAGES %}{% ifequal settings.LANGUAGE_CODE lang.0 %}{% trans lang.1 %}{% endifequal %}{% endfor %}<b class="caret"></b></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<form action="{% url 'set_language' %}" method="post" style="display:inline;" id="langform"> <form action="{% url 'set_language' %}" method="post" style="display:inline;" id="langform">
{% csrf_token %} {% csrf_token %}
<input name="next" type="hidden" value="{{ next }}" /> <input name="next" type="hidden" value="{{ next }}" />
<input id="langsel" name="language" type="hidden" value="" /> <input id="langsel" name="language" type="hidden" value="" />
</form> </form>
{% for lang in LANGUAGES %} {% for lang in settings.LANGUAGES %}
<li> <li>
<a class="select_lang" href="#" onclick="setlang('{{ lang.0 }}'); return false;" title="{{lang.1}}">{% trans lang.1 %}{% ifequal LANGUAGE_CODE lang.0 %} <i class="icon-ok"></i>{% endifequal %}</a> <a class="select_lang" href="#" onclick="setlang('{{ lang.0 }}'); return false;" title="{{lang.1}}">{% trans lang.1 %}{% ifequal settings.LANGUAGE_CODE lang.0 %} <i class="icon-ok"></i>{% endifequal %}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
<ul class="dropdown-menu dropdown-user" role="menu" > <ul class="dropdown-menu dropdown-user" role="menu" >
<li role="presentation" class="dropdown-header">{{user}}</li> <li role="presentation" class="dropdown-header">{{user}}</li>
<li class="divider"></li> <li class="divider"></li>
{% if user.get_profile.peers.all %} {% if user.userprofile.peers.all %}
<li> <li>
<a href="{% url 'user-profile' %}"><i class="fa fa-user fa-fw"></i>{% trans "My profile" %}</a> <a href="{% url 'user-profile' %}"><i class="fa fa-user fa-fw"></i>{% trans "My profile" %}</a>
</li> </li>
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
<li><a href="{% url 'admin:index' %}"><i class="fa fa-cogs fa-fw"></i> {% trans "Admin" %}</a> <li><a href="{% url 'admin:index' %}"><i class="fa fa-cogs fa-fw"></i> {% trans "Admin" %}</a>
</li> </li>
{% endif %} {% endif %}
{% if user.get_profile.peers.all %} {% if user.userprofile.peers.all %}
<li> <li>
<a href="{% url 'user-profile' %}"><i class="fa fa-user fa-fw"></i> {% trans "My profile" %}</a> <a href="{% url 'user-profile' %}"><i class="fa fa-user fa-fw"></i> {% trans "My profile" %}</a>
</li> </li>
...@@ -137,7 +137,7 @@ ...@@ -137,7 +137,7 @@
</div> </div>
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% block contentplaceholder %} {% block contentplaceholder %}
{% endblock %} {% endblock %}
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
{% if user.is_authenticated %} {% if user.is_authenticated %}
<p>{% trans "If you have any questions or need help, contact GÉANT OC at <a href='mailto:support@oc.geant.net'>support@oc.geant.net</a> or +44 1223 733033." %}</p> <p>{% trans "If you have any questions or need help, contact GÉANT OC at <a href='mailto:support@oc.geant.net'>support@oc.geant.net</a> or +44 1223 733033." %}</p>
{% endif %} {% endif %}
<!--<div style="padding-top: 10px;"><a href="https://code.grnet.gr/projects/flowspy">Version: <strong>{{VERSION}}</strong></a> --> <!--<div style="padding-top: 10px;"><a href="https://code.grnet.gr/projects/flowspy">Version: <strong>{{ settings.SW_VERSION }}</strong></a> -->
<div style="padding-top: 10px;"><a href="https://github.com/GEANT/FOD">Version: <strong>{{VERSION}}</strong></a> - <div style="padding-top: 10px;"><a href="https://github.com/GEANT/FOD">Version: <strong>{{ settings.SW_VERSION }}</strong></a> -
{% trans "Designed and developed in GÉANT4-SGA2 JRA2-T6; Originally designed and developed by GRNET NOC" %} {% trans "Designed and developed in GÉANT4-SGA2 JRA2-T6; Originally designed and developed by GRNET NOC" %}
</a> </a>
</div> </div>
......
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
{% include "poll_message.html" %} {% include "poll_message.html" %}
{% endfor %} {% endfor %}
<input type="hidden" name="hid_mid" id="hid_mid" value=''/> <input type="hidden" name="hid_mid" id="hid_mid" value=''/>
</div> </div>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment