Beispiel #1
0
    def create_application(self, team_id, msg, user):
        if not user.is_authenticated():
            return Error(_('You should be authenticated.'))

        try:
            if not team_id:
                raise Team.DoesNotExist
            team = Team.objects.get(pk=team_id)
        except Team.DoesNotExist:
            return Error(_('Team does not exist'))

        try:
            tm = TeamMember.objects.get(team=team, user=user)
            return Error(_(u'You are already a member of this team.'))
        except TeamMember.DoesNotExist:
            pass

        if team.is_open():
            TeamMember(team=team, user=user).save()
            return Msg(
                _(u'You are now a member of this team because it is open.'))
        elif team.is_by_application():
            application, created = Application.objects.get_or_create(team=team,
                                                                     user=user)
            application.note = msg
            application.save()
            return Msg(
                _(u'Application sent success. Wait for answer from team.'))
        else:
            return Error(_(u'You can\'t join this team by application.'))
Beispiel #2
0
    def create_application(self, team_id, msg, user):
        if not user.is_authenticated():
            return Error(_('You should be authenticated.'))

        try:
            if not team_id:
                raise Team.DoesNotExist
            team = Team.objects.get(pk=team_id)
        except Team.DoesNotExist:
            return Error(_('Team does not exist'))

        try:
            TeamMember.objects.get(team=team, user=user)
            return Error(_(u'You are already a member of this team.'))
        except TeamMember.DoesNotExist:
            pass

        if team.is_open():
            TeamMember(team=team, user=user).save()
            return Msg(_(u'You are now a member of this team.'))
        elif team.is_by_application():

            if msg.strip() == '':
                return Error(_(u'The "About you" field is required in order to apply.'))

            application, created = Application.objects.get_or_create(team=team, user=user)
            application.note = msg

            application.save()
            notifier.application_sent.delay(application.pk)

            return Msg(_(u"Your application has been submitted. "
                         u"You will be notified of the team administrator's response"))
        else:
            return Error(_(u"You can't join this team by application."))
Beispiel #3
0
    def create_application(self, team_id, msg, user):
        if not user.is_authenticated():
            return Error(_('You should be authenticated.'))

        try:
            if not team_id:
                raise Team.DoesNotExist
            team = Team.objects.get(pk=team_id)
        except Team.DoesNotExist:
            return Error(_('Team does not exist'))

        try:
            TeamMember.objects.get(team=team, user=user)
            return Error(_(u'You are already a member of this team.'))
        except TeamMember.DoesNotExist:
            pass

        if team.is_open():
            TeamMember(team=team, user=user).save()
            return Msg(_(u'You are now a member of this team.'))
        elif team.is_by_application():

            if msg.strip() == '':
                return Error(
                    _(u'The "About you" field is required in order to apply.'))
            try:
                application = team.applications.get(user=user)
                if application.status == Application.STATUS_PENDING:
                    return Error(_(u'You have already applied to this team.'))
                elif application.status == Application.STATUS_DENIED:
                    return Error(_(u'Your application has been denied.'))
                elif application.status == Application.STATUS_MEMBER_REMOVED:
                    return Error(_(u'You have been removed from this team.'))
                elif application.status == Application.STATUS_MEMBER_LEFT:
                    # the user chose to participate, so we can already approve it
                    application.note = msg
                    application.approve(author=application.user,
                                        interface='web UI')
                    return Msg(
                        _(u"Your application has been approved. "
                          u"You are now a member of this team"))
            except Application.DoesNotExist:
                application = Application(team=team, user=user)
            application.note = msg
            application.save(author=user, interface='web UI')
            notifier.application_sent.delay(application.pk)

            return Msg(
                _(u"Your application has been submitted. "
                  u"You will be notified of the team administrator's response")
            )
        else:
            return Error(_(u"You can't join this team by application."))
Beispiel #4
0
    def change_title_video(self, video_pk, title, user):
        title = title.strip()
        if not user.is_authenticated():
            return Error(self.authentication_error_msg)

        if not title:
            return Error(_(u'Title can\'t be empty'))

        try:
            video = Video.objects.get(pk=video_pk)
            if title and not video.title or video.is_html5(
            ) or user.is_superuser:
                if title != video.title:
                    old_title = video.title_display()
                    video.title = title
                    video.slug = slugify(video.title)
                    video.save()
                    send_change_title_email.delay(video.id, user and user.id,
                                                  old_title.encode('utf8'),
                                                  video.title.encode('utf8'))
            else:
                return Error(_(u'Title can\'t be changed for this video'))
        except Video.DoesNotExist:
            return Error(_(u'Video does not exist'))

        return Msg(_(u'Title was changed success'))
Beispiel #5
0
    def set_email(self, email, user):
        if not user.is_authenticated():
            return Error(_(u'You should be authenticated.'))

        form = EditUserEmailForm(dict(email=email), instance=user)
        if form.is_valid():
            form.save()
            return Msg(_(u'Your email was updated.'))
        else:
            return Error(form.errors['email'])
Beispiel #6
0
 def unfollow_language(self, language_id, user):
     if not user.is_authenticated():
         return Error(self.authentication_error_msg)
     
     try:
         language = SubtitleLanguage.objects.get(pk=language_id)
     except SubtitleLanguage.DoesNotExist:
         return Error(_(u'Subtitles does not exist.'))
     
     language.followers.remove(user)
     
     return Msg(_(u'You stopped following this subtitles now.'))
Beispiel #7
0
 def unfollow(self, video_id, user):
     if not user.is_authenticated():
         return Error(self.authentication_error_msg)
     
     try:
         video = Video.objects.get(pk=video_id)
     except Video.DoesNotExist:
         return Error(_(u'Video does not exist.'))
     
     video.followers.remove(user)
     
     for l in video.subtitlelanguage_set.all():
         l.followers.remove(user)        
     
     return Msg(_(u'You stopped following this video now.'))
Beispiel #8
0
 def change_title_translation(self, language_id, title, user):
     if not user.is_authenticated():
         return Error(self.authentication_error_msg)
     
     if not title:
         return Error(_(u'Title can\'t be empty'))
     
     try:
         sl = SubtitleLanguage.objects.get(id=language_id)
     except SubtitleLanguage.DoesNotExist:
         return Error(_(u'Subtitle language does not exist'))
     
     if not sl.standard_language_id:
         sl.title = title
         sl.save()
         update_search_index.delay(Video, sl.video_id)
         return Msg(_(u'Title was changed success'))
     else:
         return Error(_(u'This is not forked translation'))
Beispiel #9
0
    def leave(self, team_id, user):
        if not user.is_authenticated():
            return Error(_('You should be authenticated.'))

        try:
            team = Team.objects.get(pk=team_id)
        except Team.DoesNotExist:
            return Error(_('Team does not exist'))

        try:
            tm = TeamMember.objects.get(team=team, user=user)
            if team.members.exclude(pk=tm.pk).exists():
                tm.delete()
                return Msg(_(u'You are not a member of team now.'),
                           is_open=team.is_open())
            else:
                return Error(_(u'You are last member of this team.'))
        except TeamMember.DoesNotExist:
            return Error(_(u'You are not a member of this team.'))
Beispiel #10
0
    def join(self, team_id, user):
        if not user.is_authenticated():
            return Error(_('You should be authenticated.'))

        try:
            team = Team.objects.get(pk=team_id)
        except Team.DoesNotExist:
            return Error(_('Team does not exist'))

        try:
            TeamMember.objects.get(team=team, user=user)
            return Error(_(u'You are already a member of this team.'))
        except TeamMember.DoesNotExist:
            pass

        if not team.is_open():
            return Error(_(u'This team is not open.'))
        else:
            TeamMember(team=team, user=user).save()
            return Msg(_(u'You are now a member of this team.'))
Beispiel #11
0
    def promote_user(self, team_id, member_id, role, user):
        try:
            team = Team.objects.for_user(user).get(pk=team_id)
        except Team.DoesNotExist:
            return Error(_(u'Team does not exist.'))

        if not team.is_manager(user):
            return Error(_(u'You are not manager of this team.'))

        if not role in dict(TeamMember.ROLES):
            return Error(_(u'Incorrect team member role.'))

        try:
            tm = TeamMember.objects.get(pk=member_id, team=team)
        except TeamMember.DoesNotExist:
            return Error(_(u'Team member does not exist.'))

        if tm.user == user:
            return Error(_(u'You can\'t promote yourself.'))

        tm.role = role
        tm.save()
        return Msg(_(u'Team member role changed.'))
Beispiel #12
0
 def test_api(self, message, user):
     return Msg(u'Received message: "%s" from user "%s"' %
                (message, unicode(user)))