예제 #1
0
class ClassifierSetting(models.Model):
    """
        A model wrapper around the gamera classifier settings xml file.
        The xml file can be used in the classification jobs to provide
        feature weights.

        A setting file is typically produced from a classifier optimization
        task, in which case the setting will be linked to an `optimizationrun`
        record.
    """
    @property
    def setting_directory(self):
        return os.path.join(self.project.project_path, 'classifier_settings')

    def upload_fn(self, filename):
        _, ext = os.path.splitext(os.path.basename(filename))
        return os.path.join(self.setting_directory,
                            "{0}{1}".format(str(self.uuid), ext))

    uuid = UUIDField(primary_key=True, auto=True)
    name = models.CharField(max_length=255)
    settings_file = models.FileField(upload_to=upload_fn,
                                     null=True,
                                     blank=True,
                                     max_length=512)
    project = models.ForeignKey("rodan.Project",
                                related_name="classifier_settings")

    fitness = models.FloatField(null=True, blank=True)
    producer = models.ForeignKey('rodan.Classifier',
                                 related_name="classifier_settings",
                                 null=True,
                                 blank=True)

    optimization_started_at = models.DateTimeField(null=True, blank=True)
    optimization_finished_at = models.DateTimeField(null=True, blank=True)

    creator = models.ForeignKey("auth.User",
                                related_name="classifier_settings",
                                blank=True,
                                null=True)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    @property
    def file_path(self):
        return os.path.join(self.setting_directory,
                            "{0}.xml".format(str(self.uuid)))

    @property
    def file_url(self):
        if self.settings_file:
            return os.path.join(
                settings.MEDIA_URL,
                os.path.relpath(self.settings_file.path, settings.MEDIA_ROOT))

    def save(self, *args, **kwargs):
        super(ClassifierSetting, self).save(*args, **kwargs)
        if not os.path.exists(self.setting_directory):
            os.makedirs(self.setting_directory)

    def __unicode__(self):
        return u"<ClassifierSetting {0}>".format(str(self.name))

    class Meta:
        app_label = 'rodan'

    def delete(self, *args, **kwargs):
        if os.path.exists(self.settings_file.path):
            os.remove(self.settings_file.path)
        super(ClassifierSetting, self).delete(*args, **kwargs)
예제 #2
0
class Location(models.Model):
    """Administrative location (city, place everything with a name and Lat/Lng that
    is not intended to contain anything; use Areas for that).
    """
    NONE = 0
    COUNTRY = 10
    EXACT = 20

    ACCURACY = (
        (NONE, _('None')),
        (COUNTRY, _('Country')),
        (EXACT, _('Exact')))

    country = models.ForeignKey(Country, db_index=True)
    area = models.ForeignKey(AdministrativeArea, db_index=True, blank=True, null=True)
    type = models.ForeignKey(LocationType, blank=True, null=True)

    is_capital = models.BooleanField(default=False, help_text="True if is the capital of `country`")
    is_administrative = models.BooleanField(default=False, help_text="True if is administrative for `area`")
    uuid = UUIDField(auto=True, blank=False, version=1, help_text=_('unique id'), default="")

    name = models.CharField(_('Name'), max_length=255, db_index=True)
    loccode = models.CharField(_('UN LOCODE'), max_length=255, db_index=True, blank=True, null=True)
    iata = models.CharField(_('IATA code (if exists)'), max_length=255, db_index=True, blank=True, null=True)

    description = models.CharField(max_length=100, blank=True, null=True)
    lat = models.DecimalField(max_digits=18, decimal_places=12, blank=True, null=True)
    lng = models.DecimalField(max_digits=18, decimal_places=12, blank=True, null=True)
    acc = models.IntegerField(choices=ACCURACY, default=NONE, blank=True, null=True,
                              help_text="Define the level of accuracy of lat/lng infos")

    flags = BitField(flags=({0: 'unknown',
                             1: 'port',
                             2: 'rail_terminal',
                             3: 'road_terminal',
                             4: 'airport',
                             5: 'postal_exchange',
                             6: 'reserved',
                             7: 'reserved'}),
                     default=0)

    status = models.CharField(max_length=2,
                              blank=True, null=True,
                              choices=(
                                  ('AA', 'Approved by competent national government agency'),
                                  ('AC', 'Approved by Customs Authority'),
                                  ('AF', 'Approved by national facilitation body'),
                                  ('AI', 'Code adopted by international organisation (IATA or ECLAC)'),
                                  ('RL', 'Recognised location - Existence and representation of location name '
                                         'confirmed by check against nominated gazetteer or other reference work'),
                                  ('RN', 'Request from credible national sources for locations in their own country'),
                                  ('RQ', 'Request under consideration'),
                                  ('RR', 'Request rejected'),
                                  ('QQ', 'Original entry not verified since date indicated'),
                                  ('XX', 'Entry that will be removed from the next issue of UN/LOCODE'),
                              ))
    objects = LocationManager()


    class Meta:
        verbose_name_plural = _('Locations')
        verbose_name = _('Location')
        app_label = 'geo'
        ordering = ('name', 'country', )
        order_with_respect_to = 'country'
        unique_together = (('area', 'name'), )


    def __unicode__(self):
        return unicode(self.name)


    def natural_key(self):
        return (self.uuid.hex, )


    natural_key.dependencies = ['geo.administrativearea', 'geo.country', 'geo.locationtype']


    def clean(self):
        if self.area and self.area.country != self.country:
            raise ValidationError('Selected area not in selected country')
        super(Location, self).clean()
예제 #3
0
파일: models.py 프로젝트: JJ810/URPSM
class Client(models.Model):
    """
    Description: Client phone mobile
    """
    STATUS_CHOICES = (
        ('p', "Pending"),
        ('c', "Need Your Call"),
        ('r', "Ready"),
        ('n', "Can't Repaired"),
    )

    TODO_CHOICES = (
        ('r', "Repairing"),
        ('f', "Flashing"),
        ('u', "Unlocking"),
    )

    uuid = UUIDField(auto=True)
    # Adding model and brand
    brand = models.ForeignKey(Brand, related_name='client_brand')
    model = ChainedForeignKey(Model,
                              chained_field='brand',
                              chained_model_field='brand',
                              show_all=False,
                              auto_choose=True,
                              related_name="client_model")
    ref = models.CharField(max_length=50, unique=True)
    shop = models.ForeignKey(Shop, related_name='phone_shop')
    serial = models.CharField(max_length=255, blank=True, null=True)
    imei = models.CharField(max_length=255, validators=[validate_imei])
    phone_number = PhoneNumberField(help_text='eg: +212612345678')
    email = models.EmailField(blank=True, null=True)
    amount = models.DecimalField(
        max_digits=9,
        decimal_places=2,
        validators=[MinValueValidator(Decimal('0.00'))])

    status = models.CharField(max_length=64,
                              choices=STATUS_CHOICES,
                              default='p')
    status_description = models.TextField(blank=True, null=True)

    todo = models.CharField(max_length=64, choices=TODO_CHOICES, default='r')
    todo_description = models.TextField(blank=True, null=True)

    paid = models.BooleanField(default=False)
    paid_for = models.ForeignKey(User, null=True, blank=True)

    delivery_time = models.DateTimeField(null=True, blank=True)
    delivered_at = models.DateTimeField(null=True, blank=True)
    deleted = models.BooleanField(default=False)

    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    # class Meta:
    #     ordering = ['-created']

    def __str__(self):
        return unicode(self.shop)

    @property
    def subtotal(self):
        addons_amount = self.addons_phone.aggregate(
            addons=Sum('price'))['addons'] or 0
        return self.amount + addons_amount

    @property
    def vat(self):
        return (self.subtotal * self.shop.vat) / 100

    @property
    def total(self):
        return self.subtotal + self.vat

    @property
    def total_benefit(self):
        addons_amount = self.addons_phone.aggregate(
            addons=Sum('price'))['addons'] or 0
        addons_original_amount = self.addons_phone.aggregate(
            addons=Sum('original_price'))['addons'] or 0
        return self.amount + (addons_amount - addons_original_amount)

    @property
    def satisfied_clients_count(self):
        pass
예제 #4
0
class Country(models.Model):
    """ Model for the country of origin.
    """
    iso_code = models.CharField(max_length=2, unique=True, blank=False, null=False, db_index=True,
                                help_text='ISO 3166-1 alpha 2', validators=[MinLengthValidator(2)])
    iso_code3 = models.CharField(max_length=3, unique=True, blank=False, null=False, db_index=True,
                                 help_text='ISO 3166-1 alpha 3', validators=[MinLengthValidator(3)])
    iso_num = models.CharField(max_length=3, unique=True, blank=False, null=False,
                               help_text='ISO 3166-1 numeric', validators=[RegexValidator('\d\d\d')])
    uuid = UUIDField(auto=True, blank=False, version=1, help_text=_('unique id'), default="")

    undp = models.CharField(max_length=3, unique=True, blank=True, null=True,
                            help_text='UNDP code', validators=[MinLengthValidator(3)])

    nato3 = models.CharField(max_length=3, unique=True, blank=True, null=True,
                             help_text='NATO3 code', validators=[MinLengthValidator(3)])

    fips = models.CharField(max_length=255, blank=True, null=True,
                            help_text='fips code')

    itu = models.CharField(max_length=255, blank=True, null=True,
                           help_text='ITU code')

    icao = models.CharField(max_length=255, blank=True, null=True, help_text='ICAO code')

    name = models.CharField(max_length=100, db_index=True)

    fullname = models.CharField(max_length=100, db_index=True)

    region = models.ForeignKey(UNRegion, blank=True, null=True, default=None)
    continent = models.CharField(choices=CONTINENTS, max_length=2)
    currency = models.ForeignKey(Currency, blank=True, null=True)

    tld = models.CharField(help_text='Internet tld', max_length=5, blank=True, null=True)
    phone_prefix = models.CharField(help_text='Phone prefix number', max_length=20, blank=True, null=True)

    timezone = TimeZoneField(blank=True, null=True, default=None)
    expired = models.DateField(blank=True, null=True, default=None)

    lat = models.DecimalField("Latitude", max_digits=18, decimal_places=12, blank=True, null=True)
    lng = models.DecimalField("Longitude", max_digits=18, decimal_places=12, blank=True, null=True)

    last_update = models.DateTimeField(auto_now=True)

    fullname.alphabetic_filter = True
    objects = CountryManager()


    class Meta:
        app_label = 'geo'
        verbose_name_plural = _('Countries')
        ordering = ['name']

    def __unicode__(self):
        return u"%s (%s)" % (self.fullname, self.iso_code)

    def clean(self):
        super(Country, self).clean()
        self.iso_code = self.iso_code.upper()
        self.iso_code3 = self.iso_code3.upper()

    def natural_key(self):
        return (self.uuid.hex, )

    def __contains__(self, item):
        if hasattr(item, 'country'):
            return item.country.iso_code == self.iso_code

    def sub(self, type):
        return self.areas.filter(type__name=type)