From: Diane Trout Date: Tue, 3 Feb 2015 00:24:18 +0000 (-0800) Subject: convert to unicode_literals X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=d51adc01f5e4ff7eb7e3846db06afd7043fa5a71 convert to unicode_literals convert all the string handling to unicode. to make the RDF stuff work I needed to mark those strings as byte arrays --- diff --git a/bcmagic/admin.py b/bcmagic/admin.py index bb1d1d0..a70dad8 100644 --- a/bcmagic/admin.py +++ b/bcmagic/admin.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.contrib import admin from .models import KeywordMap, Printer diff --git a/bcmagic/forms.py b/bcmagic/forms.py index 000acd9..c80a44f 100644 --- a/bcmagic/forms.py +++ b/bcmagic/forms.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django import forms class BarcodeMagicForm(forms.Form): diff --git a/bcmagic/models.py b/bcmagic/models.py index 4db58a3..c91905b 100644 --- a/bcmagic/models.py +++ b/bcmagic/models.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.db import models #FIXME: Should be made more generic and probably pre-populated supported list @@ -27,5 +29,5 @@ class Printer(models.Model): label_height = models.FloatField(help_text='height in inches') notes = models.TextField() - def __unicode__(self): - return u'%s, %s, %s, %s, %sx%s' % (self.name, self.model, self.ip_address, self.label_shape, self.label_width, self.label_width) \ No newline at end of file + def __str__(self): + return '%s, %s, %s, %s, %sx%s' % (self.name, self.model, self.ip_address, self.label_shape, self.label_width, self.label_width) diff --git a/bcmagic/plugin.py b/bcmagic/plugin.py index 12de8d2..09a1f8a 100644 --- a/bcmagic/plugin.py +++ b/bcmagic/plugin.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + BCM_PLUGINS = { #'cmd_move_sample': bcm_cmds.cmd_move_sample } diff --git a/bcmagic/urls.py b/bcmagic/urls.py index 9133391..478e3c8 100644 --- a/bcmagic/urls.py +++ b/bcmagic/urls.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.conf.urls import patterns urlpatterns = patterns('', diff --git a/bcmagic/utils.py b/bcmagic/utils.py index 9374e4a..a798200 100644 --- a/bcmagic/utils.py +++ b/bcmagic/utils.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.conf import settings import ftplib diff --git a/bcmagic/views.py b/bcmagic/views.py index 3d9206f..4efbcaa 100644 --- a/bcmagic/views.py +++ b/bcmagic/views.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.http import HttpResponse from django.template import RequestContext, Template, Context from django.shortcuts import render_to_response diff --git a/eland_config/admin.py b/eland_config/admin.py index 56107ff..895ecb1 100644 --- a/eland_config/admin.py +++ b/eland_config/admin.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.contrib import admin from django.utils.translation import ugettext_lazy as _ diff --git a/eland_config/forms.py b/eland_config/forms.py index a2245f9..c24bb62 100644 --- a/eland_config/forms.py +++ b/eland_config/forms.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django import forms from django.forms.util import ErrorList diff --git a/eland_config/models.py b/eland_config/models.py index 71a8362..bd4b2ab 100644 --- a/eland_config/models.py +++ b/eland_config/models.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.db import models # Create your models here. diff --git a/eland_config/urls.py b/eland_config/urls.py index eff1477..38a2cc3 100644 --- a/eland_config/urls.py +++ b/eland_config/urls.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.conf.urls import patterns, url urlpatterns = patterns('', diff --git a/eland_config/views.py b/eland_config/views.py index f4d765e..db30741 100644 --- a/eland_config/views.py +++ b/eland_config/views.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals from django.conf import settings from django.http import HttpResponse diff --git a/experiments/admin.py b/experiments/admin.py index 4ae0060..b8fff8a 100644 --- a/experiments/admin.py +++ b/experiments/admin.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals from itertools import chain @@ -185,8 +185,8 @@ class SequencerSelect(Select): def render_option(self, selected_choices, option_value, option_label): - disabled_sequencers = [ unicode(s.id) for s in self.queryset.filter(active=False) ] - option_value = unicode(option_value) + disabled_sequencers = [ str(s.id) for s in self.queryset.filter(active=False) ] + option_value = str(option_value) selected_html = (option_value in selected_choices) and u' selected="selected"' or '' cssclass = "strikeout" if option_value in disabled_sequencers else '' return u'' % ( diff --git a/experiments/experiments.py b/experiments/experiments.py index 8738224..e9d12de 100644 --- a/experiments/experiments.py +++ b/experiments/experiments.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals # some core functions of the exp tracker module from datetime import datetime, timedelta @@ -43,7 +43,7 @@ def flowcell_information(flowcell_id): 'library_name': lane.library.library_name, 'library_id': lane.library.id, 'library_species': lane.library.library_species.scientific_name, - 'pM': unicode(lane.pM), + 'pM': str(lane.pM), 'read_length': lane.flowcell.read_length, 'status_code': lane.status, 'status': LANE_STATUS_MAP[lane.status] diff --git a/experiments/experiments_factory.py b/experiments/experiments_factory.py index 1e344b3..34e9d5f 100644 --- a/experiments/experiments_factory.py +++ b/experiments/experiments_factory.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import datetime import factory diff --git a/experiments/models.py b/experiments/models.py index 3377e28..6e1fe27 100644 --- a/experiments/models.py +++ b/experiments/models.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals import datetime import glob @@ -58,8 +58,8 @@ class ClusterStation(models.Model): class Meta: ordering = ["-isdefault", "name"] - def __unicode__(self): - return unicode(self.name) + def __str__(self): + return str(self.name) @staticmethod def update_isdefault(sender, instance, **kwargs): @@ -96,10 +96,10 @@ class Sequencer(models.Model): class Meta: ordering = ["-isdefault", "-active", "name"] - def __unicode__(self): - name = [unicode(self.name)] + def __str__(self): + name = [str(self.name)] if self.instrument_name is not None: - name.append("(%s)" % (unicode(self.instrument_name),)) + name.append("(%s)" % (str(self.instrument_name),)) return " ".join(name) @models.permalink @@ -152,8 +152,8 @@ class FlowCell(models.Model): notes = models.TextField(blank=True) - def __unicode__(self): - return unicode(self.flowcell_id) + def __str__(self): + return str(self.flowcell_id) def Lanes(self): html = [''] @@ -187,9 +187,9 @@ class FlowCell(models.Model): """Convert our boolean 'is paired' flag to a name """ if self.paired_end: - return u"Paired" + return "Paired" else: - return u"Single" + return "Single" @models.permalink def get_absolute_url(self): @@ -309,8 +309,8 @@ class Lane(models.Model): return ('experiments.views.flowcell_lane_detail', [str(self.id)]) - def __unicode__(self): - return self.flowcell.flowcell_id + ':' + unicode(self.lane_number) + def __str__(self): + return self.flowcell.flowcell_id + ':' + str(self.lane_number) class DataRun(models.Model): @@ -423,8 +423,8 @@ class FileType(models.Model): return self.name.replace(' ', '_').lower() normalized_name = property(_get_normalized_name) - def __unicode__(self): - #return u"" % (self.name,) + def __str__(self): + #return "" % (self.name,) return self.name diff --git a/experiments/test/test_cluster_station.py b/experiments/test/test_cluster_station.py index 965faa9..9bd5319 100644 --- a/experiments/test/test_cluster_station.py +++ b/experiments/test/test_cluster_station.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals from django.test import TestCase from ..models import ClusterStation, cluster_station_default diff --git a/experiments/test/test_filetype.py b/experiments/test/test_filetype.py index fdef8bf..cb89087 100644 --- a/experiments/test/test_filetype.py +++ b/experiments/test/test_filetype.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals from django.test import TestCase @@ -9,8 +9,8 @@ class TestFileType(TestCase): file_type_objects = FileType.objects name = 'QSEQ tarfile' file_type_object = file_type_objects.get(name=name) - self.assertEqual(u"QSEQ tarfile", - unicode(file_type_object)) + self.assertEqual("QSEQ tarfile", + str(file_type_object)) def test_find_file_type(self): file_type_objects = FileType.objects diff --git a/experiments/test/test_sequencer.py b/experiments/test/test_sequencer.py index 0de4f5a..c3d4a32 100644 --- a/experiments/test/test_sequencer.py +++ b/experiments/test/test_sequencer.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals from django.test import TestCase from ..models import Sequencer, sequencer_default diff --git a/experiments/test_experiments.py b/experiments/test_experiments.py index 7c5d201..99079f3 100644 --- a/experiments/test_experiments.py +++ b/experiments/test_experiments.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals import re from lxml.html import fromstring diff --git a/experiments/urls.py b/experiments/urls.py index 8330d91..0b1722e 100644 --- a/experiments/urls.py +++ b/experiments/urls.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.conf.urls import patterns urlpatterns = patterns('', diff --git a/experiments/views.py b/experiments/views.py index 294aff2..e5f675d 100644 --- a/experiments/views.py +++ b/experiments/views.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals # Create your views here. from datetime import datetime diff --git a/htsworkflow/pipelines/bustard.py b/htsworkflow/pipelines/bustard.py index 68ecc75..e56659f 100644 --- a/htsworkflow/pipelines/bustard.py +++ b/htsworkflow/pipelines/bustard.py @@ -4,7 +4,7 @@ Extract configuration from Illumina Bustard Directory. This includes the version number, run date, bustard executable parameters, and phasing estimates. """ -from __future__ import print_function +from __future__ import print_function, unicode_literals from copy import copy from datetime import date @@ -113,7 +113,7 @@ class CrosstalkMatrix(object): for b in base_order: for value in self.base[b]: crosstalk_value = ElementTree.SubElement(root, CrosstalkMatrix.ELEMENT) - crosstalk_value.text = unicode(value) + crosstalk_value.text = str(value) crosstalk_value.tail = os.linesep return root @@ -458,7 +458,7 @@ def main(cmdline): opts, args = parser.parse_args(cmdline) for bustard_dir in args: - print(u'analyzing bustard directory: ' + unicode(bustard_dir)) + print(u'analyzing bustard directory: ' + str(bustard_dir)) bustard_object = bustard(bustard_dir) bustard_object.dump() diff --git a/htsworkflow/pipelines/gerald.py b/htsworkflow/pipelines/gerald.py index b795b14..e69a330 100644 --- a/htsworkflow/pipelines/gerald.py +++ b/htsworkflow/pipelines/gerald.py @@ -1,6 +1,6 @@ """Provide access to information stored in the GERALD directory. """ -from __future__ import print_function +from __future__ import print_function, unicode_literals import collections from datetime import datetime, date @@ -72,7 +72,7 @@ class Alignment(object): return None gerald = ElementTree.Element(root_tag, - {'version': unicode(Gerald.XML_VERSION)}) + {'version': str(Gerald.XML_VERSION)}) gerald.append(self.tree) gerald.append(self.summary.get_elements()) if self.eland_results: diff --git a/htsworkflow/pipelines/summary.py b/htsworkflow/pipelines/summary.py index 8f454e6..d7081ec 100644 --- a/htsworkflow/pipelines/summary.py +++ b/htsworkflow/pipelines/summary.py @@ -1,7 +1,7 @@ """ Analyze the Summary.htm file produced by GERALD """ -from __future__ import print_function +from __future__ import print_function, unicode_literals import os import logging @@ -42,7 +42,7 @@ class Summary(object): def get_elements(self): summary = etree.Element(Summary.SUMMARY, - {'version': unicode(Summary.XML_VERSION)}) + {'version': str(Summary.XML_VERSION)}) for end in self.lane_results: for lane in end.values(): summary.append(lane.get_elements()) @@ -282,7 +282,7 @@ class LaneResultSummary(object): def get_elements(self): lane_result = etree.Element( LaneResultSummary.LANE_RESULT_SUMMARY, - {'lane': unicode(self.lane), 'end': unicode(self.end)}) + {'lane': str(self.lane), 'end': str(self.end)}) for tag, variable_name in LaneResultSummary.TAGS.items(): value = getattr(self, variable_name) if value is None: @@ -296,7 +296,7 @@ class LaneResultSummary(object): ) else: element = etree.SubElement(lane_result, tag) - element.text = unicode(value) + element.text = str(value) return lane_result def set_elements(self, tree): diff --git a/htsworkflow/util/conversion.py b/htsworkflow/util/conversion.py index d3eb4f6..f294e6f 100644 --- a/htsworkflow/util/conversion.py +++ b/htsworkflow/util/conversion.py @@ -1,15 +1,16 @@ """ Miscellaneous, more refined type casting functions """ +from __future__ import unicode_literals -def unicode_or_none(value): +def str_or_none(value): """ - Convert value to unicode if its not none. + Convert value to unicode string if its not none. """ if value is None: return None else: - return unicode(value) + return str(value) def parse_flowcell_id(flowcell_id): """ diff --git a/htsworkflow/util/rdfhelp.py b/htsworkflow/util/rdfhelp.py index 89db483..33197dd 100644 --- a/htsworkflow/util/rdfhelp.py +++ b/htsworkflow/util/rdfhelp.py @@ -295,7 +295,7 @@ def load_string_into_model(model, parser_name, data, ns=None): ns = fixup_namespace(ns) logger.debug("load_string_into_model parser={0}, len={1}".format( parser_name, len(data))) - rdf_parser = RDF.Parser(name=parser_name) + rdf_parser = RDF.Parser(name=str(parser_name)) for s in rdf_parser.parse_string_as_stream(data, ns): conditionally_add_statement(model, s, ns) diff --git a/inventory/admin.py b/inventory/admin.py index b418f99..5c17d3d 100644 --- a/inventory/admin.py +++ b/inventory/admin.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals from django.contrib import admin diff --git a/inventory/bcmagic.py b/inventory/bcmagic.py index a3cb409..703c097 100644 --- a/inventory/bcmagic.py +++ b/inventory/bcmagic.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals from .models import Item diff --git a/inventory/inventory_factory.py b/inventory/inventory_factory.py index 1698f27..e75ea41 100644 --- a/inventory/inventory_factory.py +++ b/inventory/inventory_factory.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals import datetime diff --git a/inventory/models.py b/inventory/models.py index 1e85096..7e5c239 100644 --- a/inventory/models.py +++ b/inventory/models.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals import logging @@ -48,8 +48,8 @@ class Vendor(models.Model): name = models.CharField(max_length=256) url = models.URLField(blank=True, null=True) - def __unicode__(self): - return u"%s" % (self.name) + def __str__(self): + return "%s" % (self.name) class Location(models.Model): @@ -64,11 +64,11 @@ class Location(models.Model): notes = models.TextField(blank=True, null=True) - def __unicode__(self): + def __str__(self): if len(self.location_description) > 16: - return u"%s: %s" % (self.name, self.location_description[0:16]+u"...") + return "%s: %s" % (self.name, self.location_description[0:16]+"...") else: - return u"%s: %s" % (self.name, self.location_description) + return "%s: %s" % (self.name, self.location_description) post_init.connect(_assign_uuid, sender=Location) @@ -88,16 +88,16 @@ class ItemInfo(models.Model): notes = models.TextField(blank=True, null=True) - def __unicode__(self): + def __str__(self): name = u'' if self.model_id: - name += u"model:%s " % (self.model_id) + name += "model:%s " % (self.model_id) if self.part_number: - name += u"part:%s " % (self.part_number) + name += "part:%s " % (self.part_number) if self.lot_number: - name += u"lot:%s " % (self.lot_number) + name += "lot:%s " % (self.lot_number) - return u"%s: %s" % (name, self.purchase_date) + return "%s: %s" % (name, self.purchase_date) class Meta: verbose_name_plural = "Item Info" @@ -108,15 +108,15 @@ class ItemType(models.Model): name = models.CharField(max_length=64, unique=True) description = models.TextField(blank=True, null=True) - def __unicode__(self): - return u"%s" % (self.name) + def __str__(self): + return "%s" % (self.name) class ItemStatus(models.Model): name = models.CharField(max_length=64, unique=True) notes = models.TextField(blank=True, null=True) - def __unicode__(self): + def __str__(self): return self.name class Meta: @@ -149,11 +149,11 @@ class Item(models.Model): notes = models.TextField(blank=True, null=True) - def __unicode__(self): + def __str__(self): if self.barcode_id is None or len(self.barcode_id) == 0: - return u"invu|%s" % (self.uuid) + return "invu|%s" % (self.uuid) else: - return u"invb|%s" % (self.barcode_id) + return "invb|%s" % (self.barcode_id) def get_absolute_url(self): return '/inventory/%s/' % (self.uuid) @@ -172,7 +172,7 @@ class PrinterTemplate(models.Model): template = models.TextField() - def __unicode__(self): + def __str__(self): if self.default: return u'%s %s' % (self.item_type.name, self.printer.name) else: @@ -190,8 +190,8 @@ class LongTermStorage(models.Model): creation_date = models.DateTimeField(auto_now_add=True) modified_date = models.DateTimeField(auto_now=True) - def __unicode__(self): - return u"%s: %s" % (str(self.flowcell), ', '.join([str(s) for s in self.storage_devices.iterator()])) + def __str__(self): + return "%s: %s" % (str(self.flowcell), ', '.join([str(s) for s in self.storage_devices.iterator()])) class Meta: verbose_name_plural = "Long Term Storage" @@ -213,8 +213,8 @@ class ReagentFlowcell(ReagentBase): """ flowcell = models.ForeignKey(FlowCell) - def __unicode__(self): - return u"%s: %s" % (str(self.flowcell), ', '.join([str(s) for s in self.reagent.iterator()])) + def __str__(self): + return "%s: %s" % (str(self.flowcell), ', '.join([str(s) for s in self.reagent.iterator()])) class ReagentLibrary(ReagentBase): @@ -223,5 +223,5 @@ class ReagentLibrary(ReagentBase): """ library = models.ForeignKey(Library) - def __unicode__(self): - return u"%s: %s" % (str(self.library), ', '.join([str(s) for s in self.reagent.iterator()])) + def __str__(self): + return "%s: %s" % (str(self.library), ', '.join([str(s) for s in self.reagent.iterator()])) diff --git a/inventory/test_inventory.py b/inventory/test_inventory.py index b30da8c..6a5c595 100644 --- a/inventory/test_inventory.py +++ b/inventory/test_inventory.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals import RDF @@ -41,7 +41,7 @@ class InventoryTestCase(TestCase): itemNode = RDF.Node(RDF.Uri(url)) item_type = fromTypedNode( - model.get_target(itemNode, inventoryOntology['item_type'])) + model.get_target(itemNode, inventoryOntology[b'item_type'])) self.failUnlessEqual(item_type, item.item_type.name) def test_itemindex(self): diff --git a/inventory/urls.py b/inventory/urls.py index ff71a6b..98ece19 100644 --- a/inventory/urls.py +++ b/inventory/urls.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.conf.urls import patterns urlpatterns = patterns('', diff --git a/inventory/views.py b/inventory/views.py index 149710f..23b7200 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals from django.conf import settings from django.contrib.auth.decorators import login_required diff --git a/labels/admin.py b/labels/admin.py index 3ae391e..d2c7fcf 100644 --- a/labels/admin.py +++ b/labels/admin.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.template import Context, Template from django.contrib import admin diff --git a/labels/models.py b/labels/models.py index 8794492..fa5920b 100644 --- a/labels/models.py +++ b/labels/models.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.db import models class LabelPrinter(models.Model): @@ -10,8 +12,8 @@ class LabelPrinter(models.Model): labels = models.CharField(max_length=200) notes = models.TextField(null=True, blank=True) - def __unicode__(self): - return u'%s: %s' % (self.name, self.labels) + def __str__(self): + return '%s: %s' % (self.name, self.labels) class LabelTemplate(models.Model): """ @@ -23,7 +25,7 @@ class LabelTemplate(models.Model): ZPL_code = models.TextField('template') - def __unicode__(self): + def __str__(self): return '%s %s' % (self.name, self.printer.name) class LabelContent(models.Model): diff --git a/labels/test_labels.py b/labels/test_labels.py index ca3633b..b09de7a 100644 --- a/labels/test_labels.py +++ b/labels/test_labels.py @@ -4,6 +4,7 @@ unittest). These will both pass when you run "manage.py test". Replace these with more appropriate tests for your application. """ +from __future__ import unicode_literals from django.test import TestCase diff --git a/labels/views.py b/labels/views.py index 60f00ef..6f98496 100644 --- a/labels/views.py +++ b/labels/views.py @@ -1 +1,2 @@ +from __future__ import unicode_literals # Create your views here. diff --git a/samples/admin.py b/samples/admin.py index 5b9b858..69fe059 100644 --- a/samples/admin.py +++ b/samples/admin.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals from django.contrib import admin from django.contrib.admin import widgets diff --git a/samples/auth_backend.py b/samples/auth_backend.py index aacf43b..18fbe5c 100644 --- a/samples/auth_backend.py +++ b/samples/auth_backend.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals from django.conf import settings from django.contrib.auth.backends import ModelBackend diff --git a/samples/changelist.py b/samples/changelist.py index 716713a..842eb0a 100644 --- a/samples/changelist.py +++ b/samples/changelist.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals import django from django.contrib.admin.views.main import ChangeList diff --git a/samples/models.py b/samples/models.py index 5cf2e90..94cd075 100644 --- a/samples/models.py +++ b/samples/models.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import types import logging from django.db import models @@ -24,8 +26,8 @@ class Antibody(models.Model): source = models.CharField(max_length=500, blank=True, null=True, db_index=True) biology = models.TextField(blank=True, null=True) notes = models.TextField(blank=True, null=True) - def __unicode__(self): - return u'%s - %s' % (self.antigene, self.antibodies) + def __str__(self): + return '%s - %s' % (self.antigene, self.antibodies) class Meta: verbose_name_plural = "antibodies" ordering = ["antigene"] @@ -38,8 +40,8 @@ class Cellline(models.Model): db_index=True) notes = models.TextField(blank=True) - def __unicode__(self): - return unicode(self.cellline_name) + def __str__(self): + return str(self.cellline_name) class Meta: ordering = ["cellline_name"] @@ -54,8 +56,8 @@ class Condition(models.Model): verbose_name = 'Short Name') notes = models.TextField(blank=True) - def __unicode__(self): - return unicode(self.condition_name) + def __str__(self): + return str(self.condition_name) class Meta: ordering = ["condition_name"] @@ -64,8 +66,8 @@ class Condition(models.Model): class ExperimentType(models.Model): name = models.CharField(max_length=50, unique=True) - def __unicode__(self): - return unicode(self.name) + def __str__(self): + return str(self.name) class Tag(models.Model): tag_name = models.CharField(max_length=100, db_index=True,blank=False,null=False) @@ -79,8 +81,8 @@ class Tag(models.Model): context = models.CharField(max_length=50, choices=TAG_CONTEXT, default='Library') - def __unicode__(self): - return u'%s' % (self.tag_name) + def __str__(self): + return '%s' % (self.tag_name) class Meta: ordering = ["context","tag_name"] @@ -93,8 +95,8 @@ class Species(models.Model): common_name = models.CharField(max_length=256, blank=True) #use_genome_build = models.CharField(max_length=100, blank=False, null=False) - def __unicode__(self): - return u'%s (%s)' % (self.scientific_name, self.common_name) + def __str__(self): + return '%s (%s)' % (self.scientific_name, self.common_name) class Meta: verbose_name_plural = "species" @@ -111,15 +113,15 @@ class Affiliation(models.Model): users = models.ManyToManyField('HTSUser', null=True, blank=True) users.admin_order_field = "username" - def __unicode__(self): - str = unicode(self.name) + def __str__(self): + name = str(self.name) if self.contact is not None and len(self.contact) > 0: - str += u' ('+self.contact+u')' - return str + name += ' ('+self.contact+')' + return name def Users(self): users = self.users.all().order_by('username') - return ", ".join([unicode(a) for a in users ]) + return ", ".join([str(a) for a in users ]) class Meta: ordering = ["name","contact"] @@ -133,8 +135,8 @@ class LibraryType(models.Model): can_multiplex = models.BooleanField(default=True, help_text="Does this adapter provide multiplexing?") - def __unicode__(self): - return unicode(self.name) + def __str__(self): + return str(self.name) class Meta: ordering = ["-id"] @@ -201,7 +203,7 @@ class Library(models.Model): undiluted_concentration = models.DecimalField("Concentration", max_digits=5, decimal_places=2, blank=True, null=True, - help_text=u"Undiluted concentration (ng/\u00b5l)") + help_text = "Undiluted concentration (ng/\u00b5l)") # note \u00b5 is the micro symbol in unicode successful_pM = models.DecimalField(max_digits=9, decimal_places=1, blank=True, null=True) @@ -213,11 +215,11 @@ class Library(models.Model): bioanalyzer_summary = models.TextField(blank=True,default="") bioanalyzer_concentration = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, - help_text=u"(ng/\u00b5l)") + help_text="(ng/\u00b5l)") bioanalyzer_image_url = models.URLField(blank=True,default="") - def __unicode__(self): - return u'#%s: %s' % (self.id, self.library_name) + def __str__(self): + return '#%s: %s' % (self.id, self.library_name) class Meta: verbose_name_plural = "libraries" @@ -292,7 +294,7 @@ class Library(models.Model): tstr = '' ar = [] for t in affs: - ar.append(t.__unicode__()) + ar.append(t.__str__()) return '%s' % (", ".join(ar)) def is_archived(self): @@ -317,8 +319,8 @@ class Library(models.Model): affs = self.tags.all().order_by('tag_name') ar = [] for t in affs: - ar.append(t.__unicode__()) - return u'%s' % ( ", ".join(ar)) + ar.append(t.__str__()) + return '%s' % ( ", ".join(ar)) def DataRun(self): str ='Data Run' @@ -333,7 +335,7 @@ class Library(models.Model): # Check data sanity if res[2] != "OK": - return u'
'+res[2]+'
' + return '
'+res[2]+'
' rc = "%1.2f" % (res[1]/1000000.0) # Color Scheme: green is more than 10M, blue is more than 5M, orange is more than 3M and red is less. For RNAseq, all those thresholds should be doubled @@ -352,7 +354,7 @@ class Library(models.Model): if res[1] > rc_thr[2]: bgcolor ='#ffcc33' # Orange tstr = '
' - tstr += res[0].__unicode__()+' Lanes, '+rc+' M Reads' + tstr += res[0].__str__()+' Lanes, '+rc+' M Reads' tstr += '
' else: tstr = 'not processed yet' return tstr @@ -384,9 +386,9 @@ class HTSUser(User): def admin_url(self): return '/admin/%s/%s/%d' % (self._meta.app_label, self._meta.module_name, self.id) - def __unicode__(self): - #return unicode(self.username) + u" (" + unicode(self.get_full_name()) + u")" - return unicode(self.get_full_name()) + u' (' + unicode(self.username) + ')' + def __str__(self): + #return str(self.username) + " (" + str(self.get_full_name()) + u")" + return str(self.get_full_name()) + ' (' + str(self.username) + ')' def HTSUserInsertID(sender, instance, **kwargs): """ diff --git a/samples/results.py b/samples/results.py index 2724a37..6949d4d 100644 --- a/samples/results.py +++ b/samples/results.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.conf import settings import glob diff --git a/samples/samples_factory.py b/samples/samples_factory.py index 3dd35f5..09b7988 100644 --- a/samples/samples_factory.py +++ b/samples/samples_factory.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import datetime import factory diff --git a/samples/test_samples.py b/samples/test_samples.py index 61fc930..4d14538 100644 --- a/samples/test_samples.py +++ b/samples/test_samples.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals import datetime import unittest @@ -12,7 +12,7 @@ from .views import library_dict, library_json, library from .samples_factory import * from htsworkflow.auth import apidata -from htsworkflow.util.conversion import unicode_or_none +from htsworkflow.util.conversion import str_or_none from htsworkflow.util.ethelp import validate_xhtml class LibraryTestCase(TestCase): @@ -52,7 +52,7 @@ class SampleWebTestCase(TestCase): lib_dict = library_dict(library.id) url = '/samples/library/%s/json' % (library.id,) lib_response = self.client.get(url, apidata) - lib_json = json.loads(lib_response.content)['result'] + lib_json = json.loads(str(lib_response.content))['result'] for d in [lib_dict, lib_json]: # amplified_from_sample is a link to the library table, @@ -63,7 +63,7 @@ class SampleWebTestCase(TestCase): #self.failUnlessEqual(d['amplified_from_sample'], lib.amplified_from_sample) self.failUnlessEqual(d['antibody_id'], library.antibody_id) self.failUnlessEqual(d['cell_line_id'], library.cell_line_id) - self.failUnlessEqual(d['cell_line'], unicode_or_none(library.cell_line)) + self.failUnlessEqual(d['cell_line'], str_or_none(library.cell_line)) self.failUnlessEqual(d['experiment_type'], library.experiment_type.name) self.failUnlessEqual(d['experiment_type_id'], library.experiment_type_id) self.failUnlessEqual(d['gel_cut_size'], library.gel_cut_size) @@ -82,7 +82,7 @@ class SampleWebTestCase(TestCase): self.failUnlessEqual(d['stopping_point'], library.stopping_point) self.failUnlessEqual(d['successful_pM'], library.successful_pM) self.failUnlessEqual(d['undiluted_concentration'], - unicode(library.undiluted_concentration)) + str(library.undiluted_concentration)) def junk(self): @@ -271,9 +271,9 @@ try: import RDF HAVE_RDF = True - rdfNS = RDF.NS("http://www.w3.org/1999/02/22-rdf-syntax-ns#") - xsdNS = RDF.NS("http://www.w3.org/2001/XMLSchema#") - libNS = RDF.NS("http://jumpgate.caltech.edu/wiki/LibraryOntology#") + rdfNS = RDF.NS(b"http://www.w3.org/1999/02/22-rdf-syntax-ns#") + xsdNS = RDF.NS(b"http://www.w3.org/2001/XMLSchema#") + libNS = RDF.NS(b"http://jumpgate.caltech.edu/wiki/LibraryOntology#") from htsworkflow.util.rdfhelp import dump_model except ImportError as e: @@ -288,7 +288,7 @@ class TestRDFaLibrary(TestCase): def test_parse_rdfa(self): model = get_rdf_memory_model() - parser = RDF.Parser(name='rdfa') + parser = RDF.Parser(name=b'rdfa') bob = AffiliationFactory.create(name='Bob') @@ -309,20 +309,20 @@ class TestRDFaLibrary(TestCase): #with open('/tmp/test.ttl', 'w') as outstream: # dump_model(model, outstream) # http://jumpgate.caltech.edu/wiki/LibraryOntology#affiliation> - self.check_literal_object(model, ['Bob'], p=libNS['affiliation']) + self.check_literal_object(model, ['Bob'], p=libNS[b'affiliation']) self.check_literal_object(model, ['experiment type name'], - p=libNS['experiment_type']) - self.check_literal_object(model, ['400'], p=libNS['gel_cut']) + p=libNS[b'experiment_type']) + self.check_literal_object(model, ['400'], p=libNS[b'gel_cut']) self.check_literal_object(model, ['microfluidics bot 7321'], - p=libNS['made_by']) + p=libNS[b'made_by']) self.check_literal_object(model, [lib_object.library_name], - p=libNS['name']) + p=libNS[b'name']) self.check_literal_object(model, [lib_object.library_species.scientific_name], - p=libNS['species_name']) + p=libNS[b'species_name']) def check_literal_object(self, model, values, s=None, p=None, o=None): @@ -340,7 +340,7 @@ class TestRDFaLibrary(TestCase): self.failUnlessEqual(len(statements), len(values), "Couln't find %s %s %s" % (s,p,o)) for s in statements: - self.failUnless(unicode(s.object.uri) in values) + self.failUnless(str(s.object.uri) in values) diff --git a/samples/urls.py b/samples/urls.py index 3d09dd4..1bda463 100644 --- a/samples/urls.py +++ b/samples/urls.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from django.conf.urls import patterns, url urlpatterns = patterns('samples.views', diff --git a/samples/views.py b/samples/views.py index 0684ee7..cc94c62 100644 --- a/samples/views.py +++ b/samples/views.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import, print_function, unicode_literals # Create your views here. import logging @@ -30,7 +30,7 @@ from bcmagic.forms import BarcodeMagicForm from htsworkflow.pipelines import runfolder from htsworkflow.pipelines.eland import ResultLane from htsworkflow.pipelines.samplekey import SampleKey -from htsworkflow.util.conversion import unicode_or_none, parse_flowcell_id +from htsworkflow.util.conversion import str_or_none, parse_flowcell_id from htsworkflow.util import makebed from htsworkflow.util import opener @@ -93,7 +93,7 @@ def create_library_context(cl): summary['lanes_run'] = lanes_run summary['is_archived'] = lib.is_archived() records.append(summary) - cl.result_count = unicode(cl.paginator._count) + cl.result_count = str(cl.paginator._count) return {'library_list': records} @@ -492,7 +492,7 @@ def library_dict(library_id): #'antibody_name': lib.antibody_name(), # we have no antibodies. 'antibody_id': lib.antibody_id, 'cell_line_id': lib.cell_line_id, - 'cell_line': unicode_or_none(lib.cell_line), + 'cell_line': str_or_none(lib.cell_line), 'experiment_type': lib.experiment_type.name, 'experiment_type_id': lib.experiment_type_id, 'gel_cut_size': lib.gel_cut_size, @@ -511,8 +511,8 @@ def library_dict(library_id): 'notes': lib.notes, 'replicate': lib.replicate, 'stopping_point': lib.stopping_point, - 'successful_pM': unicode_or_none(lib.successful_pM), - 'undiluted_concentration': unicode_or_none(lib.undiluted_concentration) + 'successful_pM': str_or_none(lib.successful_pM), + 'undiluted_concentration': str_or_none(lib.undiluted_concentration) } if lib.library_type_id is None: info['library_type'] = None