class AssignmentCorrection(Model): """ Correction of an assignment """ UPLOAD_TO = "Corrections" assignment = models.OneToOneField(Assignment, verbose_name=_("Assignment")) attachment = FileField(_('Attachment'), blank=True, null=True, allowed_extensions=[ 'jpg', 'jpeg', 'png', 'docx', 'doc', 'odt', 'ppt', 'heic', 'pdf', 'xls', 'xlsx' ], upload_to=UPLOAD_TO, help_text=_("Upload a single image file here")) guideline = models.TextField(_('Guideline'), blank=True, null=True) cost = models.PositiveIntegerField(_('Cost of the correction'), blank=True, null=True, default=0) def __unicode__(self): return "%s" % self.assignment.title def get_obj_details(self): if self.cost == 0: return "<strong>Free</strong>" else: return "<strong>%(cost)s</strong>" % { 'cost': '{:,}'.format(self.cost) }
class Project(Model): name = models.CharField(_("Project's name"), max_length=150) leader = models.ForeignKey(Member) cost = models.IntegerField(_("Cost"), default=0) description = models.TextField(_("Project description")) attachment = FileField(_('Attachment'), allowed_extensions=['doc', 'docx', 'pdf', 'ppt', 'odt'], upload_to='Projects')
class Assignment(Model): """ Assignment given by a teacher """ UPLOAD_TO = "Assignments" subject = models.ForeignKey(Subject, verbose_name=_("Subject")) classroom = models.ForeignKey(Classroom, verbose_name=_("Classroom")) title = models.CharField(_('Title'), max_length=255, unique=True, null=True, blank=True) detail = models.TextField(_('Detail'), blank=True) attachment = FileField(_("Attachment"), blank=True, null=True, upload_to=UPLOAD_TO, allowed_extensions=[ 'jpg', 'jpeg', 'png', 'docx', 'doc', 'odt', 'ppt', 'heic', 'pdf', 'xls', 'xlsx' ], help_text=_("Upload a single image file here")) deadline = models.DateField(_("Deadline"), null=True, blank=True) def get_obj_details(self): return self.deadline.strftime("%Y/%m/%d") def __unicode__(self): return "%s: %s" % (self.subject.name, self.title)
class Album(AbstractWatchModel): artist = models.ForeignKey(Artist) title = models.CharField(max_length=100, db_index=True) slug = models.SlugField(db_index=True) cover = MultiImageField(upload_to='albums_covers', required_width=300, required_height=300, allowed_extensions=['jpg', 'jpeg'], blank=True, null=True, help_text=_("JPEG Image, 300 × 300px")) release = models.DateField(blank=True, null=True, db_index=True) archive = FileField(upload_to='albums_covers', allowed_extensions=['zip', 'rar', '7z'], blank=True, null=True) cost = models.IntegerField(default=0) is_active = models.BooleanField(default=True) is_main = models.BooleanField(default=False) show_on_home = models.BooleanField(default=False) order_of_appearance = models.IntegerField(default=0) tags = models.TextField(blank=True, null=True) turnover_history = ListField() earnings_history = ListField() units_sold_history = ListField() total_turnover = models.IntegerField(default=0) total_earnings = models.IntegerField(default=0) total_units_sold = models.IntegerField(default=0) class Meta: unique_together = ('artist', 'title') def __unicode__(self): return "%s - %s (%d)" % (self.artist.name, self.title, self.release.year) def _get_image(self): return self.cover image = property(_get_image) def get_obj_details(self): return "XAF %s" % intcomma(self.cost) def to_dict(self): val = super(Album, self).to_dict() val['type'] = 'album' val['url'] = reverse('mediashop:music_item_detail', args=(self.artist.slug, self.slug)) image_url = self.cover.name if self.cover.name else Service.LOGO_PLACEHOLDER val['image'] = getattr(settings, 'MEDIA_URL') + image_url return val
class Partner(Model): IMAGE_UPLOAD_TO = 'Gallery' logo = FileField(blank=True, null=True, allowed_extensions=['jpg', 'jpeg', 'png', 'heic'], upload_to=IMAGE_UPLOAD_TO, help_text=_("Upload a single logo file here")) name = models.CharField(_('Image name'), max_length=250, blank=True, null=True) def __unicode__(self): return self.name
class Gallery(Model): IMAGE_UPLOAD_TO = 'Gallery' media = FileField(blank=True, null=True, allowed_extensions=[ 'jpg', 'jpeg', 'png', 'heic', 'mp4', 'avi', 'webm', 'mov', 'ogg', 'wmv' ], upload_to=IMAGE_UPLOAD_TO, help_text=_("Upload a single media file here")) name = models.CharField(_('Image name'), max_length=250, blank=True, null=True) def __unicode__(self): return self.name
class Homework(Model): """ Homework sent by the student """ UPLOAD_TO = "Homeworks" assignment = models.ForeignKey(Assignment, verbose_name=_("Assignment")) student = models.ForeignKey(Student, verbose_name=_("Student")) attachment = FileField(_("Attachment"), blank=True, null=True, allowed_extensions=[ 'jpg', 'jpeg', 'png', 'docx', 'doc', 'odt', 'ppt', 'heic', 'pdf', 'xls', 'xlsx' ], upload_to=UPLOAD_TO) def __unicode__(self): return "%s: %s" % (self.assignment.subject.name, self.assignment.title)
class Application(Model): upload_to = 'careers/Applications' member = models.ForeignKey(Member, null=True) offer = models.ForeignKey(Offer, help_text=_('Position to which you apply')) allowed_notifications = models.BooleanField(help_text=_('Does applicant which ' 'to be notified for future job opportunities'), default=False, editable=True, null=True, blank=True) resume = FileField(verbose_name=_('Resume or CV'), allowed_extensions=['pdf', 'doc'], upload_to=upload_to, help_text=_('Upload your resume or CV here')) current_company = models.CharField(_('Name of the current company'), max_length=100, help_text=_('Name of the company you are currently working in'), null=True, blank=True) linkedin_url = models.URLField(_('LinkedIn URL'), null=True, blank=True) github_url = models.URLField(_('Github URL'), null=True, blank=True) portfolio_url = models.URLField(_('Link to your Portfolio'), null=True, blank=True) other_website = models.URLField(_('Other website URL'), null=True, blank=True) facebook_url = models.URLField(_('Facebook URL'), null=True, blank=True) instagram_url = models.URLField(_('Instagram URL'), null=True, blank=True) twitter_url = models.URLField(_('Twitter URL'), null=True, blank=True) youtube_url = models.URLField(_('YouTube URL'), null=True, blank=True) additional_information = models.TextField(_('Additional information'), null=True, blank=True, help_text=_('Add cover letter or anything else you want to share')) location = models.ForeignKey(_('Location'), help_text=_('Put the correct area and city where you live separated by a comma'), blank=True, null=True) def __unicode__(self): return "%(applicant_name)s: %(offer)s" %\ {'applicant_name': self.member.first_name, 'offer': self.offer} # g = GeoIP() # ip = request.META.get('REMOTE_ADDR', None) # if ip: # city = g.city(ip)['city'] # else: # city = 'Rome' # default city
class SchoolConfig(AbstractConfig, ResultsTracker): SESSION_AVG_CALCULATION_CHOICES = ((AVERAGE_OF_ALL, _("Average of sessions'scores")), (BEST_OF_ALL, _("Best score of all sessions"))) theme = models.ForeignKey(Theme, blank=True, null=True) back_to_school_date = models.DateTimeField(blank=True, null=True) registration_fees_title = models.CharField(_("Registration fees title"), max_length=60, default=_("Registration fees")) registration_fees_deadline = models.DateField( _("Registration fees deadline"), blank=True, null=True) first_instalment_title = models.CharField(_("First instalment title"), max_length=60, default=_("First instalment")) first_instalment_deadline = models.DateField( _("First instalment deadline"), blank=True, null=True) second_instalment_title = models.CharField(_("Second instalment title"), max_length=60, default=_("Second instalment")) second_instalment_deadline = models.DateField( _("Second instalment deadline"), blank=True, null=True) third_instalment_title = models.CharField(_("Third instalment title"), max_length=60, default=_("Third instalment")) third_instalment_deadline = models.DateField( _("Third instalment deadline"), blank=True, null=True) session_group_avg = models.CharField( max_length=60, choices=SESSION_AVG_CALCULATION_CHOICES, default=AVERAGE_OF_ALL, help_text=_("Method of calculation of Term score. Average of sessions " "scores or best score of all sessions.")) is_public = models.BooleanField( default=False, help_text="Designates whether this school is a State school.") show_discipline_report = models.BooleanField(_("Show discipline report"), default=True) show_lectures_report = models.BooleanField(_("Show lectures report"), default=True) my_kids_fees = models.IntegerField(_("MyKids annual fees"), default=2500) my_kids_fees_term = models.IntegerField(_("MyKids term fees"), default=1000) my_kids_fees_month = models.IntegerField(_("MyKids monthly fees"), default=375) my_kids_payment_period = models.IntegerField( _("Payment period"), default=30, help_text=_("Number of days left for parent to pay for the service.")) my_kids_share_rate = models.IntegerField( default=70, help_text="Percentage ikwen collects on MyKids fees payments") expected_student_count = models.IntegerField( _("Expected students count"), default=0, help_text='Total number of students (registered or not) of the school') # This must not be editable in the Admin website_is_active = models.BooleanField( default=False, help_text=_("Whether school subscribed to website service or no")) notification_emails = models.CharField( _("Notification email(s)"), max_length=150, blank=True, null=True, default='', help_text="Emails to which payment notifications are sent. " "Separate with coma if many. Eg: [email protected], [email protected]") has_subscribed_website_service = models.BooleanField( default=False, help_text=_("Check whether school subscribed " "to website service or not")) contract = FileField( _("School contract"), allowed_extensions=['pdf', 'doc', 'docx', 'odt'], help_text=_("Upload your signed contract in a single PDF file"), upload_to='Contracts') last_setup_status_check = models.DateTimeField(default=datetime.now) def __unicode__(self): return self.company_name def save(self, *args, **kwargs): if getattr(settings, 'IS_IKWEN', False): db = self.service.database add_database(db) try: obj_mirror = SchoolConfig.objects.using(db).get(pk=self.id) obj_mirror.is_public = self.is_public obj_mirror.my_kids_fees = self.my_kids_fees obj_mirror.my_kids_fees_term = self.my_kids_fees_term obj_mirror.my_kids_fees_month = self.my_kids_fees_month obj_mirror.my_kids_payment_period = self.my_kids_payment_period obj_mirror.my_kids_share_rate = self.my_kids_share_rate obj_mirror.ikwen_share_rate = self.ikwen_share_rate obj_mirror.ikwen_share_fixed = self.ikwen_share_fixed obj_mirror.cash_out_rate = self.cash_out_rate super(SchoolConfig, obj_mirror).save(using=db) except SchoolConfig.DoesNotExist: pass super(SchoolConfig, self).save(*args, **kwargs) else: before = SchoolConfig.objects.get(pk=self.id) bts = self.back_to_school_date # if bts.hour != 7 or bts.min != 30: if bts and (bts.hour != 7 or bts.min != 30): # Always set back to school time to 07:30 AM self.back_to_school_date = datetime(bts.year, bts.month, bts.day, 7, 30) super(SchoolConfig, self).save(*args, **kwargs) if before.my_kids_fees != self.my_kids_fees: from ikwen_foulassi.school.student.views import reset_my_kids_invoice if getattr(settings, 'DEBUG', False): reset_my_kids_invoice() else: Thread(target=reset_my_kids_invoice).start()
class Song(AbstractWatchModel): artist = models.ForeignKey(Artist) album = models.ForeignKey(Album, blank=True, null=True) title = models.CharField(max_length=100, db_index=True) slug = models.SlugField(db_index=True) cover = MultiImageField(upload_to='songs_covers', required_width=300, required_height=300, allowed_extensions=['jpg', 'jpeg'], blank=True, null=True, help_text=_("JPEG Image, 300 × 300px")) preview = models.FileField(upload_to='song_previews', blank=True, null=True, editable=False) media = FileField(upload_to='songs', blank=True, null=True, allowed_extensions=['mp3'], callback=generate_song_preview) download_link = models.URLField(blank=True, null=True) cost = models.IntegerField(default=0) is_active = models.BooleanField(default=True) show_on_home = models.BooleanField(default=False) order_of_appearance = models.IntegerField(default=0) tags = models.TextField(blank=True, null=True) turnover_history = ListField() earnings_history = ListField() units_sold_history = ListField() total_turnover = models.IntegerField(default=0) total_earnings = models.IntegerField(default=0) total_units_sold = models.IntegerField(default=0) class Meta: unique_together = ('artist', 'album', 'title') def __unicode__(self): return "%s - %s" % (self.title, self.artist.name) def _get_image(self): if self.cover and self.cover.name: return self.cover if self.album: return self.album.cover image = property(_get_image) def get_obj_details(self): return "XAF %d" % self.cost def to_dict(self): val = super(Song, self).to_dict() val['type'] = 'song' val['url'] = reverse('mediashop:music_item_detail', args=(self.artist.slug, self.slug)) image_url = self.image.name if self.image.name else Service.LOGO_PLACEHOLDER val['image'] = getattr(settings, 'MEDIA_URL') + image_url return val