From 085832888a6ebee7f0b2d23c68ef887833f2a94d Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Wed, 18 Nov 2015 22:41:40 +0200 Subject: Cleanup --- servo/management/commands/checkescalations.py | 16 ++++++++++++---- servo/models/order.py | 3 +++ servo/models/rules.py | 11 +++++++++++ servo/tasks.py | 3 ++- servo/templates/checkin/index.html | 4 ++-- servo/templates/modal.html | 2 +- servo/templates/rules/list_rules.html | 1 + servo/views/customer.py | 5 +++-- 8 files changed, 35 insertions(+), 10 deletions(-) (limited to 'servo') diff --git a/servo/management/commands/checkescalations.py b/servo/management/commands/checkescalations.py index 488bda9..a4dfd5f 100644 --- a/servo/management/commands/checkescalations.py +++ b/servo/management/commands/checkescalations.py @@ -4,6 +4,8 @@ from django.db.models import Q from django.utils import timezone from django.core.management.base import BaseCommand, CommandError +from servo.lib.utils import empty +from servo.exceptions import ConfigurationError from servo.models import Configuration, Note, User, Escalation @@ -11,16 +13,22 @@ class Command(BaseCommand): help = "Check updates for open escalations" def handle(self, *args, **options): + # get local user to create notes as uid = Configuration.conf('imap_act') - - if uid in [None, '']: - return + + if empty(uid): + raise ConfigurationError('Incoming message user not defined') user = User.objects.get(pk=uid) tz = timezone.get_current_timezone() for i in Escalation.objects.exclude(Q(escalation_id='') | Q(status='C')): - i.gsx_account.connect(i.created_by) + # connect per-user since the escalations can be under different ship-tos + try: + i.gsx_account.connect(i.created_by) + except Exception: + continue # skip auth errors so we don't get stuck + r = i.get_escalation().lookup() aware = timezone.make_aware(r.lastModifiedTimestamp, tz) diff --git a/servo/models/order.py b/servo/models/order.py index 1a76a37..b5c4138 100644 --- a/servo/models/order.py +++ b/servo/models/order.py @@ -430,6 +430,9 @@ class Order(models.Model): pass def set_location(self, new_location, user): + """ + Moves order to new location + """ # move the products too for soi in self.serviceorderitem_set.all(): product = soi.product diff --git a/servo/models/rules.py b/servo/models/rules.py index 1e6ec2d..460a0b6 100644 --- a/servo/models/rules.py +++ b/servo/models/rules.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import json from django.db import models from django.core.cache import cache @@ -12,6 +13,13 @@ from django.utils.translation import ugettext_lazy as _ from servo.models import Event, Queue +class RuleManager: + + def all(self): + f = open('local_rules.json', 'r') + return json.loads(f.read()) + + class ServoModel(models.Model): class Meta: abstract = True @@ -19,6 +27,9 @@ class ServoModel(models.Model): class Rule(ServoModel): + + objects = RuleManager() + description = models.CharField(max_length=128, default=_('New Rule')) MATCH_CHOICES = ( ('ANY', _('Any')), diff --git a/servo/tasks.py b/servo/tasks.py index a10cb54..ed92331 100644 --- a/servo/tasks.py +++ b/servo/tasks.py @@ -10,6 +10,7 @@ from django.conf import settings from django.core.cache import cache from servo.lib.utils import empty +from servo.exceptions import ConfigurationError from servo.models import Configuration, User, Order, Note, Template @@ -163,7 +164,7 @@ def check_mail(): uid = Configuration.conf('imap_act') if empty(uid): - raise ValueError('Incoming message user not configured') + raise ConfigurationError('Incoming message user not configured') counter = 0 user = User.objects.get(pk=uid) diff --git a/servo/templates/checkin/index.html b/servo/templates/checkin/index.html index d7928fb..c197d31 100644 --- a/servo/templates/checkin/index.html +++ b/servo/templates/checkin/index.html @@ -34,7 +34,7 @@ {% endif %} diff --git a/servo/templates/modal.html b/servo/templates/modal.html index d6f75db..dbd3d37 100755 --- a/servo/templates/modal.html +++ b/servo/templates/modal.html @@ -3,7 +3,7 @@