Beispiel #1
0
class ProductImage(models.Model):
    image = ImageWithThumbsField(
        upload_to=MediaFileNameHash("shop_image"),
        default=None,
        sizes=((320, 180), (145, 145), (711, 400),),
        preserve_ratio=True,
        verbose_name=_("Address")
    )
    size = models.CharField(max_length=150, default="", blank=True, null=True)
    product = models.ForeignKey(to=Product, verbose_name=_("Product"))
    archive = models.BooleanField(default=False, verbose_name=_("Archive"))

    class Meta:
        verbose_name = _("Product Image")
        verbose_name_plural = _("Product Images")

    def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
        if self.id is None:
            self.size = self.image.size
            try:
                self.title = self.image.name.split("@")[0]
            except:
                pass

        super(ProductImage, self).save()

    def image_tag(self):
        return u'<img src="/{0}" style="{1}" {2}/>'.format(self.image.url, "width: 100%", 'height=150')

    image_tag.allow_tags = True
Beispiel #2
0
class ProductFile(models.Model):
    file = models.FileField(
        upload_to=MediaFileNameHash("shop_files"),
        verbose_name=_("File")
    )
    product = models.ForeignKey(to=Product, verbose_name=_("Product"))
    size = models.CharField(max_length=150, default="", blank=True, null=True)
    title = models.CharField(max_length=150, default="", blank=True, null=True)
    duration = models.TimeField(blank=True, null=True)
    archive = models.BooleanField(default=False, verbose_name=_("Archive"))

    class Meta:
        verbose_name = _("File Product")
        verbose_name_plural = _("File Products")

    def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
        if self.id is None:
            try:
                self.title = self.file.name.split("@")[0]
            except:
                pass
            self.size = self.file.size

        super(ProductFile, self).save()
        # get file format
        file_format = self.file.name.split(".")[-1].upper()
        if file_format in ['MP4', 'FLV', 'MOV', 'AVI', 'MPEG', 'WMV', '3GP', 'VOB', 'MPG', 'MP3', 'M4A', 'OGG', 'WMA']:
            # get duration for video or audio
            self.duration = get_video_duration(self.file.path)
            super(ProductFile, self).save()
Beispiel #3
0
class FileActivity(models.Model):
    file = models.FileField(upload_to=MediaFileNameHash("files"),
                            verbose_name=_("Address"))
    activity = models.ForeignKey(to=Activity, verbose_name=_("Activity"))
    status = models.BooleanField(default=False, verbose_name=_("Accept"))
    size = models.CharField(max_length=150, default="", blank=True, null=True)
    title = models.CharField(max_length=150, default="", blank=True, null=True)
    comment = models.TextField(null=True,
                               blank=True,
                               verbose_name=_("Comment"))
    archive = models.BooleanField(default=False, verbose_name=_("Archive"))

    def file_link(self):
        return "<a href='/{0}' style='margin-right: 2%'>{1}</a>".format(
            self.file.url, _("Download"))

    file_link.allow_tags = True

    class Meta:
        verbose_name = _("FileActivity")
        verbose_name_plural = _("FileActivity")

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if self.id is None:
            try:
                self.title = self.file.name.split("@")[0]
            except:
                pass
            self.size = self.file.size

        super(FileActivity, self).save()
Beispiel #4
0
class Announcement(models.Model):
    title = models.CharField(max_length=255,
                             verbose_name=_("Announcement Title"))
    description = models.TextField(verbose_name=_("Announcement Description"))
    image = models.ImageField(upload_to=MediaFileNameHash("images"),
                              default=None,
                              verbose_name=_("Image"),
                              null=True,
                              blank=True)
    creator = models.ForeignKey(to=User,
                                verbose_name=_("User"),
                                null=True,
                                blank=True)
    has_date = models.BooleanField(verbose_name=_("Has Date"), default=False)
    date = models.DateTimeField(verbose_name=_("Date"), null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True,
                                      verbose_name=_("Created at"))
    updated_at = models.DateTimeField(auto_now=True,
                                      verbose_name=_("Updated at"))
    view_count = models.IntegerField(default=0)
    release_time = models.DateTimeField(verbose_name=_("Release Time"),
                                        null=True)

    def get_files(self):
        values = AnnouncementFile.objects.filter(announcement_id=self.id)
        return values

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = _("Announcement")
        verbose_name_plural = _("Announcements")
Beispiel #5
0
class School(TimeStampedModel):
    name = models.CharField(max_length=45, null=True, blank=True)
    gender = models.CharField(max_length=10, choices=static.gender_choice, default=None, null=True, blank=True)
    active = models.BooleanField(default=False)
    teacher = models.ForeignKey(to=Teacher)
    code_bagheri = models.CharField(max_length=45)

    camp = models.ForeignKey(to=Camp, verbose_name=_("Camp"), null=True, blank=True)
    county = models.ForeignKey(to=County, verbose_name=_("County"))
    province = models.ForeignKey(to=Province, verbose_name=_("Province"))

    voters = models.PositiveIntegerField(default=0, verbose_name=_("Voters"))
    image = models.ImageField(
        upload_to=MediaFileNameHash("images"),
        verbose_name=_("rank"),
        null=True,
        blank=True
    )

    student_count = models.PositiveIntegerField(verbose_name=_("Student Count"), default=0)
    anjoman_count = models.PositiveIntegerField(verbose_name=_("Anjoman Count"), default=0)
    point = models.PositiveIntegerField(default=0, verbose_name=_("Point"))
    rank = models.PositiveIntegerField(default=0, verbose_name=_("Rank"))
    province_rank = models.PositiveIntegerField(default=0, verbose_name=_("Province Rank"))
    county_rank = models.PositiveIntegerField(default=0, verbose_name=_("County Rank"))

    def __str__(self):
        return self.name

    class Meta:
        ordering = ['name']
        verbose_name = _("School")
        verbose_name_plural = _("School")
Beispiel #6
0
class ApkRelease(models.Model):
    type_choice = (
        ('student', 'student'),
        ('teacher', 'teacher'),
        ('hamraz', 'hamraz'),
    )
    version = models.FloatField(verbose_name=_("Version"))
    title = models.CharField(max_length=255, verbose_name=_("Title"))
    message = models.TextField(verbose_name=_("Message"))
    type = models.CharField(max_length=10,
                            choices=type_choice,
                            verbose_name=_("Type App"))
    file = models.FileField(upload_to=MediaFileNameHash("files"),
                            validators=[validate_file_extension],
                            verbose_name=_("Address"))
    allow_run_app = models.BooleanField(default=False)
    force_update = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True,
                                      null=True,
                                      blank=True,
                                      verbose_name=_("Created at"))

    def __str__(self):
        return str(self.version)

    class Meta:
        verbose_name = _("Apk Release")
        verbose_name_plural = _("Apk Release")
Beispiel #7
0
class File(models.Model):
    title = models.CharField(max_length=255, verbose_name=_("Title"))
    obj = models.FileField(upload_to=MediaFileNameHash('files'),
                           default=None,
                           verbose_name=_("Obj"))
    file_size = models.PositiveIntegerField(default=0,
                                            verbose_name=_("File size"))
    gender = models.CharField(max_length=1,
                              default=None,
                              verbose_name=_("Gender"))

    def save(self, *args, **kwargs):
        self.image_size = self.obj.size
        super(File, self).save(*args, **kwargs)

    def delete(self, using=None, keep_parents=False):
        remove_file(self.obj.path)
        super(File, self).delete(using=using, keep_parents=keep_parents)

    @property
    def image_size_readable(self):
        return sizeof_fmt(self.image_size)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = _("File")
        verbose_name_plural = _("Files")
Beispiel #8
0
class ImageActivity(models.Model):
    image = ImageWithThumbsField(upload_to=MediaFileNameHash("images"),
                                 default=None,
                                 sizes=(
                                     (320, 180),
                                     (145, 145),
                                     (711, 400),
                                 ),
                                 preserve_ratio=True,
                                 verbose_name=_("Address"))
    size = models.CharField(max_length=150, default="", blank=True, null=True)
    title = models.CharField(max_length=150, default="", blank=True, null=True)
    activity = models.ForeignKey(to=Activity, verbose_name=_("Activity"))
    status = models.BooleanField(default=False, verbose_name=_("Accept"))
    archive = models.BooleanField(default=False, verbose_name=_("Archive"))
    comment = models.TextField(null=True,
                               blank=True,
                               verbose_name=_("Comment"))

    def image_med(self):
        """تابع نمایش عکس کوچک در صفحه ادمین جنگو"""
        if "jpg" in self.image.url:
            img = self.image.url.replace(".jpg", ".711x400.jpg")
        else:
            img = self.image.url.replace(".jpeg", ".711x400.jpeg")
        return u'<img src="/{0}" style="{1}" {2}/>'.format(
            img, "width: 100%", 'height=150')
        # return u'<a href="'+self.image.url+'"><img src="/{0}" style="{1}" {2}/>'.format(img, "width: 100%", 'height=150')+"</a>"

    image_med.allow_tags = True

    def image_tag(self):
        return u'<img src="/{0}" style="{1}" {2}/>'.format(
            self.image.url, "width: 100%", 'height=150')

    image_tag.allow_tags = True

    class Meta:
        verbose_name = _("ImageActivity")
        verbose_name_plural = _("ImageActivity")

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if self.id is None:
            try:
                self.title = self.image.name.split("@")[0]
            except:
                pass
            self.size = self.image.size

        super(ImageActivity, self).save()
Beispiel #9
0
class QuestionFile(models.Model):
    file = models.FileField(upload_to=MediaFileNameHash("files"),
                            verbose_name=_("File"))
    uploader = models.ForeignKey(BaseUser,
                                 verbose_name=_("Uploader"),
                                 null=True,
                                 blank=True)
    uploader_ip = models.CharField(max_length=30,
                                   verbose_name=_("Uploader ip"),
                                   null=True,
                                   blank=True)
    is_question = models.BooleanField(default=True,
                                      verbose_name=_("Is question"))
    gender = models.CharField(max_length=7,
                              choices=gender_choice,
                              default=None,
                              verbose_name=_("Gender"),
                              null=True,
                              blank=True)
    question = models.ForeignKey(to=Question, related_name="question_files")
    size = models.CharField(max_length=150, default="", blank=True, null=True)
    title = models.CharField(max_length=255, default="", blank=True, null=True)

    def file_link(self):
        return "<a href='/{0}' style='margin-right: 2%' download>{1}</a>".format(
            self.file.url, _("Download"))

    file_link.allow_tags = True

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if self.id is None:
            try:
                self.title = self.file.name.split("@")[0]
            except:
                pass
            self.size = self.file.size

        super(QuestionFile, self).save()

    def __str__(self):
        return self.title
Beispiel #10
0
class ShopSlider(models.Model):
    gender_choice = (
        ('both', _('both')),
        ('female', _('female')),
        ('male', _('male'))
    )
    type_slider = (
        ("PRODUCT", 'product'),
        ('BANNER', 'banner'),
    )
    title = models.CharField(max_length=150, verbose_name=_("Title"))
    link = models.CharField(max_length=100, verbose_name=_("Link"), null=True, blank=True)
    type = models.CharField(max_length=32, verbose_name=_("Type"), choices=type_slider)
    image = ImageWithThumbsField(
        upload_to=MediaFileNameHash("banners"),
        default=None,
        sizes=((320, 180), (145, 145), (711, 400),),
        preserve_ratio=True,
        verbose_name=_("Image")
    )
    created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Created at"))
    updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated at"))

    for_student = models.BooleanField(default=True, verbose_name=_("Student"))  # محصول برای دانش آموزان است یا نه؟
    for_teacher = models.BooleanField(default=False, verbose_name=_("get_coach"))  # محصول برای مربی و ادمین ها است یا نه؟
    gender = models.CharField(
        max_length=10,
        choices=gender_choice,
        verbose_name=_("Gender"),
        null=True, blank=True
    )
    # product_related = models.ForeignKey(null=True,blank=True,to=Product, verbose_name=_("Product")) # برای اتصال

    def image_tag(self):
        return u'<img src="/{0}" style="{1}" {2}/>'.format(self.image.url, "width: 100%", 'height=150')

    image_tag.allow_tags = True

    class Meta:
        verbose_name = _("Shop Slider")
        verbose_name_plural = _("Shop Sliders")

    def __str__(self):
        return self.title
Beispiel #11
0
class AnnouncementFile(models.Model):
    title = models.CharField(max_length=150, default="")
    file = models.FileField(upload_to=MediaFileNameHash("files"),
                            default=None,
                            verbose_name=_("File"))
    size = models.CharField(max_length=150, default="", blank=True, null=True)
    duration = models.TimeField(blank=True, null=True)
    announcement = models.ForeignKey(to=Announcement,
                                     related_name="announcement_files",
                                     on_delete=models.CASCADE)

    def file_link(self):
        return "<a href='/{0}' style='margin-right: 2%'>{1}</a>".format(
            self.file.url, _("Download"))

    file_link.allow_tags = True

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if self.id is None:
            try:
                self.title = self.file.name.split("@")[0]
            except:
                pass
            self.size = self.file.size

        super(AnnouncementFile, self).save()
        # get file format
        file_format = self.file.name.split(".")[-1].upper()
        if file_format in [
                'MP4', 'FLV', 'MOV', 'AVI', 'MPEG', 'WMV', '3GP', 'VOB', 'MPG',
                'MP3', 'M4A', 'OGG', 'WMA'
        ]:
            # get duration for video
            self.duration = get_video_duration(self.file.path)
            super(AnnouncementFile, self).save()

    class Meta:
        verbose_name = _("Announcement File")
        verbose_name_plural = _("Announcement Files")
Beispiel #12
0
class Image(models.Model):
    state_choice = (('act', 'activity'), ('sho', 'shop'), ('non', 'none'),
                    ('adv', 'adv'))

    upload_folder = 'images'

    title = models.CharField(max_length=255, verbose_name=_("Title"))
    obj = models.ImageField(upload_to=MediaFileNameHash(upload_folder),
                            default=None,
                            verbose_name=_("Obj"))
    image_size = models.PositiveIntegerField(default=0,
                                             verbose_name=_("Image size"))
    gender = models.CharField(max_length=1,
                              default=None,
                              verbose_name=_("Gender"))
    state = models.CharField(max_length=3,
                             choices=state_choice,
                             default=None,
                             null=True,
                             blank=True)

    def save(self, *args, **kwargs):
        self.image_size = self.obj.size
        super(Image, self).save(*args, **kwargs)

    def delete(self, using=None, keep_parents=False):
        remove_file(self.obj.path)
        super(Image, self).delete(using=using, keep_parents=keep_parents)

    @property
    def image_size_readable(self):
        return sizeof_fmt(self.image_size)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = _("Image")
        verbose_name_plural = _("Images")
Beispiel #13
0
class BaseUser(DjangoUser, TimeStampedModel):
    gender = models.CharField(max_length=10, choices=static.gender_choice, default=None, null=True, blank=True)
    phone_number = models.CharField(max_length=50, null=True, blank=True)
    last_visit = models.DateTimeField(null=True, blank=True, verbose_name=_("Last visit"))
    user_is_test = models.BooleanField(default=False, verbose_name=_("User Is Test"))
    image = ImageWithThumbsField(
        upload_to=MediaFileNameHash("user_image"),
        default=None,
        sizes=((200, 200), ),
        preserve_ratio=True,
        null=True,
        blank=True,
        verbose_name=_("Image")
    )

    class Meta:
        verbose_name = _("Base User")
        verbose_name_plural = _("Base User")

    def __str__(self):
        return "%s %s" % (self.first_name, self.last_name)

    # def last_visit_persian_date(self):
    #     from apps.common.utils import gregorian_to_persian_chart
    #     if self.last_visit:
    #         return gregorian_to_persian_chart(self.last_visit, str_type="%Y/%m/%d %H:%M:%S")
    #     else:
    #         return ""
    #
    # last_visit_persian_date.admin_order_field = 'last_visit'

    def last_login_persian_date(self):
        from apps.common.utils import gregorian_to_persian_chart
        if self.last_login:
            return gregorian_to_persian_chart(self.last_login, str_type="%Y/%m/%d %H:%M:%S")
        else:
            return ""

    last_login_persian_date.admin_order_field = 'last_login'