Esempio n. 1
0
def repo_pull_request(request, slug, repo_name):
    repo = Repo.objects.get(directory_name__exact = repo_name, local_parent_project__project_id__exact = slug)
    # We pass off to a queue event
    msg_string = {}
                
    msg_string['directory_name'] = repo.directory_name
    msg_string['local_parent_project'] = repo.local_parent_project.project_id
                
    q = Queue.objects.get(name='repoupdate')
    update = simplejson.dumps(msg_string)
    msg = Message(message=update, queue=q)
    try:
        msg.save()
        request.user.message_set.create(message="Your repository update has been queued!")
    except:
        request.user.message_set.create(message="The repository queue has failed!")
    return HttpResponseRedirect(reverse('view-tip', kwargs={'slug': slug, 'repo_name':repo_name}))
Esempio n. 2
0
def repo_create(request, slug):
    """
        This function displays a form based on the model of the repo to authorised users
        who can create repos.  If the repo does not already exist in the project then it
        is created and the user is redirected there
    """
    
    # Get the project from the database that we want to associate with
    project = get_object_or_404(Project, project_id__exact=slug)
    
    if request.is_ajax():
        template = 'repos/repo_create_ajax.html'
    else:
        template = 'repos/repo_create.html'
    
    # Lets decide if we show the form or create a repo
    if request.method == "POST":
        # Were saving, so lets create our instance
        repo = Repo(
                    local_parent_project=project,
                    created=True,
                    local_manager = request.user
                )
        form = RepoCreateForm(request.POST, instance=repo)
        
        # Lets check the form is valid
        if form.is_valid():
            creation_method = str(form.cleaned_data['creation_method'])
            if creation_method== "New":
                # We create the repo right away
                u = ui.ui()
                hg.repository(u, project.project_directory + str(form.cleaned_data['directory_name']), create=True)
                form.cleaned_data['created'] = True
                form.save();
            else:
                # We pass off to a queue event
                msg_string = {}
                
                msg_string['directory_name'] = form.cleaned_data['directory_name']
                msg_string['local_parent_project'] = project.project_id
                
                q = Queue.objects.get(name='repoclone')
                clone = simplejson.dumps(msg_string)
                msg = Message(message=clone, queue=q)
                msg.save()
                # Save the repo, save the world!
                form.cleaned_data['created'] = False
                form.save()
            
            request.user.message_set.create(message=_("The repository %(display_name)s has been queued") % {'display_name':form.cleaned_data['display_name'] })
            if request.is_ajax():
                retval = (
                    {'success':'true', 'url':reverse('project-detail', kwargs={'slug':slug}),},
                )
                return JsonResponse(retval)
            else:
                return HttpResponseRedirect(reverse('project-detail', kwargs={'slug': slug}))
        else:
            # Return to the project view
            return render_to_response(template,
                {
                    'form':form.as_table(),
                    'project':project,
                    'permissions':project.get_permissions(request.user)
                }, context_instance=RequestContext(request)
            )
    else:
        form = RepoCreateForm()
    return render_to_response(template,
        {
            'form':form.as_table(),
            'project':project,
            'permissions':project.get_permissions(request.user)
        }, context_instance=RequestContext(request)
    )