Flake8 Fixes

Mostly whitespace fixes
Some unicode fixes
Fixed up CSV writer.  str is not bytes and all.
This commit is contained in:
Sachi King 2017-04-17 22:51:48 +10:00
parent ecf14b514d
commit 298b162be6
18 changed files with 97 additions and 94 deletions

View file

@ -25,13 +25,13 @@ def export_as_csv_action(description=None, fields=None, exclude=None,
excludeset = set(exclude)
field_names = field_names - excludeset
response = HttpResponse(content_type="text/csv")
response["Content-Disposition"] = "attachment; filename=%s.csv" % unicode(opts).replace(".", "_")
response["Content-Disposition"] = "attachment; filename=%s.csv" % str(opts).replace(".", "_")
writer = csv.writer(response)
if header:
writer.writerow(list(field_names))
for obj in queryset:
writer.writerow(
[unicode(getattr(obj, field)).encode("utf-8", "replace") for field in field_names])
[str(getattr(obj, field)).encode("utf-8", "replace") for field in field_names])
return response
if description is None:
description = _("Export selected objects as CSV file")

View file

@ -205,6 +205,7 @@ class ProposalBase(models.Model):
def __str__(self):
return self.title
reversion.register(ProposalBase)

View file

@ -8,5 +8,5 @@ class Command(BaseCommand):
def handle(self, *args, **options):
for proposal in ProposalBase.objects.filter(cancelled=0):
print "Creating assignments for %s" % (proposal.title,)
print("Creating assignments for %s" % proposal.title)
ReviewAssignment.create_assignments(proposal)

View file

@ -22,4 +22,4 @@ class Command(BaseCommand):
content_type__pk=ct.id,
defaults={"name": "Can %s %s" % (action, ps), "content_type": ct}
)
print perm
print(perm)

View file

@ -47,6 +47,8 @@ class Votes(object):
(MINUS_TWO, _("2 — Serious issues and I will argue to reject this proposal.")),
(ABSTAIN, _("Abstain - I do not want to review this proposal and I do not want to see it again.")),
]
VOTES = Votes()
@ -395,4 +397,6 @@ def accepted_proposal(sender, instance=None, **kwargs):
promote_proposal(instance.proposal)
else:
unpromote_proposal(instance.proposal)
post_save.connect(accepted_proposal, sender=ProposalResult)

View file

@ -89,12 +89,12 @@ REVIEW_STATUS_FILTERS = {
result__plus_two=0).order_by("result__vote_count"),
# proposals with at least VOTE_THRESHOLD reviews and both a +2 and -2, sorted by total
# votes (highest first)
CONTROVERSIAL: lambda qs: qs.filter(result__vote_count__gte=VOTE_THRESHOLD,
result__plus_two__gt=0, result__minus_two__gt=0)
.order_by("-result__vote_count"),
CONTROVERSIAL: lambda qs: qs.filter(
result__vote_count__gte=VOTE_THRESHOLD, result__plus_two__gt=0,
result__minus_two__gt=0).order_by("-result__vote_count"),
# proposals with fewer than VOTE_THRESHOLD reviews
TOO_FEW: lambda qs: qs.filter(result__vote_count__lt=VOTE_THRESHOLD)
.order_by("result__vote_count"),
TOO_FEW: lambda qs: qs.filter(
result__vote_count__lt=VOTE_THRESHOLD).order_by("result__vote_count"),
}
@ -189,11 +189,6 @@ def review_all_proposals_csv(request):
csv_line = [getattr(proposal, field) for field in fields]
# Enusre that unicode items are handled properly.
for i, item in enumerate(csv_line):
if isinstance(item, unicode):
csv_line[i] = item.encode("utf8")
writer.writerow(csv_line)
return response

View file

@ -28,4 +28,4 @@ def create_slot(section_slug, date, kind, start, end, rooms):
slot_room.slot = slot
slot_room.room = room
slot_room.save(force_insert=True)
print "created {} [start={}; end={}]".format(slot.kind.label, slot.start, slot.end)
print("created {} [start={}; end={}]".format(slot.kind.label, slot.start, slot.end))

View file

@ -21,6 +21,7 @@ from symposion.schedule.models import Schedule, Day, Slot, Presentation, Session
from symposion.schedule.timetable import TimeTable
from symposion.conference.models import Conference
def fetch_schedule(slug):
qs = Schedule.objects.all()
@ -265,11 +266,13 @@ def schedule_json(request):
content_type="application/json"
)
class EventFeed(ICalFeed):
product_id = '-//linux.conf.au/schedule//EN'
timezone = settings.TIME_ZONE
filename = 'conference.ics'
def description(self):
return Conference.objects.all().first().title
@ -305,18 +308,18 @@ class EventFeed(ICalFeed):
def item_location(self, item):
return ", ".join(room["name"] for room in item.rooms.values())
def item_link(self, item):
def item_link(self, item) -> str:
if hasattr(item.content, 'proposal'):
return 'http://%s%s' % (
Site.objects.get_current().domain,
reverse('schedule_presentation_detail', args=[item.content.pk])
)
return (
'http://%s%s' % (Site.objects.get_current().domain,
reverse('schedule_presentation_detail', args=[item.content.pk])))
else:
return 'http://%s' % Site.objects.get_current().domain
def item_guid(self, item):
return '%d@%s' % (item.pk, Site.objects.get_current().domain)
def session_list(request):
sessions = Session.objects.all().order_by('pk')

View file

@ -9,11 +9,12 @@ from symposion.speakers.models import Speaker
class Command(BaseCommand):
def handle(self, *args, **options):
csv_file = csv.writer(open(os.path.join(os.getcwd(), "speakers.csv"), "wb"))
csv_file.writerow(["Name", "Bio"])
with open(os.path.join(os.getcwd(), "speakers.csv"), "w") as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(["Name", "Bio"])
for speaker in Speaker.objects.all():
csv_file.writerow([
speaker.name.encode("utf-8"),
speaker.biography.encode("utf-8"),
csv_writer.writerow([
speaker.name,
speaker.biography,
])

View file

@ -30,10 +30,9 @@ class Command(BaseCommand):
except:
pass
csv_file = csv.writer(
open(os.path.join(os.getcwd(), "build", "sponsors.csv"), "wb")
)
csv_file.writerow(["Name", "URL", "Level", "Description"])
with open(os.path.join(os.getcwd(), "build", "sponsors.csv"), "w") as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(["Name", "URL", "Level", "Description"])
for sponsor in Sponsor.objects.all():
path = os.path.join(os.getcwd(), "build", slugify(sponsor.name))
@ -48,6 +47,7 @@ class Command(BaseCommand):
"level": sponsor.level.name,
"description": "",
}
for sponsor_benefit in sponsor.sponsor_benefits.all():
if sponsor_benefit.benefit_id == 2:
data["description"] = sponsor_benefit.text
@ -65,11 +65,11 @@ class Command(BaseCommand):
logo_path = data.pop("logo")
shutil.copy(logo_path, path)
csv_file.writerow([
data["name"].encode("utf-8"),
data["url"].encode("utf-8"),
data["level"].encode("utf-8"),
data["description"].encode("utf-8")
csv_writer.writerow([
data["name"],
data["url"],
data["level"],
data["description"]
])
zipdir(

View file

@ -19,7 +19,7 @@ class Command(BaseCommand):
sponsor=sponsor, benefit=benefit_level.benefit)
if created:
print "created", sponsor_benefit, "for", sponsor
print("created %s for %s" % (sponsor_benefit, sponsor))
# and set to default limits for this level.
sponsor_benefit.max_words = benefit_level.max_words

View file

@ -203,12 +203,16 @@ class Sponsor(models.Model):
def _store_initial_level(sender, instance, **kwargs):
if instance:
instance._initial_level_id = instance.level_id
post_init.connect(_store_initial_level, sender=Sponsor)
def _check_level_change(sender, instance, created, **kwargs):
if instance and (created or instance.level_id != instance._initial_level_id):
instance.reset_benefits()
post_save.connect(_check_level_change, sender=Sponsor)
@ -330,4 +334,6 @@ def _denorm_weblogo(sender, instance, created, **kwargs):
sponsor = instance.sponsor
sponsor.sponsor_logo = instance
sponsor.save()
post_save.connect(_denorm_weblogo, sender=SponsorBenefit)

View file

@ -13,4 +13,5 @@ class MembershipAdmin(VersionAdmin):
list_filter = ["team"]
search_fields = ["user__username"]
admin.site.register(Membership, MembershipAdmin)

View file

@ -69,6 +69,7 @@ class Team(models.Model):
verbose_name = _('Team')
verbose_name_plural = _('Teams')
MEMBERSHIP_STATE_CHOICES = [
("applied", _("applied")),
("invited", _("invited")),
@ -93,4 +94,5 @@ class Membership(models.Model):
verbose_name = _("Membership")
verbose_name_plural = _("Memberships")
reversion.register(Membership)

View file

@ -53,16 +53,6 @@ def __send_email__(template_prefix, to, kind, **kwargs):
from_email = settings.DEFAULT_FROM_EMAIL
try:
bcc_email = settings.ENVELOPE_BCC_LIST
except AttributeError:
bcc_email = None
try:
bcc_email = settings.ENVELOPE_BCC_LIST
except AttributeError:
bcc_email = None
email = EmailMultiAlternatives(subject, message_plaintext, from_email, to)
email.attach_alternative(message_html, "text/html")
email.send()