Fixed the fucking unicode issues with the models.
This commit is contained in:
parent
6665365fd8
commit
4c64e92320
@ -51,19 +51,19 @@ class ServerParser(object):
|
||||
def _parse_server_data(self, data):
|
||||
'''Parse the individual parts of each server.'''
|
||||
try:
|
||||
title = data.find('b').get_text().splitlines()[0].strip().encode('utf-8')
|
||||
title = data.find('b').get_text().splitlines()[0].strip()
|
||||
except AttributeError:
|
||||
# HACK: I think this happends because the raw data was incomplete.
|
||||
# No complete data, no server update.
|
||||
return None
|
||||
game_url = data.find('span', 'smaller').text.encode('utf-8')
|
||||
game_url = data.find('span', 'smaller').text
|
||||
|
||||
tmp = data.find('a')
|
||||
site_url = None
|
||||
# Default means the server hasn't set a custom site url
|
||||
if tmp and not tmp.text == 'Default':
|
||||
try:
|
||||
site_url = tmp['href'].encode('utf-8')
|
||||
site_url = tmp['href']
|
||||
# Handle some funky servers...
|
||||
if site_url == 'http://':
|
||||
site_url = ''
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from datetime import timedelta
|
||||
from ast import literal_eval
|
||||
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
|
||||
DAY_NAMES = [
|
||||
@ -17,6 +19,7 @@ DAY_NAMES = [
|
||||
]
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Server(models.Model):
|
||||
title = models.CharField(max_length=255)
|
||||
game_url = models.CharField(max_length=255)
|
||||
@ -100,6 +103,7 @@ class Server(models.Model):
|
||||
tmp = [0,0,0,0,0,0,0]
|
||||
return zip(DAY_NAMES, tmp)
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class ServerHistory(models.Model):
|
||||
server = models.ForeignKey(Server)
|
||||
created = models.DateTimeField(default=timezone.now)
|
||||
@ -109,5 +113,5 @@ class ServerHistory(models.Model):
|
||||
ordering = ['-created', 'server']
|
||||
|
||||
def __str__(self):
|
||||
return 'History for {} at {}.'.format(self.server, self.created)
|
||||
return 'History for {} at {}.'.format(self.server.title, self.created)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user