views.py 807 Bytes
Newer Older
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
1
from django.shortcuts import render
Guilhem Saurel's avatar
Guilhem Saurel committed
2
from django.views.generic import DetailView
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
3

Guilhem Saurel's avatar
Guilhem Saurel committed
4
5
from django_tables2 import RequestConfig

Guilhem Saurel's avatar
Guilhem Saurel committed
6
from .models import Forge, Namespace, Project
Guilhem Saurel's avatar
Guilhem Saurel committed
7
from .tables import ProjectTable, RepoTable
Guilhem Saurel's avatar
Guilhem Saurel committed
8
9
10


def home(request):
Guilhem Saurel's avatar
Guilhem Saurel committed
11
12
    projects = ProjectTable(Project.objects.all())
    RequestConfig(request).configure(projects)
Guilhem Saurel's avatar
Guilhem Saurel committed
13
14
15
    return render(request, 'rainboard/home.html', {
        'forges': Forge.objects.all(),
        'namespaces': Namespace.objects.all(),
Guilhem Saurel's avatar
Guilhem Saurel committed
16
        'projects': projects,
Guilhem Saurel's avatar
Guilhem Saurel committed
17
    })
Guilhem Saurel's avatar
Guilhem Saurel committed
18
19
20
21
22
23
24
25
26
27
28


class ProjectView(DetailView):
    model = Project

    def get_context_data(self, **kwargs):
        ctx = super().get_context_data(**kwargs)
        repos = RepoTable(self.object.repo_set.all())
        RequestConfig(self.request).configure(repos)
        ctx['repos'] = repos
        return ctx