Пример #1
0
    def forwards(self, orm):

        # Rename releases if needed, since we now have reserved release slugs.
        for res_slug in RESERVED_RELEASE_SLUGS:
            for rel in Release.objects.filter(slug=res_slug):
                rel.slug = get_new_slug(rel.slug)
                rel.save()

        # Populate all-resources release:
        for project in Project.objects.all():
            update_all_release(project)
    def forwards(self, orm):
    
        # Rename releases if needed, since we now have reserved release slugs.
        for res_slug in RESERVED_RELEASE_SLUGS:
            for rel in Release.objects.filter(slug=res_slug):
                rel.slug = get_new_slug(rel.slug)
                rel.save()

        # Populate all-resources release:
        for project in Project.objects.all():
            update_all_release(project)
Пример #3
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))