示例#1
0
def json_output(request):
    
    if request.user.is_anonymous():
        member = "null"
    else :
        try:
            member = Member.members.filter(user = request.user).values('openid', 'member_displayname', 'member_homepage', 'member_gtalk', 'member_msn', 'member_jabber', 'member_bio', 'member_lat', 'member_lng')
        except:
            member = "null"
        
    site_options = {
        'site_name': Project.project_options.site_name,
        'site_owner': Project.project_options.site_owner,
        'repo_directory': Project.project_options.repository_directory,    
    }
    
    json_vars = json_encode(
        {
            'user': member,
            'site_options': site_options,
        }
    )
    return dict([
                 ('json_vars', json_vars),
            ])
示例#2
0
def get_project_details(request, slug):
    #cache_key = "hgfrontcache%s" % slug
    #object_list = cache.get(cache_key)
    #if not object_list:
    #    project = get_object_or_404(Project.objects.select_related(), name_short=slug)
    #    cache.set(cache_key, project, CACHE_EXPIRES)

    project = get_object_or_404(Project.projects.select_related(), project_id=slug)
    permissions = project.get_permissions(request.user)
    
    backups = ProjectBackup.objects.filter(parent_project__exact=project).order_by('-created')
    
    issue_short_list = project.issue_set.select_related()[:Issue.issue_options.issues_per_page]
    user_can_request_to_join = ProjectPermissionSet.objects.filter(project=project, user__id=request.user.id).count()<1 and request.user.is_authenticated() and request.user != project.project_manager
    
    if request.is_ajax():
        template = 'project/project_detail_ajax.html'
    else:
        template = 'project/project_detail.html'
    
    return render_to_response(template,
        {
            'project': project,
            'permissions':permissions,
            'issues':issue_short_list,
            'backups': backups,
            'user_can_request_to_join':user_can_request_to_join,
            'json_output': json_encode({'project' : project, 'issues': issue_short_list}),
        }, context_instance=RequestContext(request)
    )
示例#3
0
def pop_queue(request, queue_name):
    # test count with
    # curl -i http://localhost:8000/q/default/
    # curl -i http://localhost:8000/q/default/json/
    
    # print "GET queue_name is %s" % queue_name
    q = None
    # pre-emptive queue name checking...
    try:
        q = Queue.objects.get(name=queue_name)
    except Queue.DoesNotExist:
        return HttpResponseNotFound()
    #
    msg = q.message_set.pop()
    response_message='void'
    if msg:
        u = ui.ui()
        message = json_encode(msg.message)
        project = Project.projects.get(project_id__exact = message['local_parent_project'])
        repo = Repo.objects.get(directory_name__exact=message['directory_name'], local_parent_project__exact=project)
        
        if (queue_name == 'repoclone'):
            try:
                hg.clone(u, str(repo.default_path), repo.repo_directory, True)
                repo.created = True
            except:
                response_message = 'failed'
            try:
                m = Message.objects.get(id=msg.id, queue=q.id)
                m.delete()
                repo.save()
                project.save()
                response_message = 'success'
            except:
                response_message = 'failed'
        elif (queue_name == 'repoupdate'):
            location = hg.repository(u, repo.repo_directory)
            try:
                commands.pull(u, location, str(repo.default_path), rev=['tip'], force=True, update=True)
                repo.folder_size = 0
                for (path, dirs, files) in os.walk(repo.repo_directory):
                    for file in files:
                        filename = os.path.join(path, file)
                        repo.folder_size += os.path.getsize(filename)
                repo.save()
                m = Message.objects.get(id=msg.id, queue=q.id)
                m.delete()
                project.save()
                response_message = 'success'
            except:
                response_message = 'failed'
    if (response_message == 'failed'):
        return HttpResponseServerError()
    else:
        return HttpResponse(response_message)
示例#4
0
def member_profile(request, member_name):
    user = User.objects.get(username__exact = member_name)
    projects_user_owns = Project.projects.filter(project_manager__exact = user)
    profile = user.get_profile()
    return render_to_response('member/profile.html',
        {
         'user': user,
         'member': profile,
         'projects_user_owns': projects_user_owns,
         'json_output': json_encode({'user' : profile, 'project_user_owns' : projects_user_owns}),
        }, context_instance=RequestContext(request)
    )
示例#5
0
def repo_list(request, slug):
    """
    List all repoistories linked to a project
    """
    project = get_object_or_404(Project, project_id__exact=slug)
    repos = Repo.objects.filter(local_parent_project=project.id)
    return render_to_response('repos/repo_list.html',
        {
            'project': project,
            'repos': repos,
            'permissions': project.get_permissions(request.user),
            'json_output': json_encode({'repos' : repos, 'project' : project})
        }, context_instance=RequestContext(request)
    )
示例#6
0
def get_project_list(request):
    projects = [project for project in Project.projects.all() if project.get_permissions(request.user).view_project]
    project_news = ProjectNews.news_items.filter(frontpage=True, authorised=True).order_by('-pub_date')[:2]
    #user_can_request_to_join = ProjectPermissionSet.objects.filter(project=project, user__id=request.user.id).count()<1 and request.user.is_authenticated() and request.user != project.user_owner
    
    if request.is_ajax():
        template = 'project/project_list_ajax.html'
    else:
        template = 'project/project_list.html'
    
    return render_to_response(template,
        {
            'view_title': "All Projects",
            'projects': projects,
            'project_news': project_news,
            'json_output': json_encode({'projects' : projects,}),
            #'user_can_request_to_join':user_can_request_to_join
        }, context_instance=RequestContext(request)
    )
示例#7
0
def create_repo(sender, instance, signal, *args, **kwargs):
    """Create the mercurial repo"""    
    if not bool(os.path.isdir(instance.repo_directory())):
        creation_method = int(instance.creation_method)
        if creation_method==1:
            u = ui.ui()
            hg.repository(u, instance.repo_directory() , create=True)
            return True
        elif creation_method==2:
            q = Queue.objects.get(name='createrepos')
            
            clone = json_encode(instance)
            
            msg = Message(message=clone, queue=q)
            msg.save()
            #hg.clone(u, str(instance.default_path), str(instance.repo_directory()), True)
            return True
        else:
            raise ValueError("Invalid Creation Method")
    else:
        raise ValueError("Invalid: %s already exists for this project" % instance.name_short)
示例#8
0
def create_project_form(request):
    """
    Form to create a new project
    """
    
    # First we check to see the site has been set up, otherwise we throw the user to the config screen
    if not bool(os.path.isdir(Project.project_options.repository_directory)):
        request.user.message_set.create(message="The site has not been set up yet.  Log in as your admin user and create your settings!")
        return HttpResponseRedirect(reverse('site-config'))
    
    if request.is_ajax():
        template ='project/project_create_ajax.html'
    else:
        template = 'project/project_create.html'
    
    # Lets check if this form is being shown or processed
    if request.method == "POST":
        # We're processing the form, so lets create the instance
        form = NewProjectForm(request.POST, auto_id=False)
        # The form is correct, lets proceeed.
        if form.is_valid():
            # Lets check the user has conformed to a sites T&C's
            if form.cleaned_data['t_and_c'] == True:
                # Create the project instance
                project = Project(
                    project_id = string.lower(form.cleaned_data['project_id']),
                    project_name = form.cleaned_data['project_name'],
                    short_description = form.cleaned_data['short_description'],
                    full_description = form.cleaned_data['full_description'],
                    project_manager = request.user,
                    hgweb_style = form.cleaned_data.get('hgweb_style', ''),
                    project_icon = form.cleaned_data['project_icon'],
                )
                # Ok, we're all good, so lets save.
                project.save()
                # We'll tell the user that there site has been saved
                request.user.message_set.create(message=_("The project " + form.cleaned_data['project_name'] + " has been created"))
                if request.is_ajax():
                    return HttpResponse(
                                        "{'success': 'true', 'url': '" + reverse('project-detail', kwargs={'slug':form.cleaned_data['project_id']}) + "', 'project': " + json_encode(project) + "}"
                                        , mimetype="application/json")
                else:
                    return HttpResponseRedirect(reverse('project-detail', kwargs={'slug': form.cleaned_data['project_id']}))
        else:
            return render_to_response(template,
                {
                    'form':form.as_table(),
                }, context_instance=RequestContext(request)
            )
        #return HttpResponseRedirect(reverse('project-detail', kwargs={'slug':form.cleaned_data['name_short']}))
    else:
        form = NewProjectForm()
        is_auth = request.user.is_authenticated()
        
        return render_to_response(template,
            {
                'form':form.as_table(),
                'is_auth': is_auth
            }, context_instance=RequestContext(request)
        )
示例#9
0
def view_changeset(request, slug, repo_name, changeset='tip'):
    project = Project.projects.get(project_id__exact=slug)
    repo = Repo.objects.get(directory_name__exact=repo_name, local_parent_project__exact = project)
    
    cmd = request.GET.get('cmd','')
    if cmd:
        if cmd == 'heads':
            #u = ui.ui()
            #loc = hg.repository(u, repo.repo_directory)
            #resp = " ".join(map(hex, loc.heads())) + "\n"
            #return HttpResponse(resp, mimetype='application/mercurial-0.1')
            return HttpResponse('Not yet implemented')
    else:
        try:
            changeset_tags = repo.get_tags()
        except:
            changeset_tags = []            
        try:
            changeset_branches = repo.get_branches()
        except:
            changeset_branches = []
        try:
            changeset_id = repo.get_changeset(changeset)
        except:
            changeset_id = []
        try:
            changeset_user = repo.get_changeset(changeset).user()
        except:
            changeset_user = []
        try:
            changeset_notes = repo.get_changeset(changeset).description()
        except:
            changeset_notes = []
        try:
            changeset_files = repo.get_changeset(changeset).files()
        except:
            changeset_files = []
        try:
            changeset_number = repo.get_changeset_number(changeset)
        except:
            changeset_number = []
        try:
            changeset_children = repo.get_next_changeset(changeset)
        except:
            changeset_children = []
        try:
            changeset_parents = repo.get_previous_changeset(changeset)
        except:
            changeset_parents = []
        return render_to_response('repos/repo_detail.html',
            {
                'changeset_tags': changeset_tags,
                'changeset_branches': changeset_branches,
                'changeset_id': changeset_id,
                'changeset_user': changeset_user,
                'changeset_notes': changeset_notes,
                'changeset_files': changeset_files,
                'changeset_number': changeset_number,
                'changeset_parents': changeset_parents,
                'changeset_children': changeset_children,
                'project': project,
                'repo': repo,
                'json_output': json_encode({'repo' : repo, 'project' : project})
            }, context_instance=RequestContext(request)
        )