def get_workflow_override(video): team_video = video.get_team_video() if team_video is None: return DONT_OVERRIDE # if we have have a video from cache also get the team from cache if video.cache.cache_pattern is not None: team = Team.cache.get_instance(team_video.team_id, video.cache.cache_pattern) team_video.team = team team_workflow = TeamWorkflow.get_workflow(team) else: team_workflow = TeamWorkflow.get_workflow(team_video.team) return team_workflow.get_subtitle_workflow(team_video)
def __init__(self, user, *args, **kwargs): self.user = user super(CreateTeamForm, self).__init__(*args, **kwargs) self.fields['workflow_type'].choices = TeamWorkflow.get_choices() self.fields['video_url'].label = _(u'Team intro video URL') self.fields['video_url'].required = False self.fields['video_url'].help_text = _( u'''You can put an optional video on your team homepage that explains what your team is about, to attract volunteers. Enter a link to any compatible video, or to any video page on our site.''') self.fields['is_visible'].widget.attrs['class'] = 'checkbox' self.fields['slug'].label = _( u'Team URL: http://universalsubtitles.org/teams/')
class TeamUpdateSerializer(TeamSerializer): name = serializers.CharField(required=False) slug = serializers.SlugField(required=False) type = MappedChoiceField(source='workflow_type', read_only=True, choices=TeamWorkflow.get_api_choices())
class TeamSerializer(serializers.ModelSerializer): type = MappedChoiceField(source='workflow_type', required=False, default='O', choices=TeamWorkflow.get_api_choices()) # Handle mapping internal values for membership/video policy to the values # we use in the api (currently the english display name) MEMBERSHIP_POLICY_CHOICES = ( (Team.OPEN, u'Open'), (Team.APPLICATION, u'Application'), (Team.INVITATION_BY_ALL, u'Invitation by any team member'), (Team.INVITATION_BY_MANAGER, u'Invitation by manager'), (Team.INVITATION_BY_ADMIN, u'Invitation by admin'), ) VIDEO_POLICY_CHOICES = ( (Team.VP_MEMBER, u'Any team member'), (Team.VP_MANAGER, u'Managers and admins'), (Team.VP_ADMIN, u'Admins only'), ) membership_policy = MappedChoiceField( MEMBERSHIP_POLICY_CHOICES, required=False, default=Team._meta.get_field('membership_policy').get_default()) video_policy = MappedChoiceField( VIDEO_POLICY_CHOICES, required=False, default=Team._meta.get_field('video_policy').get_default()) team_visibility = EnumField(TeamVisibility, required=False) video_visibility = EnumField(VideoVisibility, required=False) is_visible = IsVisibleField(required=False, default=None) activity_uri = serializers.HyperlinkedIdentityField( view_name='api:team-activity', lookup_field='slug', ) members_uri = serializers.SerializerMethodField() projects_uri = serializers.SerializerMethodField() applications_uri = serializers.SerializerMethodField() tasks_uri = serializers.SerializerMethodField() languages_uri = serializers.SerializerMethodField() resource_uri = serializers.SerializerMethodField() def get_fields(self): fields = super(TeamSerializer, self).get_fields() if (self.instance and isinstance(self.instance, Team) and self.instance.is_old_style()): del fields['team_visibility'] del fields['video_visibility'] return fields def get_members_uri(self, team): return reverse('api:team-members-list', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def get_projects_uri(self, team): return reverse('api:projects-list', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def get_applications_uri(self, team): if not team.is_by_application(): return None return reverse('api:team-application-list', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def get_languages_uri(self, team): if not team.is_old_style(): return None return reverse('api:team-languages', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def get_tasks_uri(self, team): if not team.workflow_enabled: return None return reverse('api:tasks-list', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def get_resource_uri(self, team): return reverse('api:teams-detail', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def save(self): is_visible = self.validated_data.pop('is_visible', None) team = super(TeamSerializer, self).save() if is_visible is not None: team.set_legacy_visibility(is_visible) team.save() return team def create(self, validated_data): if 'team_visibility' not in validated_data: validated_data['team_visibility'] = 'public' if 'video_visibility' not in validated_data: validated_data['video_visibility'] = 'public' return super(TeamSerializer, self).create(validated_data) class Meta: model = Team fields = ('name', 'slug', 'type', 'description', 'team_visibility', 'video_visibility', 'is_visible', 'membership_policy', 'video_policy', 'activity_uri', 'members_uri', 'projects_uri', 'applications_uri', 'languages_uri', 'tasks_uri', 'resource_uri')
class TeamSerializer(serializers.ModelSerializer): type = MappedChoiceField(source='workflow_type', required=False, default='O', choices=TeamWorkflow.get_api_choices()) # Handle mapping internal values for membership/video policy to the values # we use in the api (currently the english display name) MEMBERSHIP_POLICY_CHOICES = ( (Team.OPEN, u'Open'), (Team.APPLICATION, u'Application'), (Team.INVITATION_BY_ALL, u'Invitation by any team member'), (Team.INVITATION_BY_MANAGER, u'Invitation by manager'), (Team.INVITATION_BY_ADMIN, u'Invitation by admin'), ) VIDEO_POLICY_CHOICES = ( (Team.VP_MEMBER, u'Any team member'), (Team.VP_MANAGER, u'Managers and admins'), (Team.VP_ADMIN, u'Admins only'), ) membership_policy = MappedChoiceField( MEMBERSHIP_POLICY_CHOICES, required=False, default=Team._meta.get_field('membership_policy').get_default()) video_policy = MappedChoiceField( VIDEO_POLICY_CHOICES, required=False, default=Team._meta.get_field('video_policy').get_default()) activity_uri = serializers.HyperlinkedIdentityField( view_name='api:team-activity', lookup_field='slug', ) members_uri = serializers.SerializerMethodField() projects_uri = serializers.SerializerMethodField() applications_uri = serializers.SerializerMethodField() tasks_uri = serializers.SerializerMethodField() languages_uri = serializers.SerializerMethodField() resource_uri = serializers.SerializerMethodField() def get_members_uri(self, team): return reverse('api:team-members-list', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def get_projects_uri(self, team): return reverse('api:projects-list', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def get_applications_uri(self, team): if not team.is_by_application(): return None return reverse('api:team-application-list', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def get_languages_uri(self, team): if not team.is_old_style(): return None return reverse('api:team-languages', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def get_tasks_uri(self, team): if not team.workflow_enabled: return None return reverse('api:tasks-list', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) def get_resource_uri(self, team): return reverse('api:teams-detail', kwargs={ 'team_slug': team.slug, }, request=self.context['request']) class Meta: model = Team fields = ('name', 'slug', 'type', 'description', 'is_visible', 'membership_policy', 'video_policy', 'activity_uri', 'members_uri', 'projects_uri', 'applications_uri', 'languages_uri', 'tasks_uri', 'resource_uri')