Ejemplo n.º 1
0
def release_delete(request, project_slug, release_slug):
    release = get_object_or_404(Release, slug=release_slug,
                                project__slug=project_slug)
    if request.method == 'POST':
        import copy
        release_ = copy.copy(release)
        release.delete()
        messages.success(request,
                        _("The release '%s' was deleted.") % release.full_name)

        # ActionLog & Notification
        nt = 'project_release_deleted'
        context = {'release': release_,
                   'sender': request.user}
        action_logging(request.user, [release_.project], nt, context=context)
        if settings.ENABLE_NOTICES:
            txnotification.send_observation_notices_for(release_.project,
                                signal=nt, extra_context=context)

        return HttpResponseRedirect(reverse('project_detail',
                                     args=(project_slug,)))
    else:
        return render_to_response('projects/release_confirm_delete.html',
                                  {'release': release,},
                                  context_instance=RequestContext(request))
Ejemplo n.º 2
0
def _send_notice_save_action(request, notice):
    """
    Handler for manipulating notifications and save action logs

    The argument notice must have the following dictionary structure:

    notice = {
        'type': '<notice_type_label>',
        'object': <object>,
        'sendto': [<list_of_users_to_send_to>],
        'extra_context': {'var_needed_in_template': var_needed_in_template},
    }

    Explanation:
        `type`: It is the notice label related to the action
        `object`: It is the object that is suffering the action
        `sendto`: List of Users to sent the notification to
        `extra_context`: Any extra var used in the message templates
    """
    action_logging(request.user, [notice['object']],
                   notice['type'],
                   context=notice['extra_context'])
    if settings.ENABLE_NOTICES:
        notification.send(set(notice['sendto']),
                          notice['type'],
                          extra_context=notice['extra_context'])
Ejemplo n.º 3
0
def release_delete(request, project_slug, release_slug):
    release = get_object_or_404(Release,
                                slug=release_slug,
                                project__slug=project_slug)
    if request.method == 'POST':
        import copy
        release_ = copy.copy(release)
        release.delete()
        messages.success(
            request,
            _("The release '%s' was deleted.") % release.full_name)

        # ActionLog & Notification
        nt = 'project_release_deleted'
        context = {'release': release_, 'sender': request.user}
        action_logging(request.user, [release_.project], nt, context=context)
        if settings.ENABLE_NOTICES:
            txnotification.send_observation_notices_for(release_.project,
                                                        signal=nt,
                                                        extra_context=context)

        return HttpResponseRedirect(
            reverse('project_detail', args=(project_slug, )))
    else:
        return HttpResponseRedirect(
            reverse('release_edit', args=(project_slug, release_slug)))
Ejemplo n.º 4
0
def project_hub_join_withdraw(request, project_slug):

    # project_slug here refers to outsourced_project_slug. It was kept like
    # it to keep consistency across url regexes.
    hub_request = get_object_or_404(HubRequest, project__slug=project_slug)

    if request.POST:
        try:
            _hub_request = copy.copy(hub_request)
            hub_request.delete()
            messages.success(request, _("Request to join '%s' project hub "
                "was withdrawn") % _hub_request.project_hub)

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_hub_join_withdrawn'
            context = {'hub_request': _hub_request,
                       'performer': request.user,
                       'sender': request.user}

            # Logging action
            action_logging(request.user, [_hub_request.project,
                hub_request.project_hub], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for maintainers, coordinators and the user
                notification.send(_hub_request.project_hub.maintainers.all(),
                    nt, context)
        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % e.message)
Ejemplo n.º 5
0
def team_join_withdraw(request, project_slug, language_code):

    team = get_object_or_404(Team, project__slug=project_slug,
        language__code=language_code)
    project = team.project
    access_request = get_object_or_404(TeamAccessRequest, team__pk=team.pk,
        user__pk=request.user.pk)

    if request.POST:
        try:
            access_request.delete()
            messages.success(request,_(
                "You withdrew your request to join the '%s' team."
                ) % team.language.name)

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_withdrawn'
            context = {'access_request': access_request,
                       'performer': request.user,}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers, coordinators
                notification.send(set(itertools.chain(project.maintainers.all(),
                    team.coordinators.all())), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 6
0
def team_request_deny(request, project_slug, language_code):

    team_request = get_object_or_404(TeamRequest, project__slug=project_slug,
        language__code=language_code)
    project = team_request.project

    if request.POST:
        try:
            team_request.delete()
            messages.success(request, _(
                "You rejected the request by '%(user)s' for a '%(team)s' team."
                ) % {'team':team_request.language.name,
                     'user':team_request.user})

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_request_denied'
            context = {'team_request': team_request,
                       'performer': request.user}

            # Logging action
            action_logging(request.user, [project], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers and the user
                notification.send(set(itertools.chain(project.maintainers.all(),
                    [team_request.user])), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 7
0
def team_delete(request, project_slug, language_code):

    project = get_object_or_404(Project, slug=project_slug)
    team = get_object_or_404(Team, project__pk=project.pk,
        language__code=language_code)

    if request.method == "POST":
        _team = copy.copy(team)
        team.delete()
        messages.success(request, _("The team '%s' was deleted.") % _team.language.name)

        # ActionLog & Notification
        # TODO: Use signals
        nt = 'project_team_deleted'
        context = {'team': _team}

        # Logging action
        action_logging(request.user, [project, _team], nt, context=context)

        if settings.ENABLE_NOTICES:
            # Send notification for those that are observing this project
            txnotification.send_observation_notices_for(project,
                    signal=nt, extra_context=context)
            # Send notification for maintainers
            notification.send(project.maintainers.all(), nt, context)

        return HttpResponseRedirect(reverse("team_list",
                                     args=(project_slug,)))
    else:
        return render_to_response("teams/team_confirm_delete.html",
                                  {"team": team,},
                                  context_instance=RequestContext(request))
Ejemplo n.º 8
0
def team_join_request(request, project_slug, language_code):

    team = get_object_or_404(Team,
                             project__slug=project_slug,
                             language__code=language_code)
    project = team.project

    if request.POST:
        if request.user in team.members.all() or \
            request.user in team.coordinators.all():
            messages.warning(
                request,
                _("You are already on the '%s' team.") % team.language.name)
        try:
            # send pre_team_join signal
            cla_sign = 'cla_sign' in request.POST and request.POST['cla_sign']
            cla_sign = cla_sign and True
            pre_team_join.send(sender='join_team_view',
                               project=project,
                               user=request.user,
                               cla_sign=cla_sign)

            access_request = TeamAccessRequest(team=team, user=request.user)
            access_request.save()
            messages.success(
                request,
                _("You requested to join the '%s' team.") % team.language.name)
            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_requested'
            context = {
                'access_request': access_request,
                'sender': request.user
            }

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                notification.send(
                    set(
                        itertools.chain(project.maintainers.all(),
                                        team.coordinators.all())), nt, context)

        except IntegrityError:
            transaction.rollback()
            messages.error(
                request,
                _("You already requested to join the '%s' team.") %
                team.language.name)
        except ClaNotSignedError, e:
            messages.error(request,
                             _("You need to sign the Contribution License Agreement for this "\
                "project before you join a translation team"))
Ejemplo n.º 9
0
def team_join_approve(request, project_slug, language_code, username):

    team = get_object_or_404(Team,
                             project__slug=project_slug,
                             language__code=language_code)
    project = team.project
    user = get_object_or_404(User, username=username)
    access_request = get_object_or_404(TeamAccessRequest,
                                       team__pk=team.pk,
                                       user__pk=user.pk)

    if request.POST:
        if user in team.members.all() or \
            user in team.coordinators.all():
            messages.warning(
                request,
                _("User '%(user)s' is already on the '%(team)s' team.") % {
                    'user': user,
                    'team': team.language.name
                })
            access_request.delete()
        try:
            team.members.add(user)
            team.save()
            messages.success(
                request,
                _("You added '%(user)s' to the '%(team)s' team.") % {
                    'user': user,
                    'team': team.language.name
                })
            access_request.delete()

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_approved'
            context = {
                'access_request': access_request,
                'sender': request.user
            }

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers, coordinators and the user
                notification.send(
                    set(
                        itertools.chain(project.maintainers.all(),
                                        team.coordinators.all(),
                                        [access_request.user])), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 10
0
def _project_create_update(request, project_slug=None, template_name="projects/project_form.html"):
    """
    Handler for creating and updating a project.

    This function helps to eliminate duplication of code between those two
    actions, and also allows to apply different permission checks in the
    respective views.
    """

    if project_slug:
        project = get_object_or_404(Project, slug=project_slug)
    else:
        project = None

    if request.method == "POST":
        project_form = ProjectForm(request.POST, instance=project, prefix="project")
        if project_form.is_valid():
            project = project_form.save(commit=False)
            project_id = project.id
            # Only here the owner is written to the project model
            if not project_id:
                project.owner = request.user

            # provide the form data to any signal handlers before project_save
            Signal.send(signals.pre_proj_save, sender=Project, instance=project, form=project_form)
            project.save()
            project_form.save_m2m()

            # TODO: Not sure if here is the best place to put it
            Signal.send(signals.post_proj_save_m2m, sender=Project, instance=project, form=project_form)

            # ActionLog & Notification
            context = {"project": project}
            if not project_id:
                nt = "project_added"
                action_logging(request.user, [project], nt, context=context)
            else:
                nt = "project_changed"
                action_logging(request.user, [project], nt, context=context)
                if settings.ENABLE_NOTICES:
                    txnotification.send_observation_notices_for(project, signal=nt, extra_context=context)

            return HttpResponseRedirect(reverse("project_detail", args=[project.slug]))
    else:
        # Make the current user the maintainer when adding a project
        if project:
            initial_data = {}
        else:
            initial_data = {"maintainers": [request.user.pk]}

        project_form = ProjectForm(instance=project, prefix="project", initial=initial_data)

    return render_to_response(
        template_name, {"project_form": project_form, "project": project}, context_instance=RequestContext(request)
    )
Ejemplo n.º 11
0
def exit(request, project_slug, lang_code, resource_slug=None, *args, **kwargs):
    """
    Exiting Lotte
    """
    if request.method != 'POST':
        return HttpResponse(status=405)

    # Permissions handling
    # Project should always be available
    project = get_object_or_404(Project, slug=project_slug)
    team = Team.objects.get_or_none(project, lang_code)
    check = ProjectPermission(request.user)
    if not check.submit_translations(team or project) and not\
        check.maintain(project):
        return permission_denied(request)

    language = Language.objects.by_code_or_alias(lang_code)

    resources = []
    if resource_slug:
        resources = Resource.objects.filter(slug=resource_slug, project=project)
        if not resources:
            raise Http404
    else:
        resources = Resource.objects.filter(project=project)


    data = simplejson.loads(request.raw_post_data)

    if data.get('updated'):
        modified = True
        # ActionLog & Notification
        for resource in resources:
            nt = 'project_resource_translated'
            context = {'project': project,
                       'resource': resource,
                       'language': language,
                       'sender': request.user}
            object_list = [project, resource, language]
            if team:
                object_list.append(team)
            action_logging(request.user, object_list, nt, context=context)
    else:
        modified = False

    lotte_done.send(None, request=request, resources=resources,
        language=language, modified=modified)

    redirect_url = reverse('team_detail', args=[project_slug, language.code])

    if request.is_ajax():
        json = simplejson.dumps(dict(redirect=redirect_url))
        return HttpResponse(json, mimetype='application/json')

    return HttpResponseRedirect(redirect_url)
Ejemplo n.º 12
0
def team_leave(request, project_slug, language_code):

    team = get_object_or_404(Team,
                             project__slug=project_slug,
                             language__code=language_code)
    project = team.project

    if request.POST:
        try:
            if (team.members.filter(username=request.user.username).exists()
                    or team.reviewers.filter(
                        username=request.user.username).exists()):
                team.members.remove(request.user)
                team.reviewers.remove(request.user)
                messages.info(
                    request,
                    _("You left the '%s' team.") % team.language.name)

                # ActionLog & Notification
                # TODO: Use signals
                nt = 'project_team_left'
                context = {
                    'team': team,
                    'performer': request.user,
                    'sender': request.user
                }

                # Logging action
                action_logging(request.user, [project, team],
                               nt,
                               context=context)

                if settings.ENABLE_NOTICES:
                    # Send notification for those that are observing this project
                    txnotification.send_observation_notices_for(
                        project, signal=nt, extra_context=context)
                    # Send notification for maintainers, coordinators
                    notification.send(
                        set(
                            itertools.chain(project.maintainers.all(),
                                            team.coordinators.all())), nt,
                        context)
            else:
                messages.info(
                    request,
                    _("You are not in the '%s' team.") % team.language.name)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 13
0
def exit(request, project_slug, lang_code, resource_slug=None, *args, **kwargs):
    """
    Exiting Lotte
    """

    # Permissions handling
    # Project should always be available
    project = get_object_or_404(Project, slug=project_slug)
    team = Team.objects.get_or_none(project, lang_code)
    check = ProjectPermission(request.user)
    if not check.submit_translations(team or project) and not\
        check.maintain(project):
        return permission_denied(request)

    language = Language.objects.by_code_or_alias(lang_code)

    resources = []
    if resource_slug:
        resources = Resource.objects.filter(slug=resource_slug, project=project)
        if not resources:
            raise Http404
        url = reverse('resource_detail', args=[project_slug, resource_slug])
    else:
        resources = Resource.objects.filter(project=project)
        url = reverse('project_detail', args=[project_slug])

    if request.POST.get('updated', None) == 'true':
        modified = True
        # ActionLog & Notification
        for resource in resources:
            nt = 'project_resource_translated'
            context = {'project': project,
                       'resource': resource,
                       'language': language}
            object_list = [project, resource, language]
            action_logging(request.user, object_list, nt, context=context)
            if settings.ENABLE_NOTICES:
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
    else:
        modified = False

    lotte_done.send(None, request=request, resources=resources,
        language=language, modified=modified)

    if request.is_ajax():
        json = simplejson.dumps(dict(redirect=url))
        return HttpResponse(json, mimetype='application/json')

    return HttpResponseRedirect(url)
Ejemplo n.º 14
0
def _delete_project(request, project):
    import copy
    project_ = copy.copy(project)
    project.delete()

    messages.success(request, _("The project '%s' was deleted." % project.name))

    # ActionLog & Notification
    nt = 'project_deleted'
    context = {'project': project_}
    action_logging(request.user, [project_], nt, context=context)
    if settings.ENABLE_NOTICES:
        txnotification.send_observation_notices_for(project_,
            signal=nt, extra_context=context)
Ejemplo n.º 15
0
def team_join_request(request, project_slug, language_code):

    team = get_object_or_404(Team, project__slug=project_slug,
        language__code=language_code)
    project = team.project

    if request.POST:
        if request.user in team.members.all() or \
            request.user in team.coordinators.all():
            messages.warning(request,
                          _("You are already on the '%s' team.") % team.language.name)
        try:
            # send pre_team_join signal
            cla_sign = 'cla_sign' in request.POST and request.POST['cla_sign']
            cla_sign = cla_sign and True
            pre_team_join.send(sender='join_team_view', project=project,
                               user=request.user, cla_sign=cla_sign)

            access_request = TeamAccessRequest(team=team, user=request.user)
            access_request.save()
            messages.success(request,
                _("You requested to join the '%s' team.") % team.language.name)
            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_requested'
            context = {'access_request': access_request,
                       'sender': request.user}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                notification.send(set(itertools.chain(project.maintainers.all(),
                    team.coordinators.all())), nt, context)


        except IntegrityError:
            transaction.rollback()
            messages.error(request,
                            _("You already requested to join the '%s' team.")
                             % team.language.name)
        except ClaNotSignedError, e:
            messages.error(request,
                             _("You need to sign the Contribution License Agreement for this "\
                "project before you join a translation team"))
Ejemplo n.º 16
0
def _delete_project(request, project):
    project_ = copy.copy(project)
    project.delete()
    Permission.objects.filter(content_type__model="project",
                              object_id=project_.id).delete()

    messages.success(request,
                     _("The project '%s' was deleted." % project.name))

    # ActionLog & Notification
    nt = 'project_deleted'
    context = {'project': project_, 'sender': request.user}
    action_logging(request.user, [project_], nt, context=context)
    if settings.ENABLE_NOTICES:
        txnotification.send_observation_notices_for(project_,
                                                    signal=nt,
                                                    extra_context=context)
Ejemplo n.º 17
0
def release_create_update(request,
                          project_slug,
                          release_slug=None,
                          *args,
                          **kwargs):
    project = get_object_or_404(Project, slug__exact=project_slug)
    if release_slug:
        release = get_object_or_404(Release,
                                    slug=release_slug,
                                    project__slug=project_slug)
    else:
        release = None
    if request.method == 'POST':
        release_form = ReleaseForm(project,
                                   request.user,
                                   request.POST,
                                   instance=release)
        if release_form.is_valid():
            if release:
                nt = "project_release_changed"
                created = False
            else:
                nt = "project_release_added"
                created = True
            release = release_form.save()
            context = {
                'project': project,
                'release': release,
            }
            object_list = [project, release]
            action_logging(request.user, object_list, nt, context=context)
            post_release_save.send(sender=None,
                                   instance=release,
                                   created=created,
                                   user=request.user)
            return HttpResponseRedirect(
                reverse('release_detail', args=[project_slug, release.slug]))
    else:
        release_form = ReleaseForm(project, request.user, instance=release)

    return render_to_response('projects/release_form.html', {
        'form': release_form,
        'project': project,
        'release': release,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 18
0
def team_request_approve(request, project_slug, language_code):

    team_request = get_object_or_404(TeamRequest,
                                     project__slug=project_slug,
                                     language__code=language_code)
    project = team_request.project

    if request.POST:
        try:
            team = Team(project=team_request.project,
                        language=team_request.language,
                        creator=request.user)
            team.save()
            team.coordinators.add(team_request.user)
            team.save()
            team_request.delete()
            messages.success(
                request,
                _("You approved the '%(team)s' team requested by '%(user)s'.")
                % {
                    'team': team.language.name,
                    'user': team_request.user
                })

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_added'
            context = {'team': team, 'sender': request.user}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                notification.send(
                    set(
                        itertools.chain(project.maintainers.all(),
                                        team.coordinators.all())), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 19
0
def project_hub_join_approve(request, project_slug, outsourced_project_slug):

    hub_request = get_object_or_404(HubRequest,
                                    project__slug=outsourced_project_slug,
                                    project_hub__slug=project_slug)

    outsourced_project = hub_request.project

    if request.POST:
        try:
            outsourced_project.outsource = hub_request.project_hub
            outsourced_project.anyone_submit = False
            outsourced_project.save()

            _hub_request = copy.copy(hub_request)
            hub_request.delete()

            messages.success(
                request,
                _("You added '%(project)s' to the "
                  "'%(project_hub)s' project hub") % {
                      'project': outsourced_project,
                      'project_hub': hub_request.project_hub
                  })

            # ActionLog & Notification
            nt = 'project_hub_join_approved'
            context = {'hub_request': hub_request, 'sender': request.user}

            # Logging action
            action_logging(request.user,
                           [outsourced_project, hub_request.project_hub],
                           nt,
                           context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for maintainers, coordinators and the user
                notification.send(outsourced_project.maintainers.all(), nt,
                                  context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))

        project_outsourced_changed.send(sender=hub_request.project_hub)
Ejemplo n.º 20
0
def team_join_approve(request, project_slug, language_code, username):

    team = get_object_or_404(Team, project__slug=project_slug,
        language__code=language_code)
    project = team.project
    user = get_object_or_404(User, username=username)
    access_request = get_object_or_404(TeamAccessRequest, team__pk=team.pk,
        user__pk=user.pk)

    if request.POST:
        if user in team.members.all() or \
            user in team.coordinators.all():
            messages.warning(request,
                            _("User '%(user)s' is already on the '%(team)s' team.")
                            % {'user':user, 'team':team.language.name})
            access_request.delete()
        try:
            team.members.add(user)
            team.save()
            messages.success(request,
                            _("You added '%(user)s' to the '%(team)s' team.")
                            % {'user':user, 'team':team.language.name})
            access_request.delete()

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_approved'
            context = {'access_request': access_request,
                       'sender': request.user}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers, coordinators and the user
                notification.send(set(itertools.chain(project.maintainers.all(),
                    team.coordinators.all(), [access_request.user])), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 21
0
def project_hub_join_deny(request, project_slug, outsourced_project_slug):

    hub_request = get_object_or_404(HubRequest,
                                    project__slug=outsourced_project_slug,
                                    project_hub__slug=project_slug)

    outsourced_project = hub_request.project

    if request.POST:
        try:
            _hub_request = copy.copy(hub_request)
            hub_request.delete()

            messages.info(
                request,
                _("You rejected the request of "
                  "'%(project)s' to join the '%(project_hub)s' project hub") %
                {
                    'project': outsourced_project,
                    'project_hub': _hub_request.project_hub
                })

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_hub_join_denied'
            context = {'hub_request': hub_request, 'sender': request.user}

            # Logging action
            action_logging(request.user,
                           [outsourced_project, _hub_request.project_hub],
                           nt,
                           context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for maintainers, coordinators and the user
                notification.send(outsourced_project.maintainers.all(), nt,
                                  context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % e.message)

        project_outsourced_changed.send(sender=hub_request.project_hub)
Ejemplo n.º 22
0
def team_join_withdraw(request, project_slug, language_code):

    team = get_object_or_404(Team,
                             project__slug=project_slug,
                             language__code=language_code)
    project = team.project
    access_request = get_object_or_404(TeamAccessRequest,
                                       team__pk=team.pk,
                                       user__pk=request.user.pk)

    if request.POST:
        try:
            access_request.delete()
            messages.success(
                request,
                _("You withdrew your request to join the '%s' team.") %
                team.language.name)

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_withdrawn'
            context = {
                'access_request': access_request,
                'performer': request.user,
                'sender': request.user
            }

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers, coordinators
                notification.send(
                    set(
                        itertools.chain(project.maintainers.all(),
                                        team.coordinators.all())), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 23
0
def team_request_deny(request, project_slug, language_code):

    team_request = get_object_or_404(TeamRequest,
                                     project__slug=project_slug,
                                     language__code=language_code)
    project = team_request.project

    if request.POST:
        try:
            team_request.delete()
            messages.success(
                request,
                _("You rejected the request by '%(user)s' for a '%(team)s' team."
                  ) % {
                      'team': team_request.language.name,
                      'user': team_request.user
                  })

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_request_denied'
            context = {
                'team_request': team_request,
                'performer': request.user,
                'sender': request.user
            }

            # Logging action
            action_logging(request.user, [project], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers and the user
                notification.send(
                    set(
                        itertools.chain(project.maintainers.all(),
                                        [team_request.user])), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 24
0
def team_delete(request, project_slug, language_code):

    project = get_object_or_404(Project, slug=project_slug)
    team = get_object_or_404(Team,
                             project__pk=project.pk,
                             language__code=language_code)

    if request.method == "POST":
        _team = copy.copy(team)
        team.delete()
        messages.success(request,
                         _("The team '%s' was deleted.") % _team.language.name)

        # ActionLog & Notification
        # TODO: Use signals
        nt = 'project_team_deleted'
        context = {'team': _team, 'sender': request.user}

        #Delete rlstats for this team in outsourced projects
        for p in project.outsourcing.all():
            RLStats.objects.select_related('resource').by_project_and_language(
                p, _team.language).filter(translated=0).delete()

        # Logging action
        action_logging(request.user, [project, _team], nt, context=context)

        if settings.ENABLE_NOTICES:
            # Send notification for those that are observing this project
            txnotification.send_observation_notices_for(project,
                                                        signal=nt,
                                                        extra_context=context)
            # Send notification for maintainers
            notification.send(project.maintainers.all(), nt, context)

        return HttpResponseRedirect(
            reverse("project_detail", args=(project_slug, )))
    else:
        return render_to_response("teams/team_confirm_delete.html", {
            "team": team,
            "project": team.project
        },
                                  context_instance=RequestContext(request))
Ejemplo n.º 25
0
def project_delete(request, project_slug):
    project = get_object_or_404(Project, slug=project_slug)
    if request.method == "POST":
        import copy

        project_ = copy.copy(project)
        project.delete()

        messages.success(request, "The project '%s' was deleted." % project.name)

        # ActionLog & Notification
        nt = "project_deleted"
        context = {"project": project_}
        action_logging(request.user, [project_], nt, context=context)

        return HttpResponseRedirect(reverse("project_list"))
    else:
        return render_to_response(
            "projects/project_confirm_delete.html", {"project": project}, context_instance=RequestContext(request)
        )
Ejemplo n.º 26
0
def team_leave(request, project_slug, language_code):

    team = get_object_or_404(Team, project__slug=project_slug,
        language__code=language_code)
    project = team.project

    if request.POST:
        try:
            if (team.members.filter(username=request.user.username).exists() or
                team.reviewers.filter(username=request.user.username).exists()):
                team.members.remove(request.user)
                team.reviewers.remove(request.user)
                messages.info(request, _(
                    "You left the '%s' team."
                    ) % team.language.name)

                # ActionLog & Notification
                # TODO: Use signals
                nt = 'project_team_left'
                context = {'team': team,
                           'performer': request.user,
                           'sender': request.user}

                # Logging action
                action_logging(request.user, [project, team], nt, context=context)

                if settings.ENABLE_NOTICES:
                    # Send notification for those that are observing this project
                    txnotification.send_observation_notices_for(project,
                            signal=nt, extra_context=context)
                    # Send notification for maintainers, coordinators
                    notification.send(set(itertools.chain(project.maintainers.all(),
                        team.coordinators.all())), nt, context)
            else:
                messages.info(request, _(
                    "You are not in the '%s' team."
                    ) % team.language.name)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 27
0
def project_hub_join_approve(request, project_slug, outsourced_project_slug):

    hub_request = get_object_or_404(HubRequest,
        project__slug=outsourced_project_slug,
        project_hub__slug=project_slug)

    outsourced_project = hub_request.project

    if request.POST:
        try:
            outsourced_project.outsource = hub_request.project_hub
            outsourced_project.anyone_submit = False
            outsourced_project.save()

            _hub_request = copy.copy(hub_request)
            hub_request.delete()

            messages.success(request, _("You added '%(project)s' to the "
                "'%(project_hub)s' project hub")% {
                    'project':outsourced_project,
                    'project_hub':hub_request.project_hub})

            # ActionLog & Notification
            nt = 'project_hub_join_approved'
            context = {'hub_request': hub_request,
                       'sender': request.user}

            # Logging action
            action_logging(request.user, [outsourced_project,
                hub_request.project_hub], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for maintainers, coordinators and the user
                notification.send(outsourced_project.maintainers.all(), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))

        project_outsourced_changed.send(sender=hub_request.project_hub)
Ejemplo n.º 28
0
def team_delete(request, project_slug, language_code):

    project = get_object_or_404(Project, slug=project_slug)
    team = get_object_or_404(Team, project__pk=project.pk,
        language__code=language_code)

    if request.method == "POST":
        _team = copy.copy(team)
        team.delete()
        messages.success(request, _("The team '%s' was deleted.") % _team.language.name)

        # ActionLog & Notification
        # TODO: Use signals
        nt = 'project_team_deleted'
        context = {'team': _team,
                   'sender': request.user}

        #Delete rlstats for this team in outsourced projects
        for p in project.outsourcing.all():
            RLStats.objects.select_related('resource').by_project_and_language(
                    p, _team.language).filter(translated=0).delete()

        # Logging action
        action_logging(request.user, [project, _team], nt, context=context)

        if settings.ENABLE_NOTICES:
            # Send notification for those that are observing this project
            txnotification.send_observation_notices_for(project,
                    signal=nt, extra_context=context)
            # Send notification for maintainers
            notification.send(project.maintainers.all(), nt, context)

        return HttpResponseRedirect(reverse("project_detail",
                                     args=(project_slug,)))
    else:
        return render_to_response(
            "teams/team_confirm_delete.html",
            {"team": team, "project": team.project},
            context_instance=RequestContext(request)
        )
Ejemplo n.º 29
0
def team_request_approve(request, project_slug, language_code):

    team_request = get_object_or_404(TeamRequest, project__slug=project_slug,
        language__code=language_code)
    project = team_request.project

    if request.POST:
        try:
            team = Team(project=team_request.project,
                language=team_request.language, creator=request.user)
            team.save()
            team.coordinators.add(team_request.user)
            team.save()
            team_request.delete()
            messages.success(request, _(
                "You approved the '%(team)s' team requested by '%(user)s'."
                ) % {'team':team.language.name, 'user':team_request.user})

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_added'
            context = {'team': team,
                       'sender': request.user}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                notification.send(set(itertools.chain(project.maintainers.all(),
                    team.coordinators.all())), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 30
0
def project_hub_join_deny(request, project_slug, outsourced_project_slug):

    hub_request = get_object_or_404(HubRequest,
        project__slug=outsourced_project_slug,
        project_hub__slug=project_slug)

    outsourced_project = hub_request.project

    if request.POST:
        try:
            _hub_request = copy.copy(hub_request)
            hub_request.delete()

            messages.info(request, _("You rejected the request of "
                "'%(project)s' to join the '%(project_hub)s' project hub")% {
                    'project': outsourced_project,
                    'project_hub':_hub_request.project_hub})

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_hub_join_denied'
            context = {'hub_request': hub_request,
                       'sender': request.user}

            # Logging action
            action_logging(request.user, [outsourced_project,
                _hub_request.project_hub], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for maintainers, coordinators and the user
                notification.send(outsourced_project.maintainers.all(), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % e.message)

        project_outsourced_changed.send(sender=hub_request.project_hub)
Ejemplo n.º 31
0
def project_hub_join_withdraw(request, project_slug):

    # project_slug here refers to outsourced_project_slug. It was kept like
    # it to keep consistency across url regexes.
    hub_request = get_object_or_404(HubRequest, project__slug=project_slug)

    if request.POST:
        try:
            _hub_request = copy.copy(hub_request)
            hub_request.delete()
            messages.success(
                request,
                _("Request to join '%s' project hub "
                  "was withdrawn") % _hub_request.project_hub)

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_hub_join_withdrawn'
            context = {
                'hub_request': _hub_request,
                'performer': request.user,
                'sender': request.user
            }

            # Logging action
            action_logging(request.user,
                           [_hub_request.project, hub_request.project_hub],
                           nt,
                           context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for maintainers, coordinators and the user
                notification.send(_hub_request.project_hub.maintainers.all(),
                                  nt, context)
        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % e.message)
Ejemplo n.º 32
0
def _send_notice_save_action(request, notice):
    """
    Handler for manipulating notifications and save action logs

    The argument notice must have the following dictionary structure:

    notice = {
        'type': '<notice_type_label>',
        'object': <object>,
        'sendto': [<list_of_users_to_send_to>],
        'extra_context': {'var_needed_in_template': var_needed_in_template},
    }

    Explanation:
        `type`: It is the notice label related to the action
        `object`: It is the object that is suffering the action
        `sendto`: List of Users to sent the notification to
        `extra_context`: Any extra var used in the message templates
    """
    action_logging(request.user, [notice['object']], notice['type'],
                context=notice['extra_context'])
    if settings.ENABLE_NOTICES:
        notification.send(set(notice['sendto']),
            notice['type'], extra_context=notice['extra_context'])
Ejemplo n.º 33
0
def release_create_update(request, project_slug, release_slug=None, *args, **kwargs):
    project = get_object_or_404(Project, slug__exact=project_slug)
    if release_slug:
        release = get_object_or_404(Release, slug=release_slug,
                                    project__slug=project_slug)
    else:
        release = None
    if request.method == 'POST':
        release_form = ReleaseForm(
            project, request.user, request.POST, instance=release
        )
        if release_form.is_valid():
            if release:
                nt = "project_release_changed"
                created = False
            else:
                nt = "project_release_added"
                created = True
            release = release_form.save()
            context = {'project': project,
                       'release': release,}
            object_list = [project, release]
            action_logging(request.user, object_list, nt, context=context)
            post_release_save.send(sender=None, instance=release,
                    created=created, user=request.user)
            return HttpResponseRedirect(
                reverse('release_detail',
                         args=[project_slug, release.slug]))
    else:
        release_form = ReleaseForm(project, request.user, instance=release)

    return render_to_response('projects/release_form.html', {
        'form': release_form,
        'project': project,
        'release': release,
    }, context_instance=RequestContext(request))
Ejemplo n.º 34
0
def user_nudge(request, username):
    """View for nudging a user"""
    user = get_object_or_404(User, username=username)
    ctype = ContentType.objects.get_for_model(user)

    #It's just allowed to re-nudge the same person after 15 minutes
    last_minutes = datetime.datetime.today() - datetime.timedelta(minutes=15)

    log_entries = LogEntry.objects.filter(user=request.user,
        object_id=user.pk, content_type=ctype, action_time__gt=last_minutes)

    if log_entries:
        messages.warning(request,
                         _("You can't re-nudge the same user in a short amount of time."))
    elif user.pk == request.user.pk:
        messages.warning(request, _("You can't nudge yourself."))
    else:
        context={'performer': request.user}
        nt= 'user_nudge'
        action_logging(request.user, [user], nt, context=context)
        notification.send([user], nt, context)
        messages.success(request, _("You have nudged '%s'.") % user)

    return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
Ejemplo n.º 35
0
def exit(request,
         project_slug,
         lang_code,
         resource_slug=None,
         *args,
         **kwargs):
    """
    Exiting Lotte
    """
    if request.method != 'POST':
        return HttpResponse(status=405)

    # Permissions handling
    # Project should always be available
    project = get_object_or_404(Project, slug=project_slug)
    team = Team.objects.get_or_none(project, lang_code)
    check = ProjectPermission(request.user)
    if not check.submit_translations(team or project) and not\
        check.maintain(project):
        return permission_denied(request)

    language = Language.objects.by_code_or_alias(lang_code)

    resources = []
    if resource_slug:
        resources = Resource.objects.filter(slug=resource_slug,
                                            project=project)
        if not resources:
            raise Http404
    else:
        resources = Resource.objects.filter(project=project)

    data = simplejson.loads(request.raw_post_data)

    if data.get('updated'):
        modified = True
        # ActionLog & Notification
        for resource in resources:
            nt = 'project_resource_translated'
            context = {
                'project': project,
                'resource': resource,
                'language': language,
                'sender': request.user
            }
            object_list = [project, resource, language]
            if team:
                object_list.append(team)
            action_logging(request.user, object_list, nt, context=context)
    else:
        modified = False

    lotte_done.send(None,
                    request=request,
                    resources=resources,
                    language=language,
                    modified=modified)

    redirect_url = reverse('team_detail', args=[project_slug, language.code])

    if request.is_ajax():
        json = simplejson.dumps(dict(redirect=redirect_url))
        return HttpResponse(json, mimetype='application/json')

    return HttpResponseRedirect(redirect_url)
Ejemplo n.º 36
0
def project_access_control_edit(request, project_slug):
    project = get_object_or_404(Project, slug=project_slug)
    outsourced = project.outsource
    if request.method == 'POST':
        form = ProjectAccessControlForm(request.POST,
                                        instance=project,
                                        user=request.user)
        if form.is_valid():
            access_control = form.cleaned_data['access_control']
            project_type = form.cleaned_data['project_type']
            project = form.save(commit=False)
            project_hub = project.outsource
            hub_request = None

            # TODO call signal project_outsourced_changed
            if 'outsourced' != project_type:
                project.outsource = None
            else:
                check = ProjectPermission(request.user)
                if not (check.maintain(project)
                        and check.maintain(project_hub)):
                    # If the user is not maintainer of both projects it does
                    # not associate the outsource project directly.
                    # It does a request instead.
                    try:
                        hub_request = HubRequest.objects.get(project=project)
                    except ObjectDoesNotExist:
                        hub_request = HubRequest(project=project)
                    hub_request.project_hub = project_hub
                    hub_request.user = request.user
                    hub_request.save()

                    messages.success(
                        request,
                        _("Requested to join the '%s' project hub.") %
                        project_hub)
                    # ActionLog & Notification
                    # TODO: Use signals
                    nt = 'project_hub_join_requested'
                    context = {
                        'hub_request': hub_request,
                        'sender': request.user
                    }

                    # Logging action
                    action_logging(request.user, [project, project_hub],
                                   nt,
                                   context=context)

                    if settings.ENABLE_NOTICES:
                        # Send notification for project hub maintainers
                        notification.send(project_hub.maintainers.all(), nt,
                                          context)

                    return HttpResponseRedirect(
                        reverse('project_detail', args=[project.slug]), )

            if 'hub' == project_type:
                project.is_hub = True
            else:
                project.is_hub = False

            if ('free_for_all' == access_control
                    and project_type != "outsourced"):
                project.anyone_submit = True
            else:
                project.anyone_submit = False

            # Check if cla form exists before sending the signal
            if 'limited_access' == access_control and \
            form.cleaned_data.has_key('cla_license_text'):
                # send signal to save CLA
                signals.cla_create.send(
                    sender='project_access_control_edit_view',
                    project=project,
                    license_text=form.cleaned_data['cla_license_text'],
                    request=request)

            project.save()
            form.save_m2m()
            handle_stats_on_access_control_edit(project)
            project_outsourced_changed.send(sender=project_hub)

            if outsourced and not project.outsource:
                # Drop resources from all-resources release of the hub project
                update_all_release(outsourced)

                # Logging action
                nt = 'project_hub_left'
                context = {
                    'project': project,
                    'project_hub': outsourced,
                    'sender': request.user
                }
                action_logging(request.user, [project, outsourced],
                               nt,
                               context=context)

            return HttpResponseRedirect(
                reverse('project_detail', args=[project.slug]), )

    else:
        form = ProjectAccessControlForm(instance=project, user=request.user)

    return render_to_response('projects/project_form_access_control.html', {
        'project_permission': True,
        'project': project,
        'form': form,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 37
0
def _project_create_update(request,
                           project_slug=None,
                           template_name='projects/project_form.html'):
    """
    Handler for creating and updating a project.

    This function helps to eliminate duplication of code between those two
    actions, and also allows to apply different permission checks in the
    respective views.
    """

    if project_slug:
        project = get_object_or_404(Project, slug=project_slug)
    else:
        project = None

    if request.method == 'POST':
        owner = project and project.owner or request.user
        project_form = ProjectForm(request.POST,
                                   request.FILES,
                                   instance=project,
                                   prefix='project',
                                   owner=owner)
        if project_form.is_valid():
            project = project_form.save(commit=False)
            project_id = project.id
            # Only here the owner is written to the project model
            if not project_id:
                project.owner = request.user

            # provide the form data to any signal handlers before project_save
            Signal.send(signals.pre_proj_save,
                        sender=Project,
                        instance=project,
                        form=project_form)
            project.save()
            project_form.save_m2m()

            # TODO: Not sure if here is the best place to put it
            Signal.send(signals.post_proj_save_m2m,
                        sender=Project,
                        instance=project,
                        form=project_form)

            # ActionLog & Notification
            context = {'project': project, 'sender': request.user}
            if not project_id:
                nt = 'project_added'
                action_logging(request.user, [project], nt, context=context)
            else:
                nt = 'project_changed'
                action_logging(request.user, [project], nt, context=context)
                if settings.ENABLE_NOTICES:
                    txnotification.send_observation_notices_for(
                        project, signal=nt, extra_context=context)

            return HttpResponseRedirect(
                reverse('project_detail', args=[project.slug]), )
    else:
        # Make the current user the maintainer when adding a project
        if project:
            initial_data = {}
        else:
            initial_data = {"maintainers": [request.user.pk]}

        project_form = ProjectForm(instance=project,
                                   prefix='project',
                                   initial=initial_data)

    return render_to_response(template_name, {
        'project_form': project_form,
        'project': project,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 38
0
def team_request(request, project_slug):

    if request.POST:
        language_pk = request.POST.get('language', None)
        if not language_pk:
            messages.error(request, _(
                "Please select a language before submitting the form."))
            return HttpResponseRedirect(reverse("team_list",
                                        args=[project_slug,]))


        project = get_object_or_404(Project, slug=project_slug)

        language = get_object_or_404(Language, pk=int(language_pk))

        try:
            team = Team.objects.get(project__pk=project.pk,
                language__pk=language.pk)
            messages.warning(request,_(
                "'%s' team already exists.") % team.language.name)
        except Team.DoesNotExist:
            try:
                team_request = TeamRequest.objects.get(project__pk=project.pk,
                    language__pk=language.pk)
                messages.warning(request, _(
                    "A request to create the '%s' team already exists.")
                    % team_request.language.name)
            except TeamRequest.DoesNotExist:
                try:
                    # send pre_team_request signal
                    cla_sign = 'cla_sign' in request.POST and \
                            request.POST['cla_sign']
                    cla_sign = cla_sign and True
                    pre_team_request.send(sender='request_team_view',
                                          project=project,
                                          user=request.user,
                                          cla_sign=cla_sign)

                    team_request = TeamRequest(project=project,
                        language=language, user=request.user)
                    team_request.save()
                    messages.info(request, _(
                        "You requested creation of the '%s' team.")
                        % team_request.language.name)

                    # ActionLog & Notification
                    # TODO: Use signals
                    nt = 'project_team_requested'
                    context = {'team_request': team_request}

                    # Logging action
                    action_logging(request.user, [project], nt, context=context)

                    if settings.ENABLE_NOTICES:
                        # Send notification for those that are observing this project
                        txnotification.send_observation_notices_for(project,
                                signal=nt, extra_context=context)
                        # Send notification for maintainers
                        notification.send(project.maintainers.all(), nt, context)

                except IntegrityError, e:
                    transaction.rollback()
                    logger.error("Something weird happened: %s" % str(e))
                except ClaNotSignedError, e:
                    messages.error(request, _(
                        "You need to sign the Contribution License Agreement "\
                        "for this project before you submit a team creation "\
                        "request."
                    ))
Ejemplo n.º 39
0
def _team_create_update(request, project_slug, language_code=None):
    """
    Handler for creating and updating a team of a project.

    This function helps to eliminate duplication of code between those two
    actions, and also allows to apply different permission checks in the
    respective views.
    """
    project = get_object_or_404(Project, slug=project_slug)
    team = None

    if language_code:
        try:
            team = Team.objects.get(project__pk=project.pk,
                language__code=language_code)
        except Team.DoesNotExist:
            pass

    if request.POST:
        form = TeamSimpleForm(project, language_code, request.POST, instance=team)
        form.data["creator"] = request.user.pk
        if form.is_valid():
            team=form.save(commit=False)
            team_id = team.id
            team.save()
            form.save_m2m()

            # Delete access requests for users that were added
            for member in itertools.chain(team.members.all(),
                team.coordinators.all()):
                tr = TeamAccessRequest.objects.get_or_none(team, member)
                if tr:
                    tr.delete()

            # ActionLog & Notification
            # TODO: Use signals
            if not team_id:
                nt = 'project_team_added'
            else:
                nt = 'project_team_changed'

            context = {'team': team}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                from notification.models import NoticeType
                try:
                    notification.send(set(itertools.chain(project.maintainers.all(),
                        team.coordinators.all())), nt, context)
                except NoticeType.DoesNotExist:
                    pass

            return HttpResponseRedirect(reverse("team_detail",
                                        args=[project.slug, team.language.code]))
    else:
        form=TeamSimpleForm(project, language_code, instance=team)

    return render_to_response("teams/team_form.html",
                              {"project": project,
                               "team": team,
                               "project_team_form": form,
                               "project_team_page": True},
                                context_instance=RequestContext(request))
Ejemplo n.º 40
0
def team_request(request, project_slug):

    if request.POST:
        language_pk = request.POST.get('language', None)
        if not language_pk:
            messages.error(
                request,
                _("Please select a language before submitting the form."))
            return HttpResponseRedirect(
                reverse("project_detail", args=[
                    project_slug,
                ]))

        project = get_object_or_404(Project, slug=project_slug)

        language = get_object_or_404(Language, pk=int(language_pk))

        try:
            team = Team.objects.get(project__pk=project.pk,
                                    language__pk=language.pk)
            messages.warning(
                request,
                _("'%s' team already exists.") % team.language.name)
        except Team.DoesNotExist:
            try:
                team_request = TeamRequest.objects.get(
                    project__pk=project.pk, language__pk=language.pk)
                messages.warning(
                    request,
                    _("A request to create the '%s' team already exists.") %
                    team_request.language.name)
            except TeamRequest.DoesNotExist:
                try:
                    # send pre_team_request signal
                    cla_sign = 'cla_sign' in request.POST and \
                            request.POST['cla_sign']
                    cla_sign = cla_sign and True
                    pre_team_request.send(sender='request_team_view',
                                          project=project,
                                          user=request.user,
                                          cla_sign=cla_sign)

                    team_request = TeamRequest(project=project,
                                               language=language,
                                               user=request.user)
                    team_request.save()
                    messages.info(
                        request,
                        _("You requested creation of the '%s' team.") %
                        team_request.language.name)

                    # ActionLog & Notification
                    # TODO: Use signals
                    nt = 'project_team_requested'
                    context = {
                        'team_request': team_request,
                        'sender': request.user
                    }

                    # Logging action
                    action_logging(request.user, [project],
                                   nt,
                                   context=context)

                    if settings.ENABLE_NOTICES:
                        # Send notification for those that are observing this project
                        txnotification.send_observation_notices_for(
                            project, signal=nt, extra_context=context)
                        # Send notification for maintainers
                        notification.send(project.maintainers.all(), nt,
                                          context)

                except IntegrityError, e:
                    transaction.rollback()
                    logger.error("Something weird happened: %s" % str(e))
                except ClaNotSignedError, e:
                    messages.error(request, _(
                        "You need to sign the Contribution License Agreement "\
                        "for this project before you submit a team creation "\
                        "request."
                    ))
Ejemplo n.º 41
0
def _team_create_update(request,
                        project_slug,
                        language_code=None,
                        extra_context=None):
    """
    Handler for creating and updating a team of a project.

    This function helps to eliminate duplication of code between those two
    actions, and also allows to apply different permission checks in the
    respective views.
    """
    project = get_object_or_404(Project, slug=project_slug)
    team, language = None, None

    if language_code:
        language = get_object_or_404(Language, code=language_code)
        try:
            team = Team.objects.get(project__pk=project.pk, language=language)
        except Team.DoesNotExist:
            pass

    if request.POST:
        form = TeamSimpleForm(project, language, request.POST, instance=team)
        form.data["creator"] = request.user.pk
        if form.is_valid():
            team = form.save(commit=False)
            team_id = team.id
            team.save()
            form.save_m2m()

            # Delete access requests for users that were added
            for member in itertools.chain(team.members.all(),
                                          team.coordinators.all()):
                tr = TeamAccessRequest.objects.get_or_none(team, member)
                if tr:
                    tr.delete()

            # ActionLog & Notification
            # TODO: Use signals
            if not team_id:
                nt = 'project_team_added'
            else:
                nt = 'project_team_changed'

            context = {'team': team, 'sender': request.user}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)
            update_team_request(team)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                from notification.models import NoticeType
                try:
                    notification.send(
                        set(
                            itertools.chain(project.maintainers.all(),
                                            team.coordinators.all())), nt,
                        context)
                except NoticeType.DoesNotExist:
                    pass

            return HttpResponseRedirect(
                reverse("team_members",
                        args=[project.slug, team.language.code]))
    else:
        form = TeamSimpleForm(project, language, instance=team)

    context = {
        "project": project,
        "team": team,
        "project_team_form": form,
    }

    if extra_context:
        context.update(extra_context)

    return render_to_response("teams/team_form.html",
                              context,
                              context_instance=RequestContext(request))