How to use the orchestra.utils.python.AttrDict function in orchestra

To help you get started, we’ve selected a few orchestra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github glic3rinu / django-orchestra / orchestra / contrib / domains / models.py View on Github external
def get_records(self):
        types = set()
        records = utils.RecordStorage()
        for record in self.get_declared_records():
            types.add(record.type)
            if record.type == record.SOA:
                # Update serial and insert at 0
                value = record.value.split()
                value[2] = str(self.serial)
                records.insert(0, AttrDict(
                    type=record.SOA,
                    ttl=record.get_ttl(),
                    value=' '.join(value)
                ))
            else:
                records.append(AttrDict(
                    type=record.type,
                    ttl=record.get_ttl(),
                    value=record.value
                ))
        for record in self.get_default_records():
            if self.record_is_implicit(record, types):
                if record.type is Record.SOA:
                    records.insert(0, record)
                else:
                    records.append(record)
github glic3rinu / django-orchestra / orchestra / contrib / domains / models.py View on Github external
def get_records(self):
        types = set()
        records = utils.RecordStorage()
        for record in self.get_declared_records():
            types.add(record.type)
            if record.type == record.SOA:
                # Update serial and insert at 0
                value = record.value.split()
                value[2] = str(self.serial)
                records.insert(0, AttrDict(
                    type=record.SOA,
                    ttl=record.get_ttl(),
                    value=' '.join(value)
                ))
            else:
                records.append(AttrDict(
                    type=record.type,
                    ttl=record.get_ttl(),
                    value=record.value
                ))
        for record in self.get_default_records():
            if self.record_is_implicit(record, types):
                if record.type is Record.SOA:
                    records.insert(0, record)
                else:
                    records.append(record)
        return records
github glic3rinu / django-orchestra / orchestra / contrib / resources / aggregations.py View on Github external
def aggregate_history(self, dataset):
        prev = None
        prev_object_id = None
        datas = []
        sink = AttrDict(object_id=-1, value=-1, content_object_repr='',
            created_at=AttrDict(year=-1, month=-1))
        for mdata in itertools.chain(dataset.order_by('object_id', 'created_at'), [sink]):
            object_id = mdata.object_id
            ymonth = (mdata.created_at.year, mdata.created_at.month)
            if object_id != prev_object_id or ymonth != prev.ymonth:
                if prev_object_id is not None:
                    data = AttrDict(
                        date=datetime.date(
                            year=prev.ymonth[0],
                            month=prev.ymonth[1],
                            day=1
                        ),
                        value=current,
                        content_object_repr=prev.content_object_repr
                    )
                    datas.append(data)
                current = mdata.value
github glic3rinu / django-orchestra / orchestra / utils / python.py View on Github external
def __init__(self, *args, **kwargs):
        super(AttrDict, self).__init__(*args, **kwargs)
        self.__dict__ = self
github glic3rinu / django-orchestra / orchestra / contrib / domains / models.py View on Github external
def get_default_records(self):
        defaults = []
        if self.is_top:
            for ns in settings.DOMAINS_DEFAULT_NS:
                defaults.append(AttrDict(
                    type=Record.NS,
                    value=ns
                ))
            soa = self.get_default_soa()
            defaults.insert(0, AttrDict(
                type=Record.SOA,
                value=soa
            ))
        for mx in settings.DOMAINS_DEFAULT_MX:
            defaults.append(AttrDict(
                type=Record.MX,
                value=mx
            ))
        default_a = settings.DOMAINS_DEFAULT_A
        if default_a:
            defaults.append(AttrDict(
github glic3rinu / django-orchestra / orchestra / contrib / resources / aggregations.py View on Github external
def aggregate_history(self, dataset):
        prev = None
        prev_object_id = None
        datas = []
        sink = AttrDict(object_id=-1, value=-1, content_object_repr='',
            created_at=AttrDict(year=-1, month=-1))
        for mdata in itertools.chain(dataset.order_by('object_id', 'created_at'), [sink]):
            object_id = mdata.object_id
            ymonth = (mdata.created_at.year, mdata.created_at.month)
            if object_id != prev_object_id or ymonth != prev.ymonth:
                if prev_object_id is not None:
                    data = AttrDict(
                        date=datetime.date(
                            year=prev.ymonth[0],
                            month=prev.ymonth[1],
                            day=1
                        ),
                        value=current,
                        content_object_repr=prev.content_object_repr
                    )
                    datas.append(data)
github glic3rinu / django-orchestra / orchestra / contrib / services / handlers.py View on Github external
discounts: extra discounts to apply
        computed: price = price*size already performed
        """
        if len(dates) == 2:
            ini, end = dates
        elif len(dates) == 1:
            ini, end = dates[0], dates[0]
        else:
            raise AttributeError("WTF is '%s'?" % dates)
        discounts = discounts or ()
        
        size = self.get_price_size(ini, end)
        if not computed:
            price = price * size
        subtotal = self.nominal_price * size * metric
        line = AttrDict(**{
            'order': order,
            'subtotal': subtotal,
            'ini': ini,
            'end': end,
            'size': size,
            'metric': metric,
            'discounts': [],
        })
        
        if subtotal > price:
            plan_discount = price-subtotal
            self.generate_discount(line, self._PLAN, plan_discount)
            subtotal += plan_discount
        for dtype, dprice in discounts:
            subtotal += dprice
            # Prevent compensations/prepays to refund money
github glic3rinu / django-orchestra / orchestra / contrib / domains / models.py View on Github external
def get_default_records(self):
        defaults = []
        if self.is_top:
            for ns in settings.DOMAINS_DEFAULT_NS:
                defaults.append(AttrDict(
                    type=Record.NS,
                    value=ns
                ))
            soa = self.get_default_soa()
            defaults.insert(0, AttrDict(
                type=Record.SOA,
                value=soa
            ))
        for mx in settings.DOMAINS_DEFAULT_MX:
            defaults.append(AttrDict(
                type=Record.MX,
                value=mx
            ))
        default_a = settings.DOMAINS_DEFAULT_A
        if default_a:
            defaults.append(AttrDict(
                type=Record.A,
                value=default_a
            ))
        default_aaaa = settings.DOMAINS_DEFAULT_AAAA
        if default_aaaa:
            defaults.append(AttrDict(
                type=Record.AAAA,
                value=default_aaaa
            ))
        return defaults
github glic3rinu / django-orchestra / orchestra / contrib / services / handlers.py View on Github external
def generate_discount(self, line, dtype, price):
        line.discounts.append(AttrDict(**{
            'type': dtype,
            'total': price,
        }))