Esempio n. 1
0
    def update_percent_done(self):
        if self.text_change is None or self.time_change is None:
            try:
                old_version = self.language.subtitleversion_set.exclude(pk=self.pk) \
                    .order_by('-version_no')[:1].get()
            except models.ObjectDoesNotExist:
                old_version = None
            
            self.set_changes(old_version)
            self.save()
            
        if self.language.is_original or self.is_forked:
            for l in self.language.video.subtitlelanguage_set.exclude(pk=self.language.pk):
                l.update_percent_done()
        else:
            self.language.update_percent_done()        
        check_alarm.delay(self.pk)
        
        if self.language.is_original and not self.language.language:
            detect_language.delay(self.pk)

        send_notification.delay(self.pk)
Esempio n. 2
0
    def test_notification_sending(self):
        from videos.tasks import send_notification, check_alarm, detect_language
        
        latest_version = self.language.latest_version()
        
        v = SubtitleVersion()
        v.language = self.language
        v.datetime_started = datetime.now()
        v.version_no = latest_version.version_no+1
        v.save()

        for s in latest_version.subtitle_set.all():
            s.duplicate_for(v).save()
        
        s = Subtitle()
        s.version = v
        s.subtitle_id = 'asdasdsadasdasdasd'
        s.subtitle_order = 5
        s.subtitle_text = 'new subtitle'
        s.start_time = 50
        s.end_time = 51
        s.save()        

        v.update_percent_done()
        self.assertEqual(len(mail.outbox), 1)
        
        result = send_notification.delay(v.id)
        if result.failed():
            self.fail(result.traceback)
        
        result = check_alarm.delay(v.id)
        if result.failed():
            self.fail(result.traceback)
        
        result = detect_language.delay(v.id)
        if result.failed():
            self.fail(result.traceback)