Exemplo n.º 1
0
    def test_create_project(self):
        team = self._create_base_team()
        self.client.login(**self.auth)

        url = reverse("teams:add_project", kwargs={"slug": team.slug})

        data = {
            "name": u"Test Project",
            "description": u"Test Project",
            "review_allowed": u"0",
            "approve_allowed": u"0",
        }

        response = self.client.post(url, data)
        self.failUnlessEqual(response.status_code, 302)

        slug = pan_slugify(data['name'])

        project = Project.objects.get(slug=slug)
        self.assertEqual(project.name, data['name'])
        self.assertEqual(project.description, data['description'])

        # creating a duplicated project results in error
        response = self.client.post(url, data)
        self.failUnlessEqual(response.status_code, 200)
        self.assertFalse(response.context['form'].is_valid())
Exemplo n.º 2
0
    def clean_name(self):
        name = self.cleaned_data['name']

        same_name_qs = self.team.project_set.filter(slug=pan_slugify(name))
        if self.instance.id is not None:
            same_name_qs = same_name_qs.exclude(id=self.instance.id)

        import logging
        logging.warn("%s %s", same_name_qs.exists(), same_name_qs.query)
        logging.warn("%s", [p.slug for p in self.team.project_set.all()])

        if same_name_qs.exists():
            raise forms.ValidationError(
                _(u"There's already a project with this name"))
        return name
Exemplo n.º 3
0
 def setup_video(video, video_url):
     video.is_public = team.videos_public()
     if video_item.get('title'):
         video.title = video_item['title']
     if video_item.get('description'):
         video.description = video_item['description']
     if video_item.get('language'):
         language = video_item['language'].lower()
         if language in SUPPORTED_LANGUAGE_CODES:
             video.primary_audio_language_code = language
         else:
             messages.append(
                 fmt(_(
                     u"Badly formated language for %(url)s: %(language)s, ignoring it."
                 ),
                     url=video_url,
                     language=video_item['language']))
     if video_item.get('duration') and not video.duration:
         try:
             video.duration = int(video_item['duration'])
         except:
             messages.append(
                 fmt(_(
                     u"Badly formated duration for %(url)s: %(duration)s, ignoring it."
                 ),
                     url=video_url,
                     duration=video_item['duration']))
     if video_item.get('project'):
         project, created = Project.objects.get_or_create(
             team=team,
             slug=pan_slugify(video_item['project']),
             defaults={'name': video_item['project']})
     else:
         project = team.default_project
     team_video = TeamVideo.objects.create(video=video,
                                           team=team,
                                           project=project,
                                           added_by=user)
Exemplo n.º 4
0
def add_team_videos(team_pk, user_pk, videos):
    from .permissions import can_add_videos_bulk
    from teams.models import Team, Project, TeamVideo
    from videos.models import Video
    from videos.types import video_type_registrar
    from auth.models import CustomUser as User
    from utils.subtitles import load_subtitles
    from subtitles.pipeline import add_subtitles
    user = User.objects.get(pk=int(user_pk))
    team = Team.objects.get(pk=int(team_pk))
    num_successful_videos = 0
    messages = []
    if can_add_videos_bulk(user):
        for video_item in videos:
            video_url = video_item['url']
            try:
                video_type = video_type_registrar.video_type_for_url(video_url)
                video_url = video_type.convert_to_video_url()
            except:
                messages.append(
                    fmt(_(u"Unknown video type: %(url)s\n"), url=video_url))
                continue
            title = u""
            description = u""
            if len(video_item['description']) > 0:
                description = video_item['description']
            set_values = {'is_public': team.is_visible}
            if len(video_item['title']) > 0:
                set_values['title'] = video_item['title']
            if len(video_item['description']) > 0:
                set_values['description'] = video_item['description']
            video, created = Video.get_or_create_for_url(video_url,
                                                         video_type,
                                                         user,
                                                         set_values=set_values,
                                                         in_task=True)
            if not created and video.get_team_video() is not None:
                messages.append(
                    fmt(_(u"Video is already part of a team: %(url)s\n"),
                        url=video_url))
                continue
            modified_video = False
            if not created:
                video.is_public = team.is_visible
                video.title = video_item['title']
                video.description = video_item['description']
                modified_video = True
            if 'language' in video_item and len(video_item['language']) > 0:
                language = video_item['language'].lower()
                if language in LANGUAGE_CHOICES:
                    video.primary_audio_language_code = language
                    modified_video = True
                else:
                    messages.append(
                        fmt(_(
                            u"Badly formated language for %(url)s: %(language)s, ignoring it."
                        ),
                            url=video_url,
                            language=video_item['language']))
            if 'duration' in video_item and len(video_item['duration']) > 0:
                try:
                    video.duration = int(video_item['duration'])
                    modified_video = True
                except:
                    messages.append(
                        fmt(_(
                            u"Badly formated duration for %(url)s: %(duration)s, ignoring it."
                        ),
                            url=video_url,
                            duration=video_item['duration']))
            if modified_video:
                video.save()
            if 'transcript' in video_item and len(
                    video_item['transcript']
            ) > 0 and video.primary_audio_language_code:
                try:
                    sub_type = video_item['transcript'].split(".")[-1]
                    r = requests.get(video_item['transcript'])
                    if r.ok:
                        subs = load_subtitles(
                            video.primary_audio_language_code, r.text,
                            sub_type)
                        version = add_subtitles(
                            video, video.primary_audio_language_code, subs)
                    else:
                        raise Exception("Request not successful")
                except Exception, e:
                    logger.error(
                        "Error while importing transcript file: {}".format(
                            str(e)))
                    messages.append(
                        fmt(_(
                            u"Invalid transcript file or language code for video %(url)s\n"
                        ),
                            url=video_url))
            if created:
                num_successful_videos += 1
            if 'project' in video_item and len(video_item['project']) > 0:
                project, created = Project.objects.get_or_create(
                    team=team,
                    slug=pan_slugify(video_item['project']),
                    defaults={'name': video_item['project']})
                project_id = project.id
            else:
                project_id = None
            team_video = TeamVideo.objects.create(video=video,
                                                  team=team,
                                                  project_id=project_id)