class TaskExec(models.Model): class Meta: db_table = 'indices_tasks' class TaskType(enum.Enum): ALIAS = 0 CLOSE = 1 CREATE = 2 DELETE = 3 OPTIMIZE = 4 SNAPSHOT = 5 class Status(enum.Enum): SUCCESS = 0 FAILURE = 1 indexset = models.ForeignKey(IndexSet, on_delete=models.CASCADE) type = enum.EnumField(TaskType) last_run_at = models.DateTimeField(default=timenow) last_run_status = enum.EnumField(Status, default=Status.SUCCESS) last_run_info = models.TextField(default='') def __str__(self): return '[{indexset}] {type}(ed) at {last_run_at}, status:{last_run_status}'.format( indexset=str(self.indexset), type=str(self.type), last_run_at=str(self.last_run_at), last_run_status=str(self.last_run_status))
class QueueItem(models.Model): objects = QueueItemQuerySet().as_manager() banner = models.ForeignKey('banners.Banner', on_delete=models.CASCADE, related_name='queue') phone_number = models.CharField(_('phone'), validators=[phone_regex_validator], max_length=17) status = enum.EnumField(QueueItemStatus, default=QueueItemStatus.QUEUED) source = enum.EnumField(QueueItemSource, default=QueueItemSource.TWILIO) telegram_chat_id = models.BigIntegerField( null=True, blank=True, validators=[MinValueValidator(0)]) past = models.BooleanField(null=False, default=False) position = PositionField(collection=('banner', 'past')) processing_started_at = models.DateTimeField(null=True, blank=True) processing_ended_at = models.DateTimeField(null=True, blank=True) waiting_time_estimation = models.DurationField(null=True, blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: ordering = ('position', ) base_manager_name = 'objects' def __str__(self): return self.phone_number
class Issue(models.Model): submitter = models.ForeignKey(User, on_delete=models.SET_NULL, related_name='submitter', null=True) solver = models.ForeignKey(User, on_delete=models.SET_NULL, related_name='solver', null=True) description = models.CharField(max_length=200) status = enum.EnumField(IssueStatus, default=IssueStatus.OPENED) category = enum.EnumField(IssueCategory, default=IssueCategory.BUG) created = models.DateTimeField(auto_now_add=True, blank=True) finished = models.DateTimeField(null=True, editable=False) duration = models.DurationField(null=True, editable=False) def __str__(self): return '{}'.format(self.description[0:10]) @staticmethod def pre_save(sender, **kwargs): instance = kwargs.get('instance') # created = kwargs.get('created') if instance.status == IssueStatus.SOLVED: instance.finished = datetime.now() instance.duration = datetime.now(timezone.utc) - instance.created else: instance.finished = None
class Car(models.Model): car_owner = models.ForeignKey(User) car_name = models.CharField(max_length=100) car_color = enum.EnumField(ColorStyle, default=ColorStyle.RED) car_size = enum.EnumField(SizeStyle, default=SizeStyle.SMALL) car_time_created = models.DateTimeField(auto_now_add=True) car_time_changed = models.DateTimeField(auto_now=True)
class Product(TimeStampedModel): description = FroalaField(blank=True) # price with currency price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True, verbose_name=_('Verkaufspreis')) currency = enum.EnumField(Currency, default=Currency.EUR) price_changed = MonitorField(monitor='price', verbose_name=_("letzte Preisänderung am")) display_nr = models.IntegerField(default=1) # product type product_type = enum.EnumField(Producttype, default=Producttype.OTHER) objects = ProductManager() class Meta: abstract = True def __unicode__(self): return "%s: %s" % (self.name)
class Discipline(models.Model): name = models.CharField(max_length=100) code = models.CharField(max_length=100) number_credit = models.IntegerField(default=0) required = enum.EnumField(DisciplineStyle, default=DisciplineStyle.MANDATORY) offered = enum.EnumField(DisciplineStyle, default=DisciplineStyle.NOTOFFERED) period_offered = models.DateField(null=True) required_credit = models.IntegerField(blank=True, null=True) teacher = models.CharField(max_length=100) course = models.ForeignKey(Course, related_name='discipline', null=True) departament = models.ForeignKey(Departament, related_name='discipline', null=True) disciplines = models.ManyToManyField('self', related_name='discipline_req', null=True) type = models.IntegerField(default=0) def __str__(self): return self.name def __unicode__(self): return '%d: %s' % (self.id, self.name)
class CourseEventParticipation(TimeStampedModel): courseevent = models.ForeignKey(CourseEvent) user = models.ForeignKey(settings.AUTH_USER_MODEL) hidden = models.BooleanField(verbose_name=_('versteckt'), default=False) hidden_status_changed = MonitorField(monitor='hidden') notification_forum = enum.EnumField(NotificationSettings, default=NotificationSettings.ALL) notification_work = enum.EnumField(NotificationSettings, default=NotificationSettings.ALL) objects = ParticipationManager() class Meta: verbose_name = _("Kurs-Teilnehmer") verbose_name_plural = _("Kurs-Teilnehmer") unique_together = ('user', 'courseevent') def __unicode__(self): return u'%s / %s' % (self.courseevent, self.user) @cached_property def course(self): return self.courseevent.course def hide(self): self.hidden = True self.save() def unhide(self): self.hidden = False self.save()
class UniAR(models.Model): owner = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True, blank=True) name = models.CharField(max_length=200, null=True, blank=True) pub_date = models.DateTimeField('date published') uniCategory = enum.EnumField(UniCategory, default=UniCategory.ENTERTAINMENT) imageBytes = models.BinaryField(null=True, blank=True) fileBytes = models.BinaryField(null=True, blank=True) uniType = enum.EnumField(UniType, default=UniType.IMAGE_TARGET) uniFileType = enum.EnumField(UniFileType, default=UniFileType.MODEL) image = models.FileField(upload_to='images/', null=True, blank=True) file = models.FileField(upload_to='files/', null=True, blank=True) uniHyperLink = models.CharField(max_length=300, null=True, blank=True) fileSize = models.IntegerField(null=True, blank=True) isPrivate = models.BooleanField(null=True, blank=True) position_x = models.FloatField(null=True, blank=True) position_y = models.FloatField(null=True, blank=True) position_z = models.FloatField(null=True, blank=True) rotation_x = models.FloatField(null=True, blank=True) rotation_y = models.FloatField(null=True, blank=True) rotation_z = models.FloatField(null=True, blank=True) scale_x = models.FloatField(null=True, blank=True) scale_y = models.FloatField(null=True, blank=True) scale_z = models.FloatField(null=True, blank=True)
class IndexSet(models.Model): class EnumEsIndexTimeInterval(enum.Enum): HOURS = 0 DAYS = 1 WEEKS = 2 MONTHS = 3 YEARS = 4 class EnumStatus(enum.Enum): STARTED = 0 STOPPED = 1 name = models.CharField(max_length=64, unique=True) description = models.CharField(max_length=256, blank=True) index_name_prefix = models.CharField(max_length=256) # Note: available timestring defined in: # https://docs.python.org/2.7/library/datetime.html#strftime-strptime-behavior index_timestring = models.CharField(max_length=32) index_timestring_interval = enum.EnumField( EnumEsIndexTimeInterval, default=EnumEsIndexTimeInterval.DAYS) elasticsearch = models.ForeignKey(ElasticCluster, on_delete=models.CASCADE) created_at = models.DateTimeField(default=timenow) status = enum.EnumField(EnumStatus, default=EnumStatus.STARTED) class Meta: db_table = 'indices_index_set' def __str__(self): return self.name
class Clearance(BaseModel): class Meta: app_label = 'tally' result_form = models.ForeignKey(ResultForm, related_name='clearances') supervisor = models.ForeignKey(User, null=True, related_name='clearance_user') user = models.ForeignKey(User) active = models.BooleanField(default=True) reviewed_supervisor = models.BooleanField(default=False) reviewed_team = models.BooleanField(default=False) date_supervisor_modified = models.DateTimeField(null=True) date_team_modified = models.DateTimeField(null=True) # Problem Fields center_name_missing = models.BooleanField(default=False) center_name_mismatching = models.BooleanField(default=False) center_code_missing = models.BooleanField(default=False) center_code_mismatching = models.BooleanField(default=False) form_already_in_system = models.BooleanField(default=False) form_incorrectly_entered_into_system = models.BooleanField(default=False) other = models.TextField(null=True, blank=True) # Recommendations action_prior_to_recommendation = enum.EnumField(ActionsPrior, blank=True, null=True, default=4) resolution_recommendation = enum.EnumField(ClearanceResolution, null=True, blank=True, default=0) # Comments team_comment = models.TextField(null=True, blank=True) supervisor_comment = models.TextField(null=True, blank=True) def get_problems(self): problem_fields = { _('Center Name Missing'): self.center_name_missing, _('Center Name Mismatching'): self.center_name_mismatching, _('Center Code Missing'): self.center_code_missing, _('Station Number Mismatching'): self.center_code_mismatching, _('Form Already in System'): self.form_already_in_system, _('Form Incorrectly Entered into the System'): self.form_incorrectly_entered_into_system, _('Other'): self.other, } return keys_if_value(problem_fields) def action_prior_name(self): return ActionsPrior.label(self.action_prior_to_recommendation) def resolution_recommendation_name(self): return ClearanceResolution.label(self.resolution_recommendation)
class Ballot(BaseModel): class Meta: app_label = 'tally' ordering = ['number'] COMPONENT_TO_BALLOTS = { 55: [26, 27, 28], 56: [29, 30, 31], 57: [34], 58: [47], } number = models.PositiveSmallIntegerField() race_type = enum.EnumField(RaceType) active = models.BooleanField(default=True) disable_reason = enum.EnumField(DisableReason, null=True, default=None) tally = models.ForeignKey(Tally, null=True, blank=True, related_name='ballots') @property def race_type_name(self): if self.sc_general.all() and self.sc_general.all()[0].ballot_component: return _('General and Component') return _(RaceType.label(self.race_type)) @property def sub_constituency(self): sc = self.sc_general.all() or self.sc_women.all() or\ self.sc_component.all() if sc: return sc[0] @property def component_ballot(self): """Retrieve the component ballot for this ballot. :returns: The component ballot for this ballot via the general ballot sub constituency. """ return self.sc_general and self.sc_general.all() and\ self.sc_general.all()[0].ballot_component @property def form_ballot_numbers(self): #return Ballot.COMPONENT_TO_BALLOTS[self.number] if self.is_component\ # else [self.number] return [self.number] @property def is_component(self): return self.number in self.COMPONENT_TO_BALLOTS.keys() def __unicode__(self): return u'%d' % self.number
class DocumentModel(base.TimestampMixin, models.Model): """ One uploaded xls/xlsx document """ objects = base.FuzzyCountManager() # show fast, but delayed amount id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) located = enum.EnumField(DOCUMENT_LOCATION) status = enum.EnumField(DOCUMENT_STATUS, default=DOCUMENT_STATUS.PENDING) # created_at/updated_at is related to database record # uploaded_at/finished_at controling by filehandler uploaded_at = models.DateTimeField(auto_now=True) finished_at = models.DateTimeField(null=True) @property def filename(self): # extension is not matter here and we set 'xlsx' only to tell humans, # what is on this folder if self.located == DOCUMENT_LOCATION.LOCAL: return os.path.join(settings.MEDIA_ROOT, f'{self.id}.xlsx') return None def store_local(self, fobj): try: with default_storage.open(self.filename, 'wb+') as destination: for chunk in fobj.chunks(): destination.write(chunk) except Exception as e: logger.error(repr(e)) return False return True def store(self, fobj): ''' write to file storage ''' if self.located == DOCUMENT_LOCATION.LOCAL: return self.store_local(fobj) return None def load(self): ''' return file object ''' try: fobj = open(self.filename, 'rb') except Exception as e: logger.error(repr(e)) return None return fobj def __str__(self): return f'{self.id} {self.located.label} {self.filename}' class Meta: base_manager_name = 'objects' indexes = [ models.Index(fields=['status'], name='status_idx'), ]
class Schedule(models.Model): team = models.ForeignKey(Team) occurrence_freqency = enum.EnumField(ScheduleFrequency, default=ScheduleFrequency.WEEKLY) occurrence_day_of_week = enum.EnumField(ScheduleDayOfWeek, default=ScheduleDayOfWeek.FRIDAY, blank=True) occurrence_day_of_month = models.IntegerField(blank=True) advance_notification_days = models.IntegerField(default=1)
class Center(BaseModel): class Meta: app_label = 'tally' ordering = ['code'] unique_together = ('code', 'tally') sub_constituency = models.ForeignKey(SubConstituency, related_name='centers', null=True) center_type = enum.EnumField(CenterType) code = models.PositiveIntegerField() # a.k.a. Center Number latitude = models.FloatField(null=True) longitude = models.FloatField(null=True) mahalla = models.TextField() name = models.TextField() office = models.ForeignKey(Office, null=True) region = models.TextField() village = models.TextField() active = models.BooleanField(default=True) disable_reason = enum.EnumField(DisableReason, null=True) tally = models.ForeignKey(Tally, null=True, blank=True, related_name='centers') def remove(self): """Remove this center and related information. Stop and do nothing if there are results for this center. Removes the result forms and stations associated with this center. :raises: `Exception` if any results exist in any result forms are associated with this center. """ resultforms = self.resultform_set.all() check_results_for_forms(resultforms) resultforms.delete() self.stations.all().delete() self.delete() def sc_code(self): return self.sub_constituency.code if self.sub_constituency else _( 'Special') def __unicode__(self): return u'%s - %s' % (self.code, self.name) @property def status(self): return 'Enabled' if self.active else 'Disabled' @property def center_type_name(self): return 'Special' if self.center_type == 1 else 'General'
class Seat(models.Model): class Meta: unique_together = (('seat_num', 'row_num', 'section'), ) rank = enum.EnumField(Rank) extra = enum.EnumField(Extra) seq_num = models.IntegerField() seat_num = models.IntegerField() row_num = models.IntegerField() section = models.ForeignKey(Section, on_delete=models.CASCADE)
class Professor(models.Model): professor_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) first_name = models.CharField(max_length=35) last_name = models.CharField(max_length=35) email = models.EmailField() professor_type = enum.EnumField(ProfessorType) school = enum.EnumField(School) created_by = models.ForeignKey(User, on_delete=models.CASCADE) def __str__(self): return self.first_name + " " + self.last_name
class Audit(BaseModel): class Meta: app_label = 'tally' quarantine_checks = models.ManyToManyField(QuarantineCheck) result_form = models.ForeignKey(ResultForm) supervisor = models.ForeignKey(User, related_name='audit_user', null=True) user = models.ForeignKey(User) active = models.BooleanField(default=True) for_superadmin = models.BooleanField(default=False) reviewed_supervisor = models.BooleanField(default=False) reviewed_team = models.BooleanField(default=False) # Problem fields blank_reconciliation = models.BooleanField(default=False) blank_results = models.BooleanField(default=False) damaged_form = models.BooleanField(default=False) unclear_figures = models.BooleanField(default=False) other = models.TextField(null=True, blank=True) # Recommendations action_prior_to_recommendation = enum.EnumField(ActionsPrior, blank=True, null=True, default=4) resolution_recommendation = enum.EnumField( AuditResolution, null=True, blank=True, default=0) # Comments team_comment = models.TextField(null=True, blank=True) supervisor_comment = models.TextField(null=True, blank=True) def get_problems(self): """Return a list of problems for this audit. Return a list of problems for which the problem checkbox has been selected. :returns: A list of strings. """ problem_fields = { _('Blank Reconcilliation'): self.blank_reconciliation, _('Blank Results'): self.blank_results, _('Damaged Form'): self.damaged_form, _('Unclear Figures'): self.unclear_figures, _('Other'): self.other, } return keys_if_value(problem_fields) def action_prior_name(self): return _(ActionsPrior.label(self.action_prior_to_recommendation)) def resolution_recommendation_name(self): return dict(AUDIT_CHOICES).get(self.resolution_recommendation)
class Response(models.Model): assessment = models.ForeignKey(Assessment) type = enum.EnumField(ResponseType) boolean = models.BooleanField(default=True) number = models.IntegerField(null=True, blank=True) emotion = enum.EnumField(Emotion, default=Emotion.NONE) percent = models.FloatField(default=0) question_id = models.IntegerField( blank=False, null=False) # foreign key to local question_id created_at = CreationDateTimeField(_('created_at')) updated_at = ModificationDateTimeField(_('updated_at'))
class Contact(MetaInformationAbstractModel, models.Model): class DESIGNATION(enum.Enum): MR = 0 MS = 1 __labels__ = { MR: _("Mr"), MS: _("Ms"), } class GENDER(enum.Enum): MALE = 0 FEMALE = 1 OTHER = 2 __labels__ = { MALE: _("Male"), FEMALE: _("Female"), OTHER: _("Other"), } designation = enum.EnumField(DESIGNATION) first_name = models.CharField(verbose_name=_('First Name'), max_length=256) last_name = models.CharField(verbose_name=_('Last Name'), max_length=256) gender = enum.EnumField(GENDER, verbose_name=_('Gender')) job_title = models.CharField(verbose_name=_('Job Title'), max_length=256) organization = models.ForeignKey('organization.Organization', verbose_name=_('Organization'), related_name='contacts', on_delete=models.CASCADE) countries_of_operation = models.ManyToManyField( 'country.Country', verbose_name=_('Countries of Operation'), blank=True, related_name='operating_contacts', help_text=_('In which countries does this contact person' ' operate?')) country = models.ForeignKey('country.Country', verbose_name=_('Country'), blank=True, null=True, related_name='contacts', on_delete=models.SET_NULL) email = models.EmailField(verbose_name=_('Email'), blank=True, null=True) phone = models.CharField(verbose_name=_('Phone'), max_length=32, blank=True, null=True) comment = models.TextField(verbose_name=_('Comment'), blank=True, null=True) def __str__(self): return f'{self.designation.name} {self.first_name} {self.last_name}'
class Board(models.Model): """ Class for representation of the Raspberry Pi board at university laboratory There are 15 boards and every board has a number and a RFID Tag on it. The boards numbered 0-10 should be used in the laboratory during the exercise lesson (BoardLabLoan class) The boards numbered 11-15 could be loaned by authorised student for home usage (BoardHomeLoan class) Primary key = default django primary key Each board has only one unuqie rfid tag """ raspi_tag = models.OneToOneField(RaspiTag, on_delete=models.SET_NULL, blank=True, null=True) board_no = models.IntegerField('board number', unique=True) board_type = enum.EnumField(BoardType, default=BoardType.LAB_LOAN) board_status = enum.EnumField(BoardStatus, default=BoardStatus.ACTIVE) class Meta: ordering = ['board_no'] def __str__(self): if self.raspi_tag is not None: return 'Board ' + str(self.board_no) else: return 'Board ' + str(self.board_no) @staticmethod def return_board(raspi_tag): # Update the status of the board with raspi_tag Board.objects.filter(raspi_tag=raspi_tag).update( board_status=BoardStatus.ACTIVE) @staticmethod def loan_board(raspi_tag): # Update the status of the board with raspi_tag Board.objects.filter(raspi_tag=raspi_tag).update( board_status=BoardStatus.LOANED) def last_action(self): return self.action_set.last() def loan_expires_at(self): if self.board_status != BoardStatus.LOANED: return None last_action = self.last_action().timestamp if self.board_type == BoardType.LAB_LOAN: return last_action + MAX_LAB_LOAN_LIMIT elif self.board_type == BoardType.HOME_LOAN: return last_action + MAX_HOME_LOAN_LIMIT return None
class UserProfile(models.Model): user = models.OneToOneField(User, related_name='profile') birthday = models.DateField(null=True, blank=True) gender = enum.EnumField(Gender, default=Gender.MALE) meditation_time = models.TimeField(null=True) exercise_day_of_week = enum.EnumField(DayOfWeek, default=DayOfWeek.MO) exercise_time = models.TimeField(null=True) apns_device = models.ForeignKey(APNSDevice, null=True, blank=True) created_at = CreationDateTimeField(_('created_at')) updated_at = ModificationDateTimeField(_('updated_at')) def __unicode__(self): return self.user.get_full_name()
class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) fbid = models.TextField(max_length=500, blank=True, null=True) followers = models.IntegerField(null=True, blank=True) following = models.IntegerField(null=True, blank=True) unisAmount = models.IntegerField(null=True, blank=True) imageBytes = models.BinaryField(null=True, blank=True) image = models.FileField(upload_to='ProfileImages/', null=True, blank=True) userType = enum.EnumField(UserType, default=UserType.FREE) loginType = enum.EnumField(LoginType, default=LoginType.EMAIL) followers_user = models.ManyToManyField('self', related_name='follows', symmetrical=False)
class FlowEvent(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='flow_events', null=True) timestamp = models.DateTimeField() first_day = models.BooleanField(default=False) level = enum.EnumField(FlowLevel, default=FlowLevel.MEDIUM) color = enum.EnumField(FlowColor, default=FlowColor.RED) clots = enum.EnumField(ClotSize, default=None, null=True, blank=True) cramps = enum.EnumField(CrampLevel, default=None, null=True, blank=True) comment = models.CharField(max_length=250, null=True, blank=True) def __str__(self): return "%s %s (%s)" % (self.user.get_full_name(), FlowLevel.label(self.level), self.timestamp)
class Resolution(models.Model): """ Database representation of a resolution """ title = models.CharField(max_length=200) date_submitted = models.DateTimeField(auto_now_add=True) date_enacted = models.DateTimeField(blank=True, null=True) date_sent = models.DateField(blank=True, null=True) reso_type = enum.EnumField(ResoType, default=ResoType.RESOLUTION) reso_text = models.TextField() reso_text_html = models.TextField(default="") motivation_text = models.TextField(default="") motivation_text_html = models.TextField(default="") pdf_path = models.FilePathField(default="") def __str__(self): return self.title def reso_type_name(self): """ Return the ResoType label corresponding to the set resolution type :return: ResoType label :rtype: str """ return ResoType.name(self.reso_type)
class History(NicelyFormattedModel): objects = HistoryQuerySet.as_manager() class Meta: ordering = ['-date'] date = models.DateTimeField(default=timezone.now) typus = enum.EnumField(HistoryTypus) group = models.ForeignKey('groups.Group', on_delete=models.CASCADE) store = models.ForeignKey('stores.Store', null=True, on_delete=models.CASCADE) users = models.ManyToManyField('users.User') payload = JSONField(null=True) before = JSONField(null=True) after = JSONField(null=True) def __str__(self): return 'History {} - {} ({})'.format(self.date, HistoryTypus.name(self.typus), self.group) def changed(self): before = self.before or {} after = self.after or {} keys = set(after.keys()).union(before.keys()) changed_keys = [k for k in keys if before.get(k) != after.get(k)] return { 'before': {k: before.get(k) for k in changed_keys if k in before}, 'after': {k: after.get(k) for k in changed_keys if k in after}, }
class Activity(models.Model): event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name='activities') zone = models.ForeignKey(Zone, on_delete=models.PROTECT) type = enum.EnumField(ActivityType) start_date = models.DateTimeField() finish_date = models.DateTimeField() class Meta: verbose_name_plural = 'Activities' def __str__(self): return f'{self.event} - {self.zone} - {self.start_date:%d.%m.%Y-%H:%M}' @property def thing(self): items = { ActivityType.TALK: getattr(self, 'talk', None), ActivityType.WELCOME: WelcomeActivity(), ActivityType.CLOSE: CloseActivity(), ActivityType.COFFEE: CoffeeActivity(), ActivityType.LUNCH: LunchActivity(), ActivityType.DISCUSSION: self.discussion if hasattr(self, 'discussion') else DiscussionActivity() } return items.get(self.type)
class PluginConfigurationReference(KongProxyModel): api = models.ForeignKey( APIReference, related_name='plugins', help_text=_('The API on which to add a plugin configuration')) consumer = models.ForeignKey( 'ConsumerReference', null=True, blank=True, related_name='plugins', help_text= _('The consumer that overrides the existing settings for this specific consumer on incoming requests.' )) plugin = enum.EnumField( Plugins, default=Plugins.REQUEST_SIZE_LIMITING, help_text=_( 'The name of the Plugin that\'s going to be added. Currently the Plugin must be installed in every Kong ' 'instance separately.')) enabled = models.BooleanField(default=True) config = JSONField( default={}, help_text=_( 'The configuration properties for the Plugin which can be found on the plugins documentation page in the ' 'Plugin Gallery.')) objects = JSONAwareManager(json_fields=['config']) class Meta: verbose_name = _('Plugin Configuration Reference') verbose_name_plural = _('Plugin Configuration References') unique_together = [('plugin', 'api')] def __str__(self): return text_type(Plugins.label(self.plugin))
class User(AbstractBaseUser, PermissionsMixin): """ model for create user which extends AbstractBaseUser and Permissions """ name = models.CharField(max_length=250, null=True, blank=True) email = models.EmailField(max_length=250, unique=True) dob = models.DateField(auto_now_add=True, null=True, blank=True) gender_type = enum.EnumField(enums.GenderType, default=enums.GenderType.NOT_MENTIONED) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False, help_text=('Designates whether\ the user can log into this admin site.')) create_date = models.DateTimeField(auto_now_add=True) update_date = models.DateTimeField(auto_now_add=True) objects = CustomUserManager() USERNAME_FIELD = 'email' def get_short_name(self): "Returns the first name for the user." return self.name def get_full_name(self): "Returns the first name for the user." return self.name def __unicode__(self): return self.email
class Casting(models.Model): """ Represents a User being cast in a Role at an Event """ event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name='castings') profile = models.ForeignKey('userprofile.Profile', blank=True, null=True, on_delete=models.CASCADE, related_name='castings') role = enum.EnumField(Role) writein = models.CharField(max_length=64, blank=True, verbose_name='Write-In') class Meta: ordering = ['role'] @property def role_tag(self) -> Role: """ Returns the role as the Role enum """ return Role.get(self.role) @property def show_picture(self) -> bool: """ Returns True if the casting is a non-tech role with profile """ return self.profile and self.role < 30
class Event(models.Model): name = models.CharField(max_length=100) short_description = models.CharField(max_length=500) full_description = models.TextField(null=True, blank=True) ticket_description = models.TextField(null=True, blank=True) start_date = models.DateTimeField() finish_date = models.DateTimeField() venue = models.ForeignKey(Venue, on_delete=models.PROTECT) external_id = models.IntegerField(null=True, blank=True) image = models.URLField() image_vk = models.URLField(null=True, blank=True) image_facebook = models.URLField(null=True, blank=True) cfp_start = models.DateTimeField(null=True, blank=True) cfp_finish = models.DateTimeField(null=True, blank=True) cfp_url = models.URLField(null=True, blank=True) discussion_start = models.DateTimeField(null=True, blank=True) discussion_finish = models.DateTimeField(null=True, blank=True) status = enum.EnumField(EventStatusType) class Meta: permissions = [ ('view_draft', 'Can view draft event'), ] def __str__(self): return f'{self.name}, {self.start_date:%d.%m.%Y}' def clean(self): if self.external_id is not None: try: QTicketsInfo.check_event_exist(self.external_id) except Exception as e: raise forms.ValidationError( {'external_id': forms.ValidationError(str(e))})