class ActiveRegion(models.Model): country = models.CharField(max_length=40, verbose_name="Country", blank=True, null=True) region = models.CharField(max_length=40, verbose_name="Region", blank=True, null=True) region_abbr = models.CharField(max_length=3, verbose_name="Region abbreviation", blank=True, null=True) slugged_region = autoslug.AutoSlugField(max_length=400, verbose_name="Slugged Region", blank=True, null=True) slugged_region_abbr = autoslug.AutoSlugField( max_length=40, verbose_name="Slugged Region Abbr", blank=True, null=True) def save(self, *args, **kwargs): self.slugged_region = self.region self.slugged_region_abbr = self.region_abbr super(ActiveRegion, self).save(*args, **kwargs) def __unicode__(self): return self.region
class VpnProfile(models.Model): profilename = models.CharField(max_length=32) config = models.TextField() creation_date = models.DateField(auto_now_add=True) # first slug - this field is used to reference the object, e.g. when creating a download link or when deleting slug = autoslug.AutoSlugField(unique=True, populate_from=utils.secure_random_id) # second slug - this field is used for the download link download_slug = autoslug.AutoSlugField(unique=True, populate_from=utils.secure_random_id, always_update=True, null=True) download_valid_until = models.DateTimeField(null=True) dyndomain = models.CharField(max_length=256) class Meta: ordering = ["creation_date"]
class Milestone(AccessControlShortcutMixin, ActiveStateMixin, TimestampMixin, models.Model): """ Stores information related to short-term project goals. """ due_date = models.DateField() name = models.CharField(_('name'), max_length=45) slug = autoslug.AutoSlugField(_('slug'), populate_from='name') description = fields.RichTextField(_('description'), blank=True) investigation = models.ForeignKey(Investigation, related_name='milestones', related_query_name='milestone', null=True) class Meta: verbose_name = _('milestone') verbose_name_plural = _('milestones') @property def owner_group(self): return self.investigation.owner_group @property def member_group(self): return self.investigation.member_group @property def viewer_group(self): return self.investigation.viewer_group def __str__(self): return self.name
class Investigation(AccessControlShortcutMixin, ActiveStateMixin, TimestampMixin, models.Model): """ Stores information on an individual investigation related to one or more projects. """ name = models.CharField(_('name'), max_length=45) slug = autoslug.AutoSlugField(_('slug'), populate_from='name') description = fields.RichTextField(_('description'), blank=True) project = models.ForeignKey(Project, verbose_name=_('project'), related_name='investigations', related_query_name='investigation') class Meta: verbose_name = _('investigation') verbose_name_plural = _('investigations') @property def owner_group(self): return self.project.owner_group @property def member_group(self): return self.project.member_group @property def viewer_group(self): return self.project.viewer_group def __str__(self): return self.name
class Project(AccessControlShortcutMixin, ActiveStateMixin, TimestampMixin, models.Model): """ Stores information on a project, which is a higher level organizational tool. """ name = models.CharField(_('name'), max_length=45) slug = autoslug.AutoSlugField(_('slug'), populate_from='name') description = fields.RichTextField(_('description'), blank=True) owner_group = models.ForeignKey(Group, verbose_name=_('owner_group'), related_name='+', blank=True, null=True) member_group = models.ForeignKey(Group, verbose_name=_('member_group'), related_name='+', blank=True, null=True) viewer_group = models.ForeignKey(Group, verbose_name=_('viewer_group'), related_name='+', blank=True, null=True) class Meta: verbose_name = _('project') verbose_name_plural = _('projects') def __str__(self): return self.name def milestones(self): investigation_ids = self.investigations.values_list('id', flat=True) return Milestone.objects.filter(investigation_id__in=investigation_ids)
class Base(models.Model): """ Base model with boilerplate for all models. """ name = models.CharField(max_length=200, db_index=True) name_ascii = models.CharField(max_length=200, blank=True, db_index=True) slug = autoslug.AutoSlugField(populate_from='name_ascii') geoname_id = models.IntegerField(null=True, blank=True, unique=True) alternate_names = models.TextField(null=True, blank=True, default='') location_map = models.MultiPolygonField(null=True) class Meta: abstract = True ordering = ['name'] def __str__(self): display_name = getattr(self, 'display_name', None) if display_name: return display_name return self.name def save(self, *args, **kwargs): # https://gis.stackexchange.com/questions/13498/generalizing-polygons-to-multipolygons-in-geodjango # if location_map ends up as a Polygon, make it into a MultiPolygon if self.location_map and isinstance(self.location_map, geos.Polygon): self.location_map = geos.MultiPolygon(self.location_map) super().save(*args, **kwargs)
class Base(models.Model): """ Base model with boilerplate for all models. """ name_ascii = models.CharField(max_length=200, blank=True, db_index=True) slug = autoslug.AutoSlugField(populate_from='name_ascii') geoname_id = models.IntegerField(null=True, blank=True, unique=True) alternate_names = models.TextField(null=True, blank=True, default='') state = models.SmallIntegerField(verbose_name=_('Publish state'), choices=STATE_TYPES, default=1) default_language = models.CharField(max_length=2, choices=settings.LANGUAGES, default='en', verbose_name=_('Default language')) class Meta: abstract = True # ordering = ['name'] def __str__(self): display_name = getattr(self, 'display_name', None) if display_name: return display_name return self.name
class Sensor(models.Model): """ Sensors which can be in a room or outside house. We may not know the exact room of the sensor, such a sensor should be placed into 'outside' room. Sensors data comes from the third party API, hence it's important to maintain 'slug' to be equal to the slugs in the API. See README for more details To add more info on the sensor, fill in name and description. For example: name='humidity inside' description='humidity sensor in the basement on the northern wall' Slug is used for internal lookups, not connected to the third party API. """ name = models.CharField(max_length=30) description = models.CharField(max_length=100, null=True, blank=True) slug = autoslug.AutoSlugField(populate_from='name', unique=True) sensor_type = models.ForeignKey('SensorType', on_delete=models.PROTECT) room = models.ForeignKey('Room', related_name='sensors', on_delete=models.CASCADE) def __str__(self): if self.room: return f'{self.name} sensor in the {self.room}' return f'{self.name} sensor'
class Topic(models.Model): """A political topic Political topic is a point of interest around a topic. Attributes ---------- default_body : Body Many government bodies can work on a same topic, but usually one topic is bound to a particular government body. This parameter specifies which political body is most relevant for this topic. """ created = CreationDateTimeField() slug = autoslug.AutoSlugField(populate_from='title') title = models.CharField(_("Pavadinimas"), max_length=255) description = models.TextField(_("Aprašymas"), blank=True) indicators = models.ManyToManyField(Indicator, blank=True) default_body = models.ForeignKey(Body, null=True, blank=True, on_delete=models.SET_NULL) logo = ImageField(upload_to='topics/%Y/%m/%d/', blank=True) def __str__(self): return self.title def get_absolute_url(self): return reverse('topic-details', args=[self.pk, self.slug])
class LocalGroup(models.Model): slug = autoslug.AutoSlugField(populate_from="name", unique=True) name = models.CharField(max_length=100) is_active = models.BooleanField(default=True) is_public = models.BooleanField(default=True) organisers = models.ManyToManyField( settings.AUTH_USER_MODEL, through="Organisership", blank=True ) local_group_type = enum.EnumField( LocalGroupType, null=True, blank=True, default=None ) city_or_town = models.CharField(max_length=100, blank=True) country = models.CharField(max_length=100, blank=True) lat = models.FloatField(null=True, blank=True, default=None) lon = models.FloatField(null=True, blank=True, default=None) website = models.URLField(blank=True) facebook_group = models.URLField(blank=True) facebook_page = models.URLField(blank=True) email = models.EmailField(blank=True) meetup_url = models.URLField(blank=True) airtable_record = models.CharField( max_length=255, null=True, blank=True, default=None, unique=True, validators=[validators.MinLengthValidator(1)], ) last_edited = models.DateTimeField( auto_now=True, null=True, blank=True, editable=False ) objects = LocalGroupManager() class Meta: ordering = ["name", "slug"] def __str__(self): return self.name def get_absolute_url(self): return urls.reverse("group", args=[self.slug]) def public_organisers(self): return self.organisers.filter(profile__is_public=True).order_by( "profile__name", "profile__slug" ) def geocode(self): self.lat = None self.lon = None if self.city_or_town and self.country: location = geocoders.Nominatim(timeout=10).geocode( f"{self.city_or_town}, {self.country}" ) if location: self.lat = location.latitude self.lon = location.longitude
class Project(models.Model): """ OCR Project model. """ name = models.CharField(max_length=255, unique=True) slug = autoslug.AutoSlugField(populate_from="name", unique=True) description = models.TextField(blank=True) tags = taggingfields.TagField() storage_backend = models.CharField(max_length=255, choices=[(k, k) for k in registry.stores.keys()]) created_on = models.DateTimeField(editable=False) updated_on = models.DateTimeField(blank=True, null=True, editable=False) def __unicode__(self): """ String representation. """ return self.name def storage_config_dict(self): """Return a dictionary of storage config values.""" return dict([(c.name, c.value) \ for c in self.storage_config_values.all()]) def get_storage(self): backend = registry.stores[self.storage_backend] return backend(**self.storage_config_dict()) def save(self): if not self.id: self.created_on = datetime.datetime.now() else: self.updated_on = datetime.datetime.now() super(Project, self).save() def get_absolute_url(self): """URL to view an object detail""" return "/projects/show/%i/" % self.id def get_update_url(self): """url to update an object detail""" return "/projects/edit/%i/" % self.id def get_delete_url(self): """url to update an object detail""" return "/projects/delete/%i/" % self.id @classmethod def get_list_url(cls): """URL to view the object list""" return "/projects/list/" @classmethod def get_create_url(cls): """URL to create a new object""" return "/projects/create/"
class Post(models.Model): author = models.ForeignKey(User, related_name='posts') title = models.CharField(max_length=255) slug = autoslug.AutoSlugField(populate_from='title') category = models.ForeignKey(Category, related_name='posts') content = RichTextUploadingField() create_at = models.DateTimeField(auto_now=True) def __str__(self): return self.title
class Agent(models.Model): created = CreationDateTimeField() modified = ModificationDateTimeField() user = models.ForeignKey(auth_models.User) slug = autoslug.AutoSlugField(populate_from='title', unique=True) title = models.CharField(_("Pavadinimas/Vardas"), max_length=255) individual = models.BooleanField(default=True) active = models.BooleanField(default=False) def __str__(self): return self.title
class NameSlugModel(models.Model): """Object that has a name field from which a slug is automatically generated.""" name = models.CharField(max_length=100, unique=True) slug = autoslug.AutoSlugField(populate_from="name", unique=True) class Meta: abstract = True def __unicode__(self): """String representation.""" return self.name
class Topic(models.Model): created = CreationDateTimeField() modified = ModificationDateTimeField() author = models.ForeignKey(User, null=True, blank=True) slug = autoslug.AutoSlugField(populate_from='title') title = models.CharField(_("Pavadinimas"), max_length=255) description = models.TextField(_("Aprašymas"), blank=True) def __str__(self): return self.title def get_absolute_url(self): return reverse('topic-details', args=[self.slug])
class TinyContentFileUpload(models.Model): name = models.CharField(max_length=60, help_text='The name of the file.') slug = autoslug.AutoSlugField(populate_from='name', unique=True) file = models.FileField(upload_to='tinycontent/uploads') created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) def __str__(self): return self.name class Meta: verbose_name = 'File upload' ordering = ('-created', )
class Base(models.Model): name = models.CharField(null=True, blank=True, max_length=200) slug = autoslug.AutoSlugField(null=True, blank=True, populate_from="name") created = models.DateTimeField(blank=True) updated = models.DateTimeField(blank=True) def save(self, *args, **kwargs): if not self.created: self.created = datetime.datetime.now() self.updated = datetime.datetime.now() super(Base, self).save(*args, **kwargs) class Meta: abstract = True
class Group(models.Model): """Mainly used for comparison page. Only members of Group are compared in comparison page. """ slug = autoslug.AutoSlugField(populate_from='title') title = models.CharField(max_length=255) timestamp = models.DateTimeField() members = models.ManyToManyField(Actor, related_name='ingroups', related_query_name='ingroup') def __str__(self): return self.title
class Tariff(models.Model): name = models.CharField(max_length=255) slug = autoslug.AutoSlugField(populate_from='name') price = models.PositiveIntegerField() description = models.TextField() benefits = models.ManyToManyField(Benefits) class Meta: ordering = ('price', ) verbose_name = u'Тариф' verbose_name_plural = u'Тарифы' def __unicode__(self): return u'{}'.format(self.name)
class Preset(models.Model): user = models.ForeignKey(User, related_name="presets") tags = tagging.fields.TagField() name = models.CharField(max_length=100, unique=True) slug = autoslug.AutoSlugField(populate_from="name", unique=True) description = models.TextField(blank=True) public = models.BooleanField(default=True) created_on = models.DateField(editable=False) updated_on = models.DateField(editable=False, null=True, blank=True) data = JsonTextField() profile = models.ForeignKey("Profile", related_name="presets", null=True, blank=True) def __unicode__(self): """ String representation. """ return self.name def save(self): if not self.id: self.created_on = datetime.datetime.now() else: self.updated_on = datetime.datetime.now() super(Preset, self).save() def get_absolute_url(self): """URL to view an object detail""" return "/presets/show/%s/" % self.slug def get_update_url(self): """url to update an object detail""" return "/presets/edit/%s/" % self.slug def get_delete_url(self): """url to update an object detail""" return "/presets/delete/%s/" % self.slug @classmethod def get_list_url(cls): """URL to view the object list""" return "/presets/list/" @classmethod def get_create_url(cls): """URL to create a new object""" return "/presets/create/"
class SensorType(models.Model): """ Types of the sensors with their units of measure. """ name = models.CharField(max_length=30, unique=True) description = models.CharField(max_length=100, null=True, blank=True) slug = autoslug.AutoSlugField(populate_from='name', unique=True) display_symbol = models.CharField(max_length=5, help_text='Unit of measure') def __str__(self): return f'{self.name} sensor' class Meta: db_table = 'api_sensor_type'
class Person(models.Model): PROFESSION_CHOICES = [('', 'Nenurodyta')] + [ (profession, profession.title()) for profession in professions ] slug = autoslug.AutoSlugField(populate_from='name') name = models.CharField(max_length=255) profession = models.CharField(max_length=64, blank=True, choices=PROFESSION_CHOICES) objects = PersonManager() def __str__(self): return self.name
class Article(models.Model): name = models.CharField(max_length=100, verbose_name=_(u'title')) slug = autoslug.AutoSlugField(populate_from='name', unique=True) creation_user = models.ForeignKey('auth.User') creation_datetime = models.DateTimeField(auto_now_add=True) modification_datetime = models.DateTimeField(auto_now=True) text = models.TextField() def __unicode__(self): return self.name def get_absolute_url(self): return urlresolvers.reverse('article_detail', args=(self.slug, ))
class Extension(models.Model): name = models.CharField(max_length=200) uuid = models.CharField(max_length=200, unique=True, db_index=True) slug = autoslug.AutoSlugField(populate_from="name") creator = models.ForeignKey(User, db_index=True) description = models.TextField(blank=True) url = models.URLField(blank=True) created = models.DateTimeField(auto_now_add=True) downloads = models.PositiveIntegerField(default=0) popularity = models.IntegerField(default=0) class Meta: permissions = (("can-modify-data", "Can modify extension data"), ) screenshot = models.ImageField(upload_to=make_screenshot_filename, blank=True) icon = models.ImageField(upload_to=make_icon_filename, blank=True, default="/static/images/plugin.png") objects = ExtensionManager() def __unicode__(self): return self.uuid def parse_metadata_json(self, metadata): self.name = metadata.pop('name', "") self.description = metadata.pop('description', "") self.url = metadata.pop('url', "") self.uuid = metadata['uuid'] def clean(self): from django.core.exceptions import ValidationError if not validate_uuid(self.uuid): raise ValidationError("Your extension has an invalid UUID") def save(self, replace_metadata_json=True, *args, **kwargs): super(Extension, self).save(*args, **kwargs) if replace_metadata_json: for version in self.versions.all(): if version.source: try: version.replace_metadata_json() except BadZipfile, e: # Ignore bad zipfiles, we don't care pass
class Project(models.Model): created = CreationDateTimeField() modified = ModificationDateTimeField() user = models.ForeignKey(auth_models.User) agent = models.ForeignKey(Agent, verbose_name=_("Organizacija/Asmnuo")) slug = autoslug.AutoSlugField(populate_from='title', unique_with='agent') title = models.CharField(_("Pavadinimas"), max_length=255) description = models.TextField(_("Aprašymas")) datasets = models.ManyToManyField(Dataset, verbose_name=_("Duomenų šaltiniai")) likes = models.PositiveIntegerField(default=0) def __str__(self): return self.title def get_absolute_url(self): return reverse('project-details', args=[self.agent.slug, self.slug])
class DeviceEntry(models.Model): ip = models.CharField(max_length=20, unique=False) mac = models.CharField(max_length=20, null=False, unique=True) dhcp_fingerprint = models.CharField(max_length=256, null=True) dhcp_vendor = models.CharField(max_length=256, null=True) user_agent = models.ManyToManyField(UserAgent) hostname = models.CharField(max_length=256, null=True) MODES = (('SL', "Silent"), ('NJ', "Ninja"), ('NO', "No Mode")) mode = models.CharField(max_length=2, choices=MODES, default='SL') chosen_name = models.CharField(max_length=256, null=True) slug = autoslug.AutoSlugField(unique=True, populate_from=utils.secure_random_id, always_update=False, null=True) changing = models.NullBooleanField(null=True, default=False) last_seen = models.DateTimeField(default=timezone.now) objects = DeviceManager()
class Article(models.Model): uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) headline = models.CharField(max_length=200, blank=True) byline = models.CharField(max_length=100, blank=True) body = models.TextField(blank=True) pitch = models.TextField(blank=True) disclosure = models.TextField(blank=True) promo = models.CharField(max_length=200, blank=True) # Using default instead of auto_add_now since I'll be loading the articles from a fixture. created = models.DateTimeField(default=timezone.now) publish_at = models.DateTimeField(default=timezone.now, null=True) modified = models.DateTimeField(null=True, default=timezone.now) authors = models.ManyToManyField( Author, through='AuthorArticle', related_name='articles') images = models.ManyToManyField( Image, related_name='articles' ) slug = autoslug.AutoSlugField( populate_from='headline', unique_with='publish_at', blank=True) tags = tagulous.models.TagField() # For the scope of this project, I omitted a few things. That I wasn't # using like: video, collections, bureau. def __str__(self): return self.headline def get_absolute_url(self): return reverse( 'article-detail', kwargs={ 'year': self.publish_at.year, 'month': int(self.publish_at.strftime('%m').lower()), 'day': self.publish_at.day, 'slug': self.slug, }, )
class Base(models.Model): """ Base model with boilerplate for all models. """ name_ascii = models.CharField(max_length=200, blank=True, db_index=True) slug = autoslug.AutoSlugField(populate_from='name_ascii') geoname_id = models.IntegerField(null=True, blank=True, unique=True) alternate_names = models.TextField(null=True, blank=True, default='') class Meta: abstract = True ordering = ['name'] def __str__(self): display_name = getattr(self, 'display_name', None) if display_name: return display_name return self.name
class Dataset(models.Model): NO_DATA = 0 OPEN_LICENCE = 1 STRUCTURED_DATA = 2 OPEN_FORMAT = 3 USES_URIS = 4 LINKED_DATA = 5 MATURITY_LEVEL_CHOICES = ( (NO_DATA, _('0. Duomenys nėra pateikti')), (OPEN_LICENCE, _('1. Atvira licencija')), (STRUCTURED_DATA, _('2. Struktūruoti duomenys')), (OPEN_FORMAT, _('3. Atviras formatas')), (USES_URIS, _('4. Adresuojami duomenys')), (LINKED_DATA, _('5. Susietieji duomenys')), ) created = CreationDateTimeField() modified = ModificationDateTimeField() user = models.ForeignKey(auth_models.User) agent = models.ForeignKey(Agent, verbose_name=_("Organizacija"), null=True) slug = autoslug.AutoSlugField(populate_from='title', unique_with='agent') title = models.CharField(_("Pavadinimas"), max_length=255) description = models.TextField(_("Aprašymas"), blank=True) sources = models.ManyToManyField( 'self', symmetrical=False, related_name='datasets', verbose_name=_("Pirminiai duomenų šaltiniai")) maturity_level = models.PositiveSmallIntegerField( _("Brandos lygis"), choices=MATURITY_LEVEL_CHOICES) link = models.URLField( _("Nuoroda"), blank=True, help_text=_( "Nuoroda į vietą internete, kur pateikiami duomenys ar informacija " "apie duomenis.")) likes = models.PositiveIntegerField(default=0) def __str__(self): return self.title def get_absolute_url(self): return reverse('dataset-details', args=[self.agent.slug, self.slug])
class Project(dj_models.TimeStampedModel): name = models.CharField(max_length=255, blank=True, null=True) api_key = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) created_by = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True) slug = autoslug.AutoSlugField(populate_from='name', unique=True) rms_url = models.CharField( help_text='Repository Management Service (Github, Bitbucket, etc)', max_length=255, blank=True, null=True) def __str__(self): return '<Project: {}>'.format(self.name) def __repr__(self): return self.__str__()