Migrate code to python 3.5

parent 1fdd7968
Pipeline #6433 passed with stage
in 42 seconds
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
......
......@@ -24,7 +24,7 @@ class BugReport(models.Model):
_type = VirtualField("BugReport")
def __unicode__(self):
return "#%d by %s at %s" % (self.id, unicode(self.author), unicode(self.timestamp))
return "#%d by %s at %s" % (self.id, str(self.author), str(self.timestamp))
class BugReportSerializer(serializers.ModelSerializer):
......@@ -42,8 +42,8 @@ class BugReportSerializer(serializers.ModelSerializer):
payload = {
"attachments": [
{
"fallback": u"Un bug a été reporté par _%s_ dans le bar _%s_" % (b.author.get_full_name(), b.bar.name),
"text": u"Un bug a été reporté par *%s* dans le bar *%s*" % (b.author.get_full_name(), b.bar.name),
"fallback": "Un bug a été reporté par _%s_ dans le bar _%s_" % (b.author.get_full_name(), b.bar.name),
"text": "Un bug a été reporté par *%s* dans le bar *%s*" % (b.author.get_full_name(), b.bar.name),
"color": "#D00000",
"fields": [
{
......@@ -65,7 +65,7 @@ class BugReportSerializer(serializers.ModelSerializer):
requests.post(url_slack, json=payload, proxies=proxies)
if settings.IRC_HOOK:
lines = []
lines.append(u"Un bug a été reporté par %c03%c%s%c%c dans le bar %c05%c%s%c%c" % (chr(3), chr(2), b.author.get_full_name(), chr(2), chr(3), chr(3), chr(2), b.bar.name, chr(2), chr(3)))
lines.append("Un bug a été reporté par %c03%c%s%c%c dans le bar %c05%c%s%c%c" % (chr(3), chr(2), b.author.get_full_name(), chr(2), chr(3), chr(3), chr(2), b.bar.name, chr(2), chr(3)))
lines.append("%c02%cMessage: %c%c" % (chr(3), chr(2), chr(2), chr(3)))
lines.append(b.message)
lines.append("%c02%cContexte: %c%c"% (chr(3), chr(2), chr(2), chr(3)))
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.utils.timezone
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import datetime
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.utils.timezone import utc
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
......
......@@ -15,7 +15,7 @@ class LoginAttempt(models.Model):
ip = models.CharField(max_length=15)
def __unicode__(self):
return "%s at %s (success=%s)" % (unicode(self.sent_username), unicode(self.timestamp), unicode(self.success))
return "%s at %s (success=%s)" % (str(self.sent_username), str(self.timestamp), str(self.success))
class LoginAttemptSerializer(serializers.ModelSerializer):
......
......@@ -20,7 +20,7 @@ class RoleManager(models.Manager):
class Role(models.Model):
class Meta:
app_label = 'bars_core'
name = models.CharField(max_length=127, choices=zip(roles_list, roles_list))
name = models.CharField(max_length=127, choices=list(zip(roles_list, roles_list)))
bar = models.ForeignKey(Bar)
user = models.ForeignKey(User)
last_modified = models.DateTimeField(auto_now=True)
......
......@@ -194,7 +194,7 @@ class UserViewSet(viewsets.ModelViewSet):
reset_mail = {
'from_email': 'babe@binets.polytechnique.fr',
'subject': 'Mot de passe Chocapix',
'message': u"""
'message': """
Salut,
Ton mot de passe Chocapix a été réinitialisé.
......
......@@ -11,14 +11,14 @@ DEBUG_STEP = 2
def debug_begin(name, perm, obj):
if DEBUG:
global DEBUG_INDENT
print("%s%s: %s, %s" % (" "*DEBUG_INDENT, name, perm, repr(obj)))
print(("%s%s: %s, %s" % (" "*DEBUG_INDENT, name, perm, repr(obj))))
DEBUG_INDENT += DEBUG_STEP
def debug_end(name, perm, obj, res):
if DEBUG:
global DEBUG_INDENT
DEBUG_INDENT -= DEBUG_STEP
print("%s%s: %s, %s => %s" % (" "*DEBUG_INDENT, name, perm, repr(obj), res))
print(("%s%s: %s, %s => %s" % (" "*DEBUG_INDENT, name, perm, repr(obj), res)))
def debug_perm(name):
"""
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import datetime
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import datetime
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
......
......@@ -22,7 +22,7 @@ class BuyItemPrice(models.Model):
price = models.FloatField(default=0)
def __unicode__(self):
return "%s (%s)" % (unicode(self.buyitem), unicode(self.bar))
return "%s (%s)" % (str(self.buyitem), str(self.bar))
@permission_logic(RootBarRolePermissionLogic())
......@@ -34,7 +34,7 @@ class BuyItem(models.Model):
itemqty = models.FloatField(default=1)
def __unicode__(self):
return "%s * %f" % (unicode(self.details), self.itemqty)
return "%s * %f" % (str(self.details), self.itemqty)
class BuyItemSerializer(serializers.ModelSerializer):
......@@ -45,7 +45,7 @@ class BuyItemSerializer(serializers.ModelSerializer):
def to_representation(self, buyitem):
obj = super(BuyItemSerializer, self).to_representation(buyitem)
if 'request' in self.context.keys() and self.context.get('request').method == 'GET':
if 'request' in self.context and self.context.get('request').method == 'GET':
bar = self.context['request'].query_params.get('bar', None)
if bar is not None:
try:
......
......@@ -38,7 +38,7 @@ class ItemDetailsSerializer(serializers.ModelSerializer):
def to_representation(self, itemdetails):
obj = super(ItemDetailsSerializer, self).to_representation(itemdetails)
if 'request' in self.context.keys() and self.context.get('request').method == 'GET':
if 'request' in self.context and self.context.get('request').method == 'GET':
bar = self.context['request'].query_params.get('bar', None)
if bar is not None:
try:
......
......@@ -81,7 +81,7 @@ class StockItem(models.Model):
return self.get_price(unit='sell')
def __unicode__(self):
return "%s (%s)" % (unicode(self.details), unicode(self.bar))
return "%s (%s)" % (str(self.details), str(self.bar))
class StockItemSerializer(serializers.ModelSerializer):
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
......
......@@ -57,7 +57,7 @@ def _get_interval_sql(date_field, interval, engine):
try:
engine_sql = SQL[engine]
except KeyError:
msg = '%s DB engine is not supported. Supported engines are: %s' % (engine, ", ".join(SQL.keys()))
msg = '%s DB engine is not supported. Supported engines are: %s' % (engine, ", ".join(list(SQL.keys())))
raise Exception(msg)
try:
......@@ -96,7 +96,7 @@ def time_series(qs, date_field, aggregate=None, interval='days', engine=None):
def compute_transaction_stats(request, filter=id, aggregate=None):
qs = Transaction.objects.filter(canceled=False)
qs = filter(qs)
qs = list(filter(qs))
if request.bar is not None:
qs = qs.filter(bar=request.bar)
......@@ -123,7 +123,7 @@ def compute_transaction_stats(request, filter=id, aggregate=None):
def compute_total_spent(request, filter=id, aggregate=None):
qs = Transaction.objects.filter(canceled=False)
qs = filter(qs)
qs = list(filter(qs))
if request.bar is not None:
qs = qs.filter(bar=request.bar)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
......
......@@ -25,7 +25,7 @@ class Transaction(models.Model):
def __unicode__(self):
return self.type + ": " \
+ unicode(list(self.accountoperation_set.all())
+ str(list(self.accountoperation_set.all())
+ list(self.itemoperation_set.all())
+ list(self.transactiondata_set.all()))
......@@ -111,9 +111,9 @@ class BaseOperation(models.Model):
def __unicode__(self):
if self.fixed:
return unicode(self.target) + "=" + unicode(self.next_value)
return str(self.target) + "=" + str(self.next_value)
else:
return unicode(self.target) + "+=" + unicode(self.delta)
return str(self.target) + "+=" + str(self.delta)
def save(self, *args, **kwargs):
if not self.pk:
......@@ -160,7 +160,7 @@ class ItemOperation(BaseOperation):
switching_to_negative_notification_mail = {
'subject': "[Chocapix] Notification de passage en négatif",
'message': u"""
'message': """
Salut,
Tu viens de payer {amount:.2f} € dans le bar {bar}, ce qui te fait passer en négatif.
......
......@@ -127,7 +127,6 @@ class ItemQtySerializer(serializers.Serializer):
total_price = 0
for (si, si_qty) in sellitem.calc_price_qty_per_stockitem():
print("si " + str(si) + " " + str(qty))
delta = si_qty * qty
si.create_operation(delta=-delta, unit='sell', transaction=t, fuzzy=True)
total_price += delta * si.get_price(unit='sell')
......@@ -413,7 +412,7 @@ class RefundTransactionSerializer(BaseTransactionSerializer, AccountAmountSerial
punishment_notification_mail = {
'from_email': "babe@binets.polytechnique.fr",
'subject': "[Chocapix] Notification d'amende",
'message': u"""
'message': """
Salut,
{name} a infligé une amende de {amount:.2f} € à ton compte dans le bar {bar}.
......@@ -475,7 +474,7 @@ class PunishTransactionSerializer(BaseTransactionSerializer, AccountAmountSerial
agios_notification_mail = {
'subject': "[Chocapix] Notification d'agios",
'message': u"""
'message': """
Salut,
Tu viens de payer {amount:.2f} € d'agios dans le bar {bar}.
......
......@@ -23,7 +23,7 @@ class TransactionFilterBackend(filters.BaseFilterBackend):
}
def filter_queryset(self, request, queryset, view):
for (param, q) in self.filter_q.items():
for param, q in self.filter_q.items():
x = request.query_params.get(param, None)
if x is not None:
queryset = queryset.filter(q(x))
......
This diff is collapsed.
......@@ -39,7 +39,7 @@ PASSWORD = "0000"
# ça devrait suffire.
###################################
COULEUR = u"jône" if PROMO%2 else u"roûje"
COULEUR = "jône" if PROMO%2 else "roûje"
COULEUR_ = "jone" if PROMO%2 else "rouje"
_attrs = ["sn", "givenName", "mail", "uid"]
......@@ -71,21 +71,21 @@ def run():
# supprimer les bars à remplacer, avec tous les objets qui en dépendent
bars = Bar.objects.filter(id__contains=COULEUR_)
bars = bars.exclude(id__contains="equitation") #permet de ne pas supprimer le BE equitation bi-promo
input(u"Suppression des bars suivants ?\n{}\nIl est encore temps d'appuyer sur ^C ! Appuyer sur entree pour continuer : ".format(u"\n".join(map(lambda bar:bar.name, bars))))
eval(input("Suppression des bars suivants ?\n{}\nIl est encore temps d'appuyer sur ^C ! Appuyer sur entree pour continuer : ".format("\n".join([bar.name for bar in bars]))))
bars.delete()
print("Done.")
# supprimer les utilisateurs qui n'ont plus de compte
vieux = User.objects.annotate(num_accounts=Count("account")).filter(num_accounts=0, is_superuser=False).exclude(username="bar")
input(u"Suppression des utilisateurs suivants ?\n{}\nIl est encore temps d'appuyer sur ^C ! Appuyer sur entree pour continuer : ".format(u"\n".join(map(lambda user: user.firstname+" "+user.lastname, vieux))))
eval(input("Suppression des utilisateurs suivants ?\n{}\nIl est encore temps d'appuyer sur ^C ! Appuyer sur entree pour continuer : ".format("\n".join([user.firstname+" "+user.lastname for user in vieux]))))
vieux.delete()
print("Done.")
# créer les bars, et les remplir
for barid, sections in BARS.items():
bar = Bar(id=barid+COULEUR_, name=u"{} {}".format(u"−".join(map(str.title, sections)), COULEUR.title()))
print(u"Creation de {}".format(bar.name))
bar = Bar(id=barid+COULEUR_, name="{} {}".format("−".join(map(str.title, sections)), COULEUR.title()))
print("Creation de {}".format(bar.name))
bar.save()
for section in sections:
for tos in get_section(section):
......@@ -94,9 +94,9 @@ def run():
def add_to_bar(user, bar):
try:
tos = User.objects.get(Q(email=user["mail"]) | Q(username=user["uid"]))
print(u"{} existe déjà".format(user["uid"]))
print(("{} existe déjà".format(user["uid"])))
except User.DoesNotExist:
print(u"Création de {}".format(user["uid"]))
print(("Création de {}".format(user["uid"])))
tos = User.objects.create_user(user["uid"], PASSWORD)
tos.pseudo = user["uid"]
tos.firstname = user["givenName"]
......
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