Commit 4bcec8a8 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis Committed by Christos Stavrakakis
Browse files

astakos: Replace str with unicode

Define __unicode__ in astakos models rather than __str__.
parent c73be1df
......@@ -120,7 +120,7 @@ def commissions(request):
@api.api_method(http_method='GET', token_required=True, user_required=False)
@component_from_token
def get_pending_commissions(request):
client_key = str(request.component_instance)
client_key = unicode(request.component_instance)
result = qh.get_pending_commissions(clientkey=client_key)
return json_response(result)
......@@ -139,7 +139,7 @@ def _provisions_to_list(provisions):
if not is_integer(quantity):
raise ValueError()
except (TypeError, KeyError, ValueError):
raise BadRequest("Malformed provision %s" % str(provision))
raise BadRequest("Malformed provision %s" % unicode(provision))
return lst
......@@ -153,7 +153,7 @@ def issue_commission(request):
except json.JSONDecodeError:
raise BadRequest("POST data should be in json format.")
client_key = str(request.component_instance)
client_key = unicode(request.component_instance)
provisions = input_data.get('provisions')
if provisions is None:
raise BadRequest("Provisions are missing.")
......@@ -243,7 +243,7 @@ def resolve_pending_commissions(request):
except json.JSONDecodeError:
raise BadRequest("POST data should be in json format.")
client_key = str(request.component_instance)
client_key = unicode(request.component_instance)
accept = input_data.get('accept', [])
reject = input_data.get('reject', [])
......@@ -273,7 +273,7 @@ def resolve_pending_commissions(request):
@component_from_token
def get_commission(request, serial):
data = request.GET
client_key = str(request.component_instance)
client_key = unicode(request.component_instance)
try:
serial = int(serial)
except ValueError:
......@@ -304,7 +304,7 @@ def serial_action(request, serial):
except ValueError:
raise BadRequest("Serial should be an integer.")
client_key = str(request.component_instance)
client_key = unicode(request.component_instance)
accept = 'accept' in input_data
reject = 'reject' in input_data
......
......@@ -251,7 +251,7 @@ class ActivationBackend(object):
user.moderated_at = datetime.datetime.now()
user.moderated_data = json.dumps(user.__dict__,
default=lambda obj:
str(obj))
unicode(obj))
user.save()
functions.enable_base_project(user)
......@@ -323,7 +323,7 @@ class ActivationBackend(object):
user.moderated_at = datetime.datetime.now()
user.moderated_data = json.dumps(user.__dict__,
default=lambda obj:
str(obj))
unicode(obj))
user.is_rejected = True
user.rejected_reason = reason
user.save()
......
......@@ -748,7 +748,7 @@ def modify_project(project_id, request):
main_fields = modifies_main_fields(request)
if main_fields:
m = (_(astakos_messages.BASE_NO_MODIFY_FIELDS)
% ", ".join(map(str, main_fields)))
% ", ".join(map(unicode, main_fields)))
raise ProjectBadRequest(m)
new_name = request.get("realname")
......@@ -765,7 +765,7 @@ def modify_projects_in_bulk(flt, request):
main_fields = modifies_main_fields(request)
if main_fields:
raise ProjectBadRequest("Cannot modify field(s) '%s' in bulk" %
", ".join(map(str, main_fields)))
", ".join(map(unicode, main_fields)))
projects = Project.objects.initialized(flt).select_for_update()
_modify_projects(projects, request)
......
......@@ -64,7 +64,6 @@ from astakos.im import auth_providers as auth
import astakos.im.messages as astakos_messages
from synnefo.lib.ordereddict import OrderedDict
from synnefo.util.text import uenc, udec
from synnefo.util import units
from astakos.im import presentation
......@@ -149,7 +148,7 @@ class Component(models.Model):
msg = 'Token renewed for component %s'
logger.log(astakos_settings.LOGGING_LEVEL, msg, self.name)
def __str__(self):
def __unicode__(self):
return self.name
@classmethod
......@@ -237,11 +236,11 @@ class Resource(models.Model):
ui_visible = models.BooleanField(default=True)
api_visible = models.BooleanField(default=True)
def __str__(self):
def __unicode__(self):
return self.name
def full_name(self):
return str(self)
return unicode(self)
def get_info(self):
return {'service': self.service_origin,
......@@ -254,34 +253,35 @@ class Resource(models.Model):
@property
def group(self):
default = self.name
return get_presentation(str(self)).get('group', default)
return get_presentation(unicode(self)).get('group', default)
@property
def help_text(self):
default = "%s resource" % self.name
return get_presentation(str(self)).get('help_text', default)
return get_presentation(unicode(self)).get('help_text', default)
@property
def help_text_input_each(self):
default = "%s resource" % self.name
return get_presentation(str(self)).get('help_text_input_each', default)
return get_presentation(unicode(self)).get(
'help_text_input_each', default)
@property
def is_abbreviation(self):
return get_presentation(str(self)).get('is_abbreviation', False)
return get_presentation(unicode(self)).get('is_abbreviation', False)
@property
def report_desc(self):
default = "%s resource" % self.name
return get_presentation(str(self)).get('report_desc', default)
return get_presentation(unicode(self)).get('report_desc', default)
@property
def placeholder(self):
return get_presentation(str(self)).get('placeholder', self.unit)
return get_presentation(unicode(self)).get('placeholder', self.unit)
@property
def verbose_name(self):
return get_presentation(str(self)).get('verbose_name', self.name)
return get_presentation(unicode(self)).get('verbose_name', self.name)
@property
def display_name(self):
......@@ -1262,7 +1262,7 @@ class UserSetting(models.Model):
class Chain(models.Model):
chain = models.AutoField(primary_key=True)
def __str__(self):
def __unicode__(self):
return "%s" % (self.chain,)
......@@ -1372,7 +1372,7 @@ class ProjectApplication(models.Model):
@property
def resource_policies(self):
return [str(rp) for rp in self.projectresourcegrant_set.all()]
return [unicode(rp) for rp in self.projectresourcegrant_set.all()]
def is_modification(self):
# if self.state != self.PENDING:
......@@ -1519,7 +1519,7 @@ class ProjectResourceGrant(models.Model):
return sign + unicode(units.show(v, unit))
return map(disp, [proj_abs, member_abs])
def __str__(self):
def __unicode__(self):
return 'Max %s per user: %s' % (self.resource.pluralized_display_name,
self.display_member_capacity())
......@@ -1627,12 +1627,6 @@ class Project(models.Model):
objects = ProjectManager()
def __str__(self):
return uenc(_("<project %s '%s'>") %
(self.id, udec(self.realname)))
__repr__ = __str__
def __unicode__(self):
return _("<project %s '%s'>") % (self.id, self.realname)
......@@ -1708,8 +1702,8 @@ class Project(models.Model):
return self.O_STATE_DISPLAY.get(self.overall_state(), _('Unknown'))
def expiration_info(self):
return (str(self.id), self.name, self.state_display(),
str(self.end_date))
return (unicode(self.id), self.name, self.state_display(),
unicode(self.end_date))
def last_deactivation(self):
objs = self.log.filter(to_state__in=self.DEACTIVATED_STATES)
......@@ -1997,11 +1991,9 @@ class ProjectMembership(models.Model):
unique_together = ("person", "project")
#index_together = [["project", "state"]]
def __str__(self):
return uenc(_("<'%s' membership in '%s'>") %
(self.person.username, self.project))
__repr__ = __str__
def __unicode__(self):
return (_("<'%s' membership in '%s'>") %
(self.person.username, self.project))
def latest_log(self):
logs = self.log.all()
......
......@@ -160,7 +160,7 @@ def issue_commission(clientkey, provisions, name="", force=False):
try:
th = holdings[key]
except KeyError:
m = ("There is no such holding %s" % str(key))
m = ("There is no such holding %s" % unicode(key))
provision = _mkProvision(key, quantity)
raise NoHoldingError(m,
provision=provision)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment