class Product(models.Model): name = models.CharField(verbose_name='name', max_length=100, blank=False, null=False) amount = models.IntegerField(verbose_name='amount', blank=True, null=True) price = models.IntegerField(verbose_name='price', blank=False, null=False) intro = models.CharField(verbose_name='intro', max_length=200, blank=True, null=True) image = StdImageField( verbose_name='image', upload_to="product", validators=[MinSizeValidator(300, 300), MaxSizeValidator(5760, 3840)], blank=True, variations={ 'medium': (500, 500, True), 'small': (300, 300, True), }, ) tx_hash = models.CharField(verbose_name='name', max_length=2000, blank=False, null=False) def __str__(self): return self.name
class Event(models.Model): # reits = models.IntegerField(_('Рейтинг'),max_length=1) title = models.CharField(_('Название'), max_length=100) # slug = AutoSlugField(populate_from='title', unique_with='date_start__month') type = models.CharField(_('Какое мероприятие'), max_length=100, choices=EVENT_TYPE, default='hak') date_start = models.DateTimeField(_('Дата начала')) date_end = models.DateTimeField(_('Дата окончания')) img = StdImageField(_("Аватар"), upload_to=avatar_path, variations={ 'thumb': (150, 150, True), 'small': (50, 50, True) }, validators=[MaxSizeValidator(1028, 768)], null=True) city = models.CharField(_('Город'), max_length=100, choices=CITIES, default='msk') specialty = models.ManyToManyField(Specialty, verbose_name=_('Специальность')) about = models.TextField(_('Описание'), max_length=2000) facebook = models.CharField(max_length=100, blank=True) instagram = models.CharField(max_length=100, blank=True) twitter = models.CharField(max_length=100, blank=True) vk = models.CharField(max_length=100, blank=True) create_by = models.ForeignKey(ItUser, verbose_name=_('Создатель'), related_name='my_events') members = models.ManyToManyField(ItUser, verbose_name=_('Участники'), blank=True, related_name='events') def __str__(self): return self.title class Meta: verbose_name = 'Event' verbose_name_plural = 'Events' def get_small_img_url(self): try: return self.img.small.url except AttributeError: return default_avatars.DEFAULT_EVENT_AVATAR_SMALL def get_thumb_img_url(self): try: return self.img.thumb.url except AttributeError: return default_avatars.DEFAULT_EVENT_AVATAR_THUMB
class Idea(models.Model): user = models.ForeignKey(Account, related_name='ideas', on_delete=models.CASCADE) title = models.CharField(verbose_name=_('Title'), max_length=255) topic = models.IntegerField( verbose_name=_('Topic'), choices=IDEA_TOPIC_CHOICES, ) description = models.TextField() image = StdImageField(verbose_name=_('Image'), default='default/img/idea.png', upload_to=UploadToPathAndRename('upload/img/idea'), validators=[ FileExtensionValidator(['png', 'jpg', 'jpeg']), MinSizeValidator(200, 200), MaxSizeValidator(1200, 1200) ], variations={ 'thumbnail': (40, 40, True), 'medium': (200, 200, True), 'large': (525, 525, True), }, blank=True, null=True) file = models.FileField( verbose_name=_('Resume'), upload_to=UploadToPathAndRename('upload/file/resume'), validators=[ FileExtensionValidator(['pdf', 'doc', 'docx']), ], blank=True, null=True) update_at = models.DateTimeField(auto_now=True) created_at = models.DateTimeField(auto_now_add=True) class Meta: verbose_name = _('idea') verbose_name_plural = _('ideas') ordering = ['-created_at'] def __str__(self): return ('%s add by %s' % (self.title, self.user.get_full_name())).strip() def get_topic_str(self): return IDEA_TOPIC_CHOICES[self.topic - 1][1]
class gallery_model(models.Model): judul = models.CharField(default='', null=False, max_length=20, verbose_name='Judul Foto') caption = models.CharField(default='', null=False, max_length=300, verbose_name='Caption Foto') image = StdImageField(upload_to='upload/gallery', validators=[MaxSizeValidator(1300, 1300)], verbose_name='Foto', blank=True) timestamp = models.DateTimeField(auto_now=False, auto_now_add=True) def __unicode__(self): return '%s' % self.judul class Meta: ordering = ["-timestamp"]
class berita_model(models.Model): judul = models.CharField(default='', max_length=200) user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1) slug = models.SlugField(unique=True) image = StdImageField(upload_to='upload/berita', validators=[MaxSizeValidator(1300, 1300)], blank=True) content = models.TextField() draft = models.BooleanField(default=False) publish = models.DateField(auto_now=False, auto_now_add=False) updated = models.DateTimeField(auto_now=True, auto_now_add=False) timestamp = models.DateTimeField(auto_now=False, auto_now_add=True) tag = models.CharField(default='', null=False, max_length=20) def __str__(self): return self.judul class Meta: ordering = ["-updated"] def get_absolute_url(self): return reverse("dashboard:detail_berita", kwargs={"slug": self.slug})
class MyUser(AbstractUser): """ Model to store all auth users """ # add custom fiels for default User profile HERE avatar = MyImageField( upload_to=avatar_directory_path, # path/to/imgs variations={'thumbnail': (150, 150, True)}, # resize to min size validators=[ validate_avatar_size, # size MinSizeValidator(150, 150), # min dimension MaxSizeValidator(500, 500) ], # max dimension delete_orphans=True, # delete orphaned files blank=True, ) date_of_birth = models.DateField(blank=True, null=True) def __str__(self): return self.username class Meta: ordering = ['username'] verbose_name = "My User" verbose_name_plural = "My Users"
class MaxSizeModel(models.Model): image = StdImageField(upload_to=upload_to, validators=[MaxSizeValidator(16, 16)])
class Account(AbstractBaseUser, PermissionsMixin): username = models.CharField( verbose_name=_('Username'), max_length=100, unique=True, validators=[USERNAME_VALIDATOR], help_text= _('Required. 100 characters or fewer. Letters, digits and @/ ./+ /- /_ only. e.g. Adam_99' )) email = models.EmailField(verbose_name=_('Email'), max_length=200, unique=True, help_text=_('Email: e.g. [email protected]')) first_name = models.CharField(verbose_name=_('First Name'), max_length=100) last_name = models.CharField(verbose_name=_('Last Name'), max_length=100) profile_pic = StdImageField( verbose_name=_('Profile Image'), default='default/img/profile.png', upload_to=UploadToPathAndRename('upload/img/profile'), validators=[ FileExtensionValidator(['png', 'jpg', 'jpeg']), MinSizeValidator(200, 200), MaxSizeValidator(1200, 1200) ], variations={ 'thumbnail': (40, 40, True), 'medium': (200, 200, True), 'large': (525, 525, True), }) country = CountryField(verbose_name=_('Country'), blank_label=_('__Select Country__')) is_admin = models.BooleanField(default=False) is_active = models.BooleanField(default=False) is_staff = models.BooleanField(default=False) is_supervisor = models.BooleanField(default=False) is_team = models.BooleanField(default=False) is_user = models.BooleanField(default=False) global_token = models.CharField(max_length=255, default=uuid4) USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['email', 'first_name', 'last_name'] objects = AccountManager() class Meta: verbose_name = _('account') verbose_name_plural = _('accounts') def __str__(self): return ('%s' % self.username).strip() def get_full_name(self): return ('%s %s' % (self.first_name, self.last_name)).strip() def get_short_name(self): return ('%s' % self.first_name).strip() def has_perm(self, perm, obj=None): return self.is_admin def has_module_perms(self, app_label): return True def email_user(self, subject, message, from_email=None, **kwargs): """Send an email to this user.""" send_mail(subject, message, from_email, [self.email], **kwargs)
class MaxSizeModel(models.Model): image = StdImageField(upload_to=UploadTo(name='image', path='img'), validators=[MaxSizeValidator(16, 16)])
class staff_model(models.Model): nama = models.CharField(default='', null=False, max_length=20, verbose_name='Nama Lengkap') nama_display = models.CharField(default='', null=False, max_length=14, verbose_name='Nama yang Ditampilkan') nidn = models.CharField(default='', null=False, max_length=10, verbose_name='NIDN') jabatan = models.CharField(default='', null=False, max_length=30, verbose_name='Jabatan Akademik') gelar1 = models.CharField(default='', null=False, max_length=30, verbose_name='Gelar Pendidikan S1') gelar2 = models.CharField(default='', blank=True, max_length=30, verbose_name='Gelar Pendidikan S2') gelar3 = models.CharField(default='', blank=True, max_length=30, verbose_name='Gelar Pendidikan S3') pendidikan1 = models.CharField(default='', null=False, max_length=100, verbose_name='Universitas Jenjang SI') pendidikan2 = models.CharField(default='', blank=True, max_length=100, verbose_name='Universitas Jenjang S2') pendidikan3 = models.CharField(default='', blank=True, max_length=100, verbose_name='Universitas Jenjang S3') bidang_keahlian1 = models.CharField(default='', null=False, max_length=80, verbose_name='Bidang Keahlian S1') bidang_keahlian2 = models.CharField(default='', blank=True, max_length=80, verbose_name='Bidang Keahlian S2') bidang_keahlian3 = models.CharField(default='', blank=True, max_length=80, verbose_name='Bidang Keahlian S3') penelitian = models.CharField(default='', blank=True, max_length=200, verbose_name='Penelitian Google Scholar') biografi = models.TextField(default='', blank=True, verbose_name='Biografi') foto = StdImageField(upload_to='upload/dosen', validators=[MaxSizeValidator(1028, 768)], blank=True) posisi = models.CharField(default='', null=False, max_length=30) def save(self, *args, **kwargs): nama = self.nama_display.upper() if self.nama_display: self.nama_display = nama super(staff_model, self).save(*args, **kwargs) def __unicode__(self): return '%s' % self.nama
class Course(TimeStampedModel, ChangedByMixin): """ Publisher Course model. It contains fields related to the course intake form.""" title = models.CharField(max_length=255, default=None, null=True, blank=True, verbose_name=_('Course title')) number = models.CharField(max_length=50, null=True, blank=True, verbose_name=_('Course number')) short_description = models.CharField( max_length=255, default=None, null=True, blank=True, verbose_name=_('Brief Description') ) full_description = models.TextField(default=None, null=True, blank=True, verbose_name=_('Full Description')) organizations = models.ManyToManyField( Organization, blank=True, related_name='publisher_courses', verbose_name=_('Partner Name') ) level_type = models.ForeignKey( LevelType, default=None, null=True, blank=True, related_name='publisher_courses', verbose_name=_('Level Type') ) expected_learnings = models.TextField(default=None, null=True, blank=True, verbose_name=_("Expected Learnings")) syllabus = models.TextField(default=None, null=True, blank=True) prerequisites = models.TextField(default=None, null=True, blank=True, verbose_name=_('Prerequisites')) learner_testimonial = models.CharField(max_length=50, null=True, blank=True) verification_deadline = models.DateTimeField( null=True, blank=True, verbose_name=_("Verification deadline"), help_text=_('Last date/time on which verification for this product can be submitted.') ) primary_subject = models.ForeignKey( Subject, default=None, null=True, blank=True, related_name='publisher_courses_primary' ) secondary_subject = models.ForeignKey( Subject, default=None, null=True, blank=True, related_name='publisher_courses_secondary' ) tertiary_subject = models.ForeignKey( Subject, default=None, null=True, blank=True, related_name='publisher_courses_tertiary' ) image = StdImageField( upload_to=UploadToFieldNamePath( populate_from='number', path='media/publisher/courses/images' ), blank=True, null=True, variations={ 'thumbnail': (100, 100, True), }, validators=[MaxSizeValidator(2120, 1192), MinSizeValidator(2120, 1192), ] ) is_seo_review = models.BooleanField(default=False) keywords = TaggableManager(blank=True, verbose_name='keywords') history = HistoricalRecords() def __str__(self): return self.title @property def post_back_url(self): return reverse('publisher:publisher_courses_edit', kwargs={'pk': self.id}) class Meta(TimeStampedModel.Meta): permissions = ( ('view_course', 'Can view course'), ) def get_course_users_emails(self): """ Returns the list of users emails with enable email notifications against a course. By default if attribute value does not exists then user will be eligible for emails. """ users_list_roles = [obj.user for obj in self.course_user_roles.all()] user_emails = [user.email for user in users_list_roles if is_email_notification_enabled(user)] return user_emails @property def keywords_data(self): keywords = self.keywords.all() if keywords: return ', '.join(k.name for k in keywords) return None @property def project_coordinator(self): try: return self.course_user_roles.get(role=PublisherUserRole.ProjectCoordinator).user except CourseUserRole.DoesNotExist: return None def assign_organization_role(self, organization): """ Create course-user-roles except CourseTeam for the given organization against a course. """ for user_role in organization.organization_user_roles.exclude(role=PublisherUserRole.CourseTeam): CourseUserRole.add_course_roles(self, user_role.role, user_role.user) @property def course_runs(self): return self.publisher_course_runs.order_by('-created') @property def course_team_admin(self): try: return self.course_user_roles.get(role=PublisherUserRole.CourseTeam).user except CourseUserRole.DoesNotExist: return None @property def partner(self): organization = self.organizations.all().first() return organization.partner if organization else None @property def marketing_reviewer(self): try: return self.course_user_roles.get(role=PublisherUserRole.MarketingReviewer).user except CourseUserRole.DoesNotExist: return None @property def organization_extension(self): organization = self.organizations.all().first() if organization: return organization.organization_extension return None @property def publisher(self): try: return self.course_user_roles.get(role=PublisherUserRole.Publisher).user except CourseUserRole.DoesNotExist: return None
class ItUser(AbstractUser): # signed = models.ForeignKey('ItUser', null=True, blank=True) # colleagues = models.ForeignKey('ItUser', null=True, blank=True) # number = models.PositiveIntegerField(max_length=5) username = models.CharField( _('Логин'), max_length=150, unique=True, validators=[AbstractUser.username_validator], error_messages={ 'unique': _("A user with that username already exists."), }, ) first_name = models.CharField(_('Имя'), max_length=30) last_name = models.CharField(_('Фамилия'), max_length=30) specialty = models.CharField(_('Специальность'), choices=SPECIALITIES, max_length=100) birth = models.DateField(_('Дата рождения'), default=timezone.now) email = models.EmailField(_('Email'), unique=True) img = StdImageField(_("Аватар"), upload_to=avatar_path, variations={ 'thumb': (150, 150, True), 'small': (50, 50, True) }, validators=[MaxSizeValidator(1028, 768)], null=True) city = models.CharField(_('Город'), max_length=100, choices=CITIES, default='msk') experience = models.CharField(_('Опыт работы'), max_length=100) education = models.CharField(_('Образование'), max_length=100) about = models.TextField(_('О себе'), max_length=2000) skills = models.CharField( _('Навыки'), max_length=1000, help_text= _('Например: Python, Photoshop, CSS, Angular - разделять навыки запятыми' )) edu = models.BooleanField(_('Готов обучать'), default=False) edu_list = models.CharField( _('Могу обучить'), max_length=1000, help_text=_('Например: Python, Photoshop, CSS, Angular'), null=True, blank=True) github = models.CharField(max_length=100, blank=True) bitbacket = models.CharField("bitbucket", max_length=100, blank=True) pinterest = models.CharField(max_length=100, blank=True) facebook = models.CharField(max_length=100, blank=True) instagram = models.CharField(max_length=100, blank=True) twitter = models.CharField(max_length=100, blank=True) vk = models.CharField(max_length=100, blank=True) def __str__(self): return self.username class Meta: verbose_name = 'ItUser' verbose_name_plural = 'ItUsers' def get_small_img_url(self): try: return self.img.small.url except AttributeError: return default_avatars.DEFAULT_USER_AVATAR_SMALL def get_thumb_img_url(self): try: return self.img.thumb.url except AttributeError: return default_avatars.DEFAULT_USER_AVATAR_THUMB def get_age(self): today = date.today() years_difference = today.year - self.birth.year is_before_birthday = (today.month, today.day) < (self.birth.month, self.birth.day) elapsed_years = years_difference - int(is_before_birthday) return elapsed_years def get_skiils(self): str = self.skill.split(',') print(str) return list(str)
STATIC_URL = "/static/" STATIC_ROOT = os.path.join(BASE_DIR, "static") STATICFILES_DIRS = [] AUTH_USER_MODEL = "members.User" MEDIA_URL = "/media/" MAX_ZIPFILE = 48 * 1024 * 1024 MIN_IMAGE_SIZE = 2 * 1024 MAX_IMAGE_SIZE = 8 * 1024 * 1024 MAX_IMAGE_WIDTH = 1280 from stdimage.validators import MinSizeValidator, MaxSizeValidator IMG_VALIDATORS = [MinSizeValidator(100, 100), MaxSizeValidator(8000, 8000)] # Note: the labels are effectively 'hardcoded' in the templates # and code; the sizes are free to edit. # IMG_VARIATIONS = { "thumbnail": (100, 100, True), "medium": (300, 200), "large": (600, 400), } UFO_DEADLINE_DAYS = 14 UFO_DISPOSE_DAYS = 7 CACHES = { "default": {