Exemple #1
0
def event(request, url_path):
    resp = force_url_paths(event, url_path)
    if resp: return resp

    try:
        qs = InheritanceQuerySet(model=Event)
        the_event = qs.select_subclasses().get(url_path=url_path)
    except:
        raise Http404

    if the_event.__class__ is Commit:
        return HttpResponseRedirect(
            reverse(commits.show,
                    args=(
                        the_event.project.url_path,
                        the_event.url_path,
                    )))
    else:
        if the_event.project is not None:
            return HttpResponseRedirect(
                reverse(blogs.show_post,
                        args=(
                            the_event.project.url_path,
                            the_event.url_path,
                        )))
        else:
            return HttpResponseRedirect(
                reverse(blogs.show_user_post,
                        args=(
                            the_event.author.id,
                            the_event.url_path,
                        )))
    raise Http404
Exemple #2
0
def show(request, project_url_path):
    # redirect if the url path is not in the correct format
    resp = force_url_paths("dashboard.views.projects.show", project_url_path)
    if resp:
        return resp

    # get the project
    project = get_object_or_404(Project, url_path=project_url_path)

    # create a paginated list of the screenshots of the project
    paginator = None
    screenshots = Screenshot.objects.filter(project=project)
    if screenshots.count > 0:
        paginator = ListPaginator(screenshots.order_by("id").reverse(), 3)

    # get the most recent commits for the project
    commits = Commit.objects.filter(repository=project.repository)
    commits = commits.order_by("date").reverse()[:SHOW_COMMIT_COUNT]

    # get the project's contributors
    contributors = Contributor.objects.filter(projects__id__exact=project.id)

    # exclude the current authors from the project
    for user in project.authors.all():
        contributors = contributors.exclude(user=user)

    # if the user has already submitted an author request, hide add/remove author
    show_add_remove_author = True
    if request.user is not None:
        try:
            AuthorRequest.objects.get(project=project, user=request.user)
            show_add_remove_author = False
        except:
            pass

    # get the most recent blog posts for the project
    blogposts = BlogPost.objects.filter(blog=project.blog)
    blogposts = blogposts.order_by("date").reverse()[:SHOW_BLOGPOST_COUNT]
    return render_to_response(
        "projects/show.html",
        {
            "project": project,
            "paginator": paginator,
            "authors": project.authors.all(),
            "default_page": 1,
            "has_screenshots": len(screenshots) > 0,
            "screenshot_pages_width": len(screenshots) * 790,
            "js_page_id": "show_project",
            "blogposts": blogposts,
            "commits": commits,
            "contributors": contributors,
            "show_add_remove_author": show_add_remove_author,
            "mentor": project.mentor,
        },
        context_instance=RequestContext(request),
    )
Exemple #3
0
def repository_page(request, project_url_path, page_num):
  resp = force_url_paths(repository_page, project_url_path, page = page_num)
  if resp: return resp
  
  project = get_object_or_404(Project, url_path = project_url_path)
  
  qs = Commit.objects.order_by('-date').filter(project = project)
  return show_page(request, page_num, qs,
                   'commits/show_repository.html',
                   project = project)
Exemple #4
0
def repository_page(request, project_url_path, page_num):
    resp = force_url_paths(repository_page, project_url_path, page=page_num)
    if resp: return resp

    project = get_object_or_404(Project, url_path=project_url_path)

    qs = Commit.objects.order_by('-date').filter(project=project)
    return show_page(request,
                     page_num,
                     qs,
                     'commits/show_repository.html',
                     project=project)
Exemple #5
0
def show(request, project_url_path):
    # redirect if the url path is not in the correct format
    resp = force_url_paths('dashboard.views.projects.show', project_url_path)
    if resp: return resp

    # get the project
    project = get_object_or_404(Project, url_path=project_url_path)

    # create a paginated list of the screenshots of the project
    paginator = None
    screenshots = Screenshot.objects.filter(project=project)
    if screenshots.count > 0:
        paginator = ListPaginator(screenshots.order_by('id').reverse(), 3)

    # get the most recent commits for the project
    commits = Commit.objects.filter(repository=project.repository)
    commits = commits.order_by('date').reverse()[:SHOW_COMMIT_COUNT]

    # get the project's contributors
    contributors = Contributor.objects.filter(projects__id__exact=project.id)

    # exclude the current authors from the project
    for user in project.authors.all():
        contributors = contributors.exclude(user=user)

    # if the user has already submitted an author request, hide add/remove author
    show_add_remove_author = True
    if request.user is not None:
        try:
            AuthorRequest.objects.get(project=project, user=request.user)
            show_add_remove_author = False
        except:
            pass

    # get the most recent blog posts for the project
    blogposts = BlogPost.objects.filter(blog=project.blog)
    blogposts = blogposts.order_by('date').reverse()[:SHOW_BLOGPOST_COUNT]
    return render_to_response('projects/show.html', {
        'project': project,
        'paginator': paginator,
        'authors': project.authors.all(),
        'default_page': 1,
        'has_screenshots': len(screenshots) > 0,
        'screenshot_pages_width': len(screenshots) * 790,
        'js_page_id': 'show_project',
        'blogposts': blogposts,
        'commits': commits,
        'contributors': contributors,
        'show_add_remove_author': show_add_remove_author,
        'mentor': project.mentor,
    },
                              context_instance=RequestContext(request))
Exemple #6
0
def show_blog(request, project_url_path):
  resp = force_url_paths(show_blog, project_url_path)
  if resp: return resp
  
  project = get_object_or_404(Project, url_path = project_url_path)
  if project.blog.from_feed:
    return HttpResponseRedirect(project.blog.url)
  else:
    return render_to_response('blogs/show-blog.html', {
        'project': project,
        'posts': project.blog.blogpost_set.all(),
        'disable_content': True
      }, context_instance = RequestContext(request))
Exemple #7
0
def show(request, project_url_path, commit_url_path):
    resp = force_url_paths(show, project_url_path, commit_url_path)
    if resp: return resp

    # find the commit
    commit = get_object_or_404(Commit, url_path=commit_url_path)

    # if the commit is external, redirect to it
    if commit.repository.from_feed:
        return HttpResponseRedirect(commit.url)

    return render_to_response("commits/show.html", {'commit': commit},
                              context_instance=RequestContext(request))
Exemple #8
0
def show_blog(request, project_url_path):
    resp = force_url_paths(show_blog, project_url_path)
    if resp: return resp

    project = get_object_or_404(Project, url_path=project_url_path)
    if project.blog.from_feed:
        return HttpResponseRedirect(project.blog.url)
    else:
        return render_to_response('blogs/show-blog.html', {
            'project': project,
            'posts': project.blog.blogpost_set.all(),
            'disable_content': True
        },
                                  context_instance=RequestContext(request))
Exemple #9
0
def show(request, project_url_path, commit_url_path):
  resp = force_url_paths(show, project_url_path, commit_url_path)
  if resp: return resp
  
  # find the commit
  commit = get_object_or_404(Commit, url_path = commit_url_path)
  
  # if the commit is external, redirect to it
  if commit.repository.from_feed:
    return HttpResponseRedirect(commit.url)
  
  return render_to_response("commits/show.html", {
      'commit': commit
    }, context_instance = RequestContext(request))
Exemple #10
0
def show_blog(request, project_url_path):
    resp = force_url_paths(show_blog, project_url_path)
    if resp:
        return resp

    project = get_object_or_404(Project, url_path=project_url_path)
    if project.blog.from_feed:
        return HttpResponseRedirect(project.blog.url)
    else:
        return render_to_response(
            "blogs/show-blog.html",
            {"project": project, "posts": project.blog.blogpost_set.all()},
            context_instance=RequestContext(request),
        )
Exemple #11
0
def edit_post(request, project_url_path, post_url_path):
  # redirect if the url path is not in the correct format
  resp = force_url_paths(edit_post, project_url_path, post_url_path)
  if resp: return resp
  
  post = get_object_or_404(BlogPost, url_path = post_url_path)
  
  if request.user not in post.blog.project.authors.all():
    return HttpResponseRedirect(reverse(projects.show,
                                        args = (project.url_path,)))
  
  return render_to_response('blogs/edit.html', {
      'project': post.blog.project,
      'post': post,
      'form': BlogPostForm(instance = post)
    }, context_instance = RequestContext(request))
Exemple #12
0
def edit_post(request, project_url_path, post_url_path):
    # redirect if the url path is not in the correct format
    resp = force_url_paths(edit_post, project_url_path, post_url_path)
    if resp: return resp

    post = get_object_or_404(BlogPost, url_path=post_url_path)

    if request.user not in post.blog.project.authors.all():
        return HttpResponseRedirect(
            reverse(projects.show, args=(project.url_path, )))

    return render_to_response('blogs/edit.html', {
        'project': post.blog.project,
        'post': post,
        'form': BlogPostForm(instance=post)
    },
                              context_instance=RequestContext(request))
Exemple #13
0
def event(request, url_path):
    resp = force_url_paths(event, url_path)
    if resp:
        return resp

    try:
        qs = InheritanceQuerySet(model=Event)
        the_event = qs.select_subclasses().get(url_path=url_path)
    except:
        raise Http404

    if the_event.__class__ is Commit:
        return HttpResponseRedirect(reverse(commits.show, args=(the_event.project.url_path, the_event.url_path)))
    else:
        if the_event.project == None:
            return HttpResponseRedirect(reverse(blogs.show_post, args=(the_event.project.url_path, the_event.url_path)))
        else:
            return HttpResponseRedirect(reverse(blogs.show_user_post, args=(the_event.user.id, the_event.url_path)))
    raise Http404
Exemple #14
0
def show_repository(request, project_url_path):
  resp = force_url_paths(show_repository, project_url_path)
  if resp: return resp
  
  return repository_page(request, project_url_path, 1)
Exemple #15
0
def show_repository(request, project_url_path):
    resp = force_url_paths(show_repository, project_url_path)
    if resp: return resp

    return repository_page(request, project_url_path, 1)
Exemple #16
0
def modify(request, project_url_path, tab_id = 1):
  # redirect if the url path is not in the correct format
  resp = force_url_paths(modify, project_url_path)
  if resp: return resp
  
  project = get_object_or_404(Project, url_path = project_url_path)
  screenshots = Screenshot.objects.filter(project = project)
  
  # if someone tries to edit a project they shouldn't be able to
  if not (request.user in project.authors.all() or request.user.is_staff):
    return HttpResponseRedirect(reverse(show, args = (project.url_path,)))
  
  # default forms
  project_form = ProjectForm(instance = project)
  cloned_repo_form = ClonedRepositoryForm(instance = project.repository)
  feed_repo_form = FeedRepositoryForm(instance = project.repository)
  blog_form = BlogForm(instance = project.blog)
  screenshot_form = UploadScreenshotForm()
  
  # if changes should be saved or rejected
  if request.POST:
    # uploading a screenshot
    if 'screenshot_upload' in request.POST:
      form = UploadScreenshotForm(request.POST, request.FILES)
      if form.is_valid():
        Screenshot.create(form, request.FILES["file"], project)
      else:
        screenshot_form = form

    # wrote a post with the js overlay
    if 'title' in request.POST and 'markdown' in request.POST:
      from observatory.dashboard.views.blogs import create_post_real
      return create_post_real(request.POST)

    # editing the project's information
    elif 'title' in request.POST:
      form = ProjectForm(request.POST)
      
      # if the form is valid, save
      if form.is_valid():
        project.title = form.cleaned_data['title']
        project.website = form.cleaned_data['website']
        project.wiki = form.cleaned_data['wiki']
        project.description = form.cleaned_data['description']
        project.active = form.cleaned_data['active']
        project.save()
        project_form = ProjectForm(instance = project)
      
      # otherwise, display the errors
      else:
        project_form = form
    
    # editing a cloned repository
    elif 'clone_url' in request.POST:
      form = ClonedRepositoryForm(request.POST)
      
      if form.is_valid():
        project.repository.web_url = form.cleaned_data['web_url']
        project.repository.clone_url = form.cleaned_data['clone_url']
        project.repository.vcs = form.cleaned_data['vcs']
        project.repository.from_feed = False
        project.repository.save()
        cloned_repo_form = ClonedRepositoryForm(instance = project.repository)
      else:
        cloned_repo_form = form
    
    # editing a feed repository
    elif 'repo_rss' in request.POST:
      form = FeedRepositoryForm(request.POST)
      
      if form.is_valid():
        project.repository.repo_rss = form.cleaned_data['repo_rss']
        project.repository.cmd = form.cleaned_data['cmd']
        project.repository.web_url = form.cleaned_data['web_url']
        project.repository.from_feed = True
        project.repository.save()
        feed_repo_form = FeedRepositoryForm(instance = project.repository)
      else:
        feed_repo_form = form
    
    # editing a feed-based blog
    elif 'url' in request.POST:
      form = BlogForm(request.POST)
      
      if form.is_valid():
        project.blog.url = form.cleaned_data['url']
        project.blog.rss = form.cleaned_data['rss']
        project.blog.from_feed = True
        project.blog.save()
        blog_form = BlogForm(instance = project.blog)
      else:
        blog_form = form
    
    # switching to hosted blog
    elif 'switch-to-hosted' in request.POST:
      project.blog.from_feed = False
      project.blog.save()
      
  return render_to_response('projects/modify.html', {
    'project': project,
    'screenshots': screenshots,
    'project_form': project_form,
    'cloned_repo_form': cloned_repo_form,
    'feed_repo_form': feed_repo_form,
    'blog_form': blog_form,
    'screenshot_form': screenshot_form,
    'post_form': BlogPostForm(),
    'repo': project.repository,
    'tab': int(tab_id)
  }, context_instance = RequestContext(request))
Exemple #17
0
def modify(request, project_url_path, tab_id=1):
    # redirect if the url path is not in the correct format
    resp = force_url_paths(modify, project_url_path)
    if resp:
        return resp

    project = get_object_or_404(Project, url_path=project_url_path)
    screenshots = Screenshot.objects.filter(project=project)

    # if someone tries to edit a project they shouldn't be able to
    if not (request.user in project.authors.all() or request.user.info.mentor):
        return HttpResponseRedirect(reverse(show, args=(project.url_path,)))

    # default forms
    project_form = ProjectForm(instance=project)
    cloned_repo_form = ClonedRepositoryForm(instance=project.repository)
    feed_repo_form = FeedRepositoryForm(instance=project.repository)
    blog_form = BlogForm(instance=project.blog)
    screenshot_form = UploadScreenshotForm()

    # if changes should be saved or rejected
    if request.POST:
        # uploading a screenshot
        if "screenshot_upload" in request.POST:
            form = UploadScreenshotForm(request.POST, request.FILES)
            if form.is_valid():
                Screenshot.create(form, request.FILES["file"], project)
            else:
                screenshot_form = form

        # wrote a post with the js overlay
        if "title" in request.POST and "markdown" in request.POST:
            from dashboard.views.blogs import create_post_real

            return create_post_real(request.POST)

        # editing the project's information
        elif "title" in request.POST:
            form = ProjectForm(request.POST)

            # if the form is valid, save
            if form.is_valid():
                project.title = form.cleaned_data["title"]
                project.website = form.cleaned_data["website"]
                project.wiki = form.cleaned_data["wiki"]
                project.description = form.cleaned_data["description"]
                project.active = form.cleaned_data["active"]
                project.save()
                project_form = ProjectForm(instance=project)

            # otherwise, display the errors
            else:
                project_form = form

        # editing a cloned repository
        elif "clone_url" in request.POST:
            form = ClonedRepositoryForm(request.POST)

            if form.is_valid():
                project.repository.web_url = form.cleaned_data["web_url"]
                project.repository.clone_url = form.cleaned_data["clone_url"]
                project.repository.vcs = form.cleaned_data["vcs"]
                project.repository.from_feed = False
                project.repository.save()
                cloned_repo_form = ClonedRepositoryForm(instance=project.repository)
            else:
                cloned_repo_form = form

        # editing a feed repository
        elif "repo_rss" in request.POST:
            form = FeedRepositoryForm(request.POST)

            if form.is_valid():
                project.repository.repo_rss = form.cleaned_data["repo_rss"]
                project.repository.cmd = form.cleaned_data["cmd"]
                project.repository.web_url = form.cleaned_data["web_url"]
                project.repository.from_feed = True
                project.repository.save()
                feed_repo_form = FeedRepositoryForm(instance=project.repository)
            else:
                feed_repo_form = form

        # editing a feed-based blog
        elif "url" in request.POST:
            form = BlogForm(request.POST)

            if form.is_valid():
                project.blog.url = form.cleaned_data["url"]
                project.blog.rss = form.cleaned_data["rss"]
                project.blog.from_feed = True
                project.blog.save()
                blog_form = BlogForm(instance=project.blog)
            else:
                blog_form = form

        # switching to hosted blog
        elif "switch-to-hosted" in request.POST:
            project.blog.from_feed = False
            project.blog.save()

    return render_to_response(
        "projects/modify.html",
        {
            "project": project,
            "screenshots": screenshots,
            "project_form": project_form,
            "cloned_repo_form": cloned_repo_form,
            "feed_repo_form": feed_repo_form,
            "blog_form": blog_form,
            "screenshot_form": screenshot_form,
            "post_form": BlogPostForm(),
            "repo": project.repository,
            "tab": int(tab_id),
        },
        context_instance=RequestContext(request),
    )
Exemple #18
0
def modify(request, project_url_path, tab_id=1):
    # redirect if the url path is not in the correct format
    resp = force_url_paths(modify, project_url_path)
    if resp: return resp

    project = get_object_or_404(Project, url_path=project_url_path)
    screenshots = Screenshot.objects.filter(project=project)

    # if someone tries to edit a project they shouldn't be able to
    if not (request.user in project.authors.all() or request.user.info.mentor):
        return HttpResponseRedirect(reverse(show, args=(project.url_path, )))

    # default forms
    project_form = ProjectForm(instance=project)
    cloned_repo_form = ClonedRepositoryForm(instance=project.repository)
    feed_repo_form = FeedRepositoryForm(instance=project.repository)
    blog_form = BlogForm(instance=project.blog)
    screenshot_form = UploadScreenshotForm()

    # if changes should be saved or rejected
    if request.POST:
        # uploading a screenshot
        if 'screenshot_upload' in request.POST:
            form = UploadScreenshotForm(request.POST, request.FILES)
            if form.is_valid():
                Screenshot.create(form, request.FILES["file"], project)
            else:
                screenshot_form = form

        # wrote a post with the js overlay
        if 'title' in request.POST and 'markdown' in request.POST:
            from dashboard.views.blogs import create_post_real
            return create_post_real(request.POST)

        # editing the project's information
        elif 'title' in request.POST:
            form = ProjectForm(request.POST)

            # if the form is valid, save
            if form.is_valid():
                project.title = form.cleaned_data['title']
                project.website = form.cleaned_data['website']
                project.wiki = form.cleaned_data['wiki']
                project.description = form.cleaned_data['description']
                project.active = form.cleaned_data['active']
                project.save()
                project_form = ProjectForm(instance=project)

            # otherwise, display the errors
            else:
                project_form = form

        # editing a cloned repository
        elif 'clone_url' in request.POST:
            form = ClonedRepositoryForm(request.POST)

            if form.is_valid():
                project.repository.web_url = form.cleaned_data['web_url']
                project.repository.clone_url = form.cleaned_data['clone_url']
                project.repository.vcs = form.cleaned_data['vcs']
                project.repository.from_feed = False
                project.repository.save()
                cloned_repo_form = ClonedRepositoryForm(
                    instance=project.repository)
            else:
                cloned_repo_form = form

        # editing a feed repository
        elif 'repo_rss' in request.POST:
            form = FeedRepositoryForm(request.POST)

            if form.is_valid():
                project.repository.repo_rss = form.cleaned_data['repo_rss']
                project.repository.cmd = form.cleaned_data['cmd']
                project.repository.web_url = form.cleaned_data['web_url']
                project.repository.from_feed = True
                project.repository.save()
                feed_repo_form = FeedRepositoryForm(
                    instance=project.repository)
            else:
                feed_repo_form = form

        # editing a feed-based blog
        elif 'url' in request.POST:
            form = BlogForm(request.POST)

            if form.is_valid():
                project.blog.url = form.cleaned_data['url']
                project.blog.rss = form.cleaned_data['rss']
                project.blog.from_feed = True
                project.blog.save()
                blog_form = BlogForm(instance=project.blog)
            else:
                blog_form = form

        # switching to hosted blog
        elif 'switch-to-hosted' in request.POST:
            project.blog.from_feed = False
            project.blog.save()

    return render_to_response('projects/modify.html', {
        'project': project,
        'screenshots': screenshots,
        'project_form': project_form,
        'cloned_repo_form': cloned_repo_form,
        'feed_repo_form': feed_repo_form,
        'blog_form': blog_form,
        'screenshot_form': screenshot_form,
        'post_form': BlogPostForm(),
        'repo': project.repository,
        'tab': int(tab_id)
    },
                              context_instance=RequestContext(request))
Exemple #19
0
def show_user_post(request, post_url_path):
    resp = force_url_paths(show_user_post, post_url_path)
    if resp: return resp
    return show_post_real(request, post_url_path)
Exemple #20
0
def show_user_post(request, post_url_path):
  resp = force_url_paths(show_user_post, post_url_path)
  if resp: return resp
  return show_post_real(request, post_url_path)