Esempio n. 1
0
class Token(models.Model):
    link = models.ForeignKey(ApplicationLink)
    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             related_name="%(app_label)s_%(class)s_user",
                             help_text="User token authenticates as")
    url = models.TextField(help_text="Suburl this token is restricted to, "
                           "relative e.g. (/my/single/service/entrypoint)",
                           default="/")
    secret = models.CharField(max_length=320,
                              help_text="Token Secret",
                              unique=True)
    modified = models.DateTimeField(default=timezone.now, editable=False)
    timeout = models.IntegerField(default=600,
                                  help_text="Timeout token in "
                                  "seconds, 0 means never times out")

    class Meta:
        app_label = 'swingers'

    def save(self, *args, **kwargs):
        try:
            revision.unregister(self.__class__)
        except:
            pass
        super(Token, self).save(*args, **kwargs)

    def natural_key(self):
        return (self.secret, )

    def get_by_natural_key(self, secret):
        return self.get(secret=secret)

    def __str__(self):
        return "{0} - {1}:{2}@{3}".format(self.pk, self.user, self.secret,
                                          self.link.client_name)[:320]
Esempio n. 2
0
class Acknowledgement(models.Model):
    burn = models.ForeignKey('PrescribedBurn',
                             related_name='acknowledgements',
                             on_delete=models.PROTECT)
    user = models.ForeignKey(User,
                             help_text="User",
                             null=True,
                             blank=True,
                             on_delete=models.PROTECT)
    acknow_type = models.CharField(max_length=64, null=True, blank=True)
    acknow_date = models.DateTimeField(auto_now_add=True,
                                       null=True,
                                       blank=True)

    fmt = "%d/%m/%Y %H:%M"

    @property
    def record(self):
        username = '******'.format(self.user.first_name[0], self.user.last_name)
        return "{} {}".format(
            username,
            self.acknow_date.astimezone(tz.tzlocal()).strftime(self.fmt))

    def remove(self):
        self.delete()

    def __str__(self):
        return "{} - {} - {}".format(self.burn, self.acknow_type, self.record)
Esempio n. 3
0
class SignInspection(Audit):
    way = models.ForeignKey(
        Way, verbose_name="Road/Track/Trail Name", on_delete=models.PROTECT)
    inspected = models.DateTimeField(
        default=timezone.now, verbose_name="Date Inspected")
    comments = models.TextField()
    inspector = models.TextField(verbose_name="Inspecting Officer")

    def __str__(self):
        return "%s (%s)" % (self.way.name, date(self.inspected))

    @property
    def prescription(self):
        return self.way.prescription

    class Meta:
        ordering = ['id']
        verbose_name = "Sign Inspection"
        verbose_name_plural = "Sign Inspections"
Esempio n. 4
0
class BurnState(models.Model):
    prescription = models.ForeignKey(Prescription,
                                     related_name='burnstate',
                                     on_delete=models.PROTECT)
    user = models.ForeignKey(User, help_text="User", on_delete=models.PROTECT)
    review_type = models.CharField(max_length=64)
    review_date = models.DateTimeField(auto_now_add=True)

    fmt = "%d/%m/%Y %H:%M:%S"

    @property
    def record(self):
        username = '******'.format(self.user.first_name[0], self.user.last_name)
        return "{} {}".format(
            username,
            self.review_date.astimezone(tz.tzlocal()).strftime(self.fmt))

    def __str__(self):
        return "{} - {} - {}".format(self.prescription, self.review_type,
                                     self.record)
Esempio n. 5
0
class Document(Audit):
    prescription = models.ForeignKey(
        Prescription, null=True,
        help_text="Prescription that this document belongs to", on_delete=models.PROTECT)
    category = models.ForeignKey(DocumentCategory, related_name="documents", on_delete=models.PROTECT)
    tag = ChainedForeignKey(
        DocumentTag, chained_field="category", chained_model_field="category",
        show_all=False, auto_choose=True, verbose_name="Descriptor", on_delete=models.PROTECT)
    custom_tag = models.CharField(
        max_length=64, blank=True, verbose_name="Custom Descriptor")
    document = ContentTypeRestrictedFileField(
        upload_to=content_file_name, max_length=200,
        content_types=['application/pdf', 'image/tiff', 'image/tif',
                       'image/jpeg', 'image/jpg', 'image/gif', 'image/png',
                       'application/zip', 'application/x-zip-compressed'],
        help_text='Acceptable file types: pdf, tiff, jpg, gif, png, zip')

    document_created = models.DateTimeField(
        verbose_name="Date Document Created", default=timezone.now, editable=True, null=True, blank=True)

    document_archived = models.BooleanField(default=False, verbose_name="Archived Document")

    objects = TagManager()

    def save(self, *args, **kwargs):
        super(Document, self).save(*args, **kwargs)
        # confirm that file is written to filesystem, if not remove the record
        if not self.exists:
            fname = self.document.name
            Document.objects.get(id=self.id).delete()
            raise Exception('ERROR: File not created on filesystem {}'.format(fname))
        return

    @property
    def descriptor(self):
        if self.custom_tag:
            return "Other ({0})".format(self.custom_tag)
        else:
            return self.tag.name

    @property
    def dimensions(self):
        return get_dimensions(self.document.path)

    @property
    def filename(self):
        try:
            return os.path.basename(self.document.path)
        except:
            return None

    @property
    def exists(self):
        """
        Check if file exists on the file system
        """
        try:
            return os.path.exists(self.document.file.name)
        except:
            return False


    @property
    def is_zipped(self):
        return self.filename.endswith('.zip')

    class Meta:
        ordering = ['tag', 'document']
        permissions = (
            ("archive_document", "Can archive documents")
        )

    def __str__(self):
        return "{0} - {1}".format(self.prescription, self.document.name)