Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        from servo.lib.utils import empty
        super(GsxRepairForm, self).__init__(*args, **kwargs)
        repair = self.instance
        techs = User.techies.filter(location=repair.order.location)
        c = [(u.tech_id, u.get_full_name()) for u in techs]
        c.insert(0, ('', '-------------------',))
        self.fields['tech_id'] = forms.ChoiceField(choices=c,
                                                   required=False,
                                                   label=_('Technician'))
        self.fields['parts'].initial = repair.order.get_parts()

        if repair.can_mark_complete is False:
            del(self.fields['mark_complete'])
            del(self.fields['replacement_sn'])

        choices = Template.templates()
        for f in ('notes', 'symptom', 'diagnosis',):
            self.fields[f].widget = AutocompleteTextarea(choices=choices)

        symptom_codes = self.instance.get_symptom_code_choices()
        self.fields['symptom_code'] = forms.ChoiceField(choices=symptom_codes,
                                                        label=_('Symptom group'))

        if empty(self.instance.symptom_code):
            # default to the first choice
            self.instance.symptom_code = symptom_codes[0][0]

        issue_codes = self.instance.get_issue_code_choices()
        self.fields['issue_code'] = forms.ChoiceField(choices=issue_codes,
                                                      label=_('Issue code'))
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        from servo.lib.utils import empty
        super(GsxRepairForm, self).__init__(*args, **kwargs)
        repair = self.instance
        techs = User.techies.filter(location=repair.order.location)
        c = [(u.tech_id, u.get_full_name()) for u in techs]
        c.insert(0, ('', '-------------------',))
        self.fields['tech_id'] = forms.ChoiceField(choices=c,
                                                   required=False,
                                                   label=_('Technician'))
        self.fields['parts'].initial = repair.order.get_parts()

        if repair.can_mark_complete is False:
            del(self.fields['mark_complete'])
            del(self.fields['replacement_sn'])

        choices = Template.templates()
        for f in ('notes', 'symptom', 'diagnosis',):
            self.fields[f].widget = AutocompleteTextarea(choices=choices)
        
        symptom_codes = self.instance.get_symptom_code_choices()
        self.fields['symptom_code'] = forms.ChoiceField(choices=symptom_codes,
                                                        label=_('Symptom group'))
        
        if empty(self.instance.symptom_code):
            # default to the first choice
            self.instance.symptom_code = symptom_codes[0][0]

        issue_codes = self.instance.get_issue_code_choices()
        self.fields['issue_code'] = forms.ChoiceField(choices=issue_codes,
                                                      label=_('Issue code'))
Ejemplo n.º 3
0
def check_mail():
    """Checks IMAP box for incoming mail"""
    uid = Configuration.conf('imap_act')

    if empty(uid):
        raise ConfigurationError('Incoming message user not configured')

    counter = 0
    user = User.objects.get(pk=uid)
    server = Configuration.get_imap_server()
    typ, data = server.search(None, "UnSeen")

    for num in data[0].split():
        #logging.debug("** Processing message %s" % num)
        typ, data = server.fetch(num, "(RFC822)")
        # parsestr() seems to return an email.message?
        msg = Parser().parsestr(data[0][1])
        Note.from_email(msg, user)
        #server.copy(num, 'servo')
        server.store(num, '+FLAGS', '\\Seen')
        counter += 1

    server.close()
    server.logout()

    return '%d messages processed' % counter
Ejemplo n.º 4
0
    def get_default_account(cls):
        from servo.lib.utils import empty
        act_pk = Configuration.conf('gsx_account')

        if empty(act_pk):
            raise ValueError(_('Default GSX account not configured'))

        return GsxAccount.objects.get(pk=act_pk)
Ejemplo n.º 5
0
    def get_smtp_server(cls):
        host, port = cls.conf('smtp_host'), 25

        if empty(host):
            raise ConfigurationError('SMTP server not configured')

        if len(host.split(':')) == 2:
            return host.split(':')

        return host, port
Ejemplo n.º 6
0
    def get_smtp_server(cls):
        host, port = cls.conf('smtp_host'), 25

        if empty(host):
            raise ConfigurationError('SMTP server not configured')

        if len(host.split(':')) == 2:
            return host.split(':')

        return host, port
Ejemplo n.º 7
0
    def get_default_account(cls):
        """
        Returns the default GSX account without connecting to it
        """
        from servo.lib.utils import empty
        act_pk = Configuration.conf('gsx_account')

        if empty(act_pk):
            raise ValueError(_('Default GSX account not configured'))

        return GsxAccount.objects.get(pk=act_pk)
Ejemplo n.º 8
0
    def handle(self, *args, **options):
        # get local user to create notes as
        uid = Configuration.conf('imap_act')

        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')):
            # 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)

            if aware < i.updated_at:  # hasn't been updated
                continue

            try:
                parent = i.note_set.latest()
            except Note.DoesNotExist:
                continue

            bodies = [n.body for n in i.note_set.all()]

            for x in r.escalationNotes.iterchildren():
                if x.text in bodies:  # skip notes we already have
                    continue

                note = Note(created_by=user, escalation=i, body=x.text)
                parent.add_reply(note)
                note.save()

            i.updated_at = timezone.now()
            i.status = r.escalationStatus
            i.save()
Ejemplo n.º 9
0
    def handle(self, *args, **options):
        # get local user to create notes as
        uid = Configuration.conf('imap_act')
        
        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')):
            # 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)

            if aware < i.updated_at: # hasn't been updated
                continue

            try:
                parent = i.note_set.latest()
            except Note.DoesNotExist:
                continue

            bodies = [n.body for n in i.note_set.all()]

            for x in r.escalationNotes.iterchildren():
                if x.text in bodies: # skip notes we already have
                    continue

                note = Note(created_by=user, escalation=i, body=x.text)
                parent.add_reply(note)
                note.save()

            i.updated_at = timezone.now()
            i.status = r.escalationStatus
            i.save()
Ejemplo n.º 10
0
    def from_gsx(cls, sn, device=None, cached=True):
        """
        Initialize new Device with warranty info from GSX
        Or update existing one
        """
        sn = sn.upper()
        cache_key = 'device-%s' % sn

        # Only cache unsaved devices
        if cached and device is None:
            if cache.get(cache_key):
                return cache.get(cache_key)

        arg = gsxws.validate(sn)

        if arg not in ("serialNumber", "alternateDeviceId",):
            raise ValueError(_(u"Invalid input for warranty check: %s") % sn)

        product = gsxws.Product(sn)
        wty     = product.warranty()
        model   = product.model()

        if device is None:
            # serialNumber may sometimes come back empty
            serial_number = wty.serialNumber or sn
            device = Device(sn=serial_number)

        from servo.lib.utils import empty

        if empty(device.notes):
            device.notes = wty.notes or ''
            device.notes += wty.csNotes or ''

        device.has_onsite       = product.has_onsite
        device.is_vintage       = product.is_vintage
        device.description      = product.description
        device.fmip_active      = product.fmip_is_active

        device.slug             = slugify(device.description)
        device.configuration    = wty.configDescription or ''
        device.purchase_country = wty.purchaseCountry or ''

        device.config_code      = model.configCode
        device.product_line     = model.productLine.replace(" ", "")
        device.parts_and_labor_covered = product.parts_and_labor_covered

        device.sla_description      = wty.slaGroupDescription or ''
        device.contract_start_date  = wty.contractCoverageStartDate
        device.contract_end_date    = wty.contractCoverageEndDate
        device.onsite_start_date    = wty.onsiteStartDate
        device.onsite_end_date      = wty.onsiteEndDate

        if wty.estimatedPurchaseDate:
            device.purchased_on = wty.estimatedPurchaseDate

        device.image_url         = wty.imageURL or ''
        device.manual_url        = wty.manualURL or ''
        device.exploded_view_url = wty.explodedViewURL or ''

        if wty.warrantyStatus:
            device.set_wty_status(wty.warrantyStatus)

        if product.is_ios:
            ad = device.get_activation()
            device.imei = ad.imeiNumber or ''
            device.unlocked = product.is_unlocked(ad)
            device.applied_activation_policy = ad.appliedActivationDetails or ''
            device.initial_activation_policy = ad.initialActivationPolicyDetails or ''
            device.next_tether_policy = ad.nextTetherPolicyDetails or ''

        cache.set(cache_key, device)

        return device
Ejemplo n.º 11
0
    def from_gsx(cls, sn, device=None, cached=True, user=None):
        """
        Initialize new Device with warranty info from GSX
        Or update existing one
        """
        sn = sn.upper()
        cache_key = 'device-%s' % sn

        # Only cache unsaved devices
        if cached and device is None:
            if cache.get(cache_key):
                return cache.get(cache_key)

        arg = gsxws.validate(sn)

        if arg not in ("serialNumber", "alternateDeviceId",):
            raise ValueError(_(u"Invalid input for warranty check: %s") % sn)

        product = gsxws.Product(sn)

        if user and user.location:
            ship_to = user.location.gsx_shipto
        else:
            gsx_act = GsxAccount.get_default_account()
            ship_to = gsx_act.ship_to

        wty = product.warranty(ship_to=ship_to)
        model = product.model()

        if device is None:
            # serialNumber may sometimes come back empty
            serial_number = wty.serialNumber or sn
            device = Device(sn=serial_number)

        from servo.lib.utils import empty

        if empty(device.notes):
            device.notes = wty.notes or ''
            device.notes += wty.csNotes or ''

        device.has_onsite = product.has_onsite
        device.is_vintage = product.is_vintage
        device.description = product.description
        device.fmip_active = product.fmip_is_active

        device.slug = slugify(device.description)
        device.configuration = wty.configDescription or ''
        device.purchase_country = countries.by_name(wty.purchaseCountry)

        device.config_code = model.configCode
        device.product_line = model.productLine.replace(" ", "")
        device.parts_and_labor_covered = product.parts_and_labor_covered

        device.sla_description = wty.slaGroupDescription or ''
        device.contract_start_date = wty.contractCoverageStartDate
        device.contract_end_date = wty.contractCoverageEndDate
        device.onsite_start_date = wty.onsiteStartDate
        device.onsite_end_date = wty.onsiteEndDate

        if wty.estimatedPurchaseDate:
            device.purchased_on = wty.estimatedPurchaseDate

        device.image_url = wty.imageURL or ''
        device.manual_url = wty.manualURL or ''
        device.exploded_view_url = wty.explodedViewURL or ''

        if wty.warrantyStatus:
            device.set_wty_status(wty.warrantyStatus)

        if product.is_ios:
            ad = device.get_activation()
            device.imei = ad.imeiNumber or ''
            device.unlocked = product.is_unlocked(ad)
            device.applied_activation_policy = ad.appliedActivationDetails or ''
            device.initial_activation_policy = ad.initialActivationPolicyDetails or ''
            device.next_tether_policy = ad.nextTetherPolicyDetails or ''

        cache.set(cache_key, device)

        return device