Skip to content

Commit

Permalink
Merge pull request #39 from volunteer-planner/hotfix/1.2.1-fix-encoding
Browse files Browse the repository at this point in the history
Fix encoding issue (fix #40)
  • Loading branch information
pitpalme committed Sep 13, 2015
2 parents 2388b12 + 7c64bf8 commit e55fb89
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 39 deletions.
13 changes: 7 additions & 6 deletions blueprint/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# coding: utf-8

from django.db import models
from django.core.exceptions import ValidationError


# Create your models here.
class BluePrintCreator(models.Model):
class Meta:
verbose_name = "Vorlage"
Expand All @@ -13,7 +13,7 @@ class Meta:
needs = models.ManyToManyField('NeedBluePrint', verbose_name="Schichten")

def __unicode__(self):
return self.title
return u'{}'.format(self.title)


class NeedBluePrint(models.Model):
Expand All @@ -31,7 +31,8 @@ def get_location(self):

def __unicode__(self):
try:
location_name = self.blueprintcreator_set.all().get().location.name
location_name = u' ({})'.format(self.blueprintcreator_set.all().get().location.name)
except:
location_name = ""
return self.topic.title + " von " + self.from_time + " bis " + self.to_time + " " + location_name
location_name = u''

return u'{} von {} bis {}{}'.format(self.topic.title, self.from_time, self.to_time, location_name)
6 changes: 3 additions & 3 deletions notifications/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

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

# Create your models here.
from django.template.defaultfilters import slugify


Expand All @@ -24,4 +24,4 @@ def save(self, *args, **kwargs):
super(Notification, self).save(*args, **kwargs)

def __unicode__(self):
return self.title
return u'{}'.format(self.title)
18 changes: 14 additions & 4 deletions registration/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# coding: utf-8

import datetime
from exceptions import Exception
import hashlib
import random
import re
import traceback

from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
Expand All @@ -14,6 +17,7 @@

try:
from django.contrib.auth import get_user_model

User = get_user_model()
except Exception as e:
traceback.format_exc()
Expand All @@ -26,7 +30,6 @@
traceback.format_exc()
print e


SHA1_RE = re.compile('^[a-f0-9]{40}$')


Expand All @@ -39,6 +42,7 @@ class RegistrationManager(models.Manager):
keys), and for cleaning out expired inactive accounts.
"""

def activate_user(self, activation_key):
"""
Validate an activation key and activate the corresponding
Expand Down Expand Up @@ -96,6 +100,7 @@ def create_inactive_user(self, username, email, password,
registration_profile.send_activation_email(site)

return new_user

# create_inactive_user = transaction.commit(create_inactive_user)

def create_profile(self, user):
Expand All @@ -112,7 +117,7 @@ def create_profile(self, user):
username = user.username
if isinstance(username, unicode):
username = username.encode('utf-8')
activation_key = hashlib.sha1(salt+username).hexdigest()
activation_key = hashlib.sha1(salt + username).hexdigest()
return self.create(user=user,
activation_key=activation_key)

Expand Down Expand Up @@ -171,6 +176,7 @@ def delete_expired_users(self, dry_run=False):
user.delete()
profile.delete()
else:
# FIXME: remove
print('Would delete ' + profile.user.username +
', activation key ' + profile.activation_key)
users += 1
Expand All @@ -187,9 +193,12 @@ def delete_expired_users(self, dry_run=False):


class RegistrationProfile(models.Model):

# FIXME: i18n
class Meta:
verbose_name = "Freiwillige"
verbose_name_plural = "Freiwillige"

"""
A simple profile which stores an activation key for use during
user account registration.
Expand All @@ -216,7 +225,7 @@ class Meta:
objects = RegistrationManager()

def __unicode__(self):
return u"Username:%s Email:%s " % (self.user, self.user.email)
return u"Username: {} Email: {}".format(self.user, self.user.email)

def get_user_email(self):
return self.user.email
Expand Down Expand Up @@ -245,7 +254,8 @@ def activation_key_expired(self):
"""
expiration_date = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)
return self.activation_key == self.ACTIVATED or \
(self.user.date_joined + expiration_date <= datetime_now())
(self.user.date_joined + expiration_date <= datetime_now())

activation_key_expired.boolean = True

def send_activation_email(self, site):
Expand Down
2 changes: 2 additions & 0 deletions scheduler/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding: utf-8

from django.contrib import admin
from .models import *

Expand Down
14 changes: 8 additions & 6 deletions scheduler/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
# coding: utf-8

import datetime
import locale

from django.db import models
from django.utils.formats import localize
from django.utils.translation import ugettext_lazy as _
import locale
import datetime


class Need(models.Model):
Expand Down Expand Up @@ -72,7 +74,7 @@ def get_conflicting_needs(self, needs, grace=datetime.timedelta(hours=1)):
]

def __unicode__(self):
return "{title} - {location} ({start} - {end})".format(
return u"{title} - {location} ({start} - {end})".format(
title=self.topic.title, location=self.location.name,
start=localize(self.start), end=localize(self.end))

Expand Down Expand Up @@ -100,7 +102,7 @@ class Meta:
date_time = models.DateTimeField()

def __unicode__(self):
return str(self.date_time)
return u'{}'.format(self.date_time)


class Location(models.Model):
Expand All @@ -121,7 +123,7 @@ class Meta:
)

def __unicode__(self):
return self.name
return u'{}'.format(self.name)

def get_dates_of_needs(self):
needs_dates = []
Expand Down
16 changes: 7 additions & 9 deletions shiftmailer/excelexport.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.core.mail.message import EmailMessage
from xlwt import *
from datetime import datetime, date
# coding: utf-8

import time

import StringIO
from django.core.mail.message import EmailMessage
from xlwt import *


class GenerateExcelSheet:
Expand All @@ -24,8 +24,8 @@ def generate_excel(self):
"Anz",
"Freiwillige",
]
ws.write(0, 2, "Listenuebersicht der Freiwilligen in der Unterkunft "+self.needs[0].location.name, style_bold)
ws.write(1, 2, "Erstellt fuer "+self.mailer.organization)
ws.write(0, 2, "Listenuebersicht der Freiwilligen in der Unterkunft " + self.needs[0].location.name, style_bold)
ws.write(1, 2, "Erstellt fuer " + self.mailer.organization)
ws.write(2, 2, "Jedwede Weitergabe der Daten an Dritte ist verboten!")

for colindex, columname in enumerate(colnames):
Expand All @@ -41,7 +41,7 @@ def generate_excel(self):
for volunteers in row_data.get_volunteers():
volunteers_string += volunteers.user.email + ", "
ws.write(row_idx, 4, volunteers_string)
filename = "Dienstplan"+str(time.time())+".xls"
filename = "Dienstplan" + str(time.time()) + ".xls"
wb.save(filename)
return filename

Expand All @@ -55,6 +55,4 @@ def send_file(self):
mail.to = [str(self.mailer.email)]
attachment = self.generate_excel()
mail.attach_file(path=attachment, mimetype='application/octet-stream')
# import ipdb
# ipdb.set_trace()
mail.send()
18 changes: 8 additions & 10 deletions shiftmailer/management/commands/mailer.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import os
# coding: utf-8

from django.conf import settings
from django.core.management.base import BaseCommand
import datetime
from datetime import date, timedelta

from django.core.management.base import BaseCommand

from django.template.loader import render_to_string
from scheduler.models import Need, Location, Topics, TimePeriods
from dateutil.parser import *

from scheduler.models import Need
from shiftmailer.models import Mailer
import ipdb
import codecs
from shiftmailer.excelexport import GenerateExcelSheet


Expand All @@ -22,11 +20,11 @@ def handle(self, *args, **options):
mailer = Mailer.objects.all()
for mail in mailer:
now = datetime.datetime.now()
needs = Need.objects.filter(location=mail.location).\
needs = Need.objects.filter(location=mail.location). \
filter(
time_period_to__date_time__year=now.strftime("%Y"),
time_period_to__date_time__month=now.strftime("%m"),
time_period_to__date_time__day=now.strftime("%d"))\
time_period_to__date_time__day=now.strftime("%d")) \
.order_by('topic', 'time_period_to__date_time')

message = render_to_string('shifts_today.html', locals())
Expand Down
4 changes: 3 additions & 1 deletion shiftmailer/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding: utf-8

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

Expand All @@ -11,4 +13,4 @@ class Mailer(models.Model):
email = models.EmailField(verbose_name=_("email"))

def __unicode__(self):
return self.organization + "(" + self.location.name + ")"
return u'{} ({})'.format(self.organization, self.location.name)

0 comments on commit e55fb89

Please sign in to comment.