views.py 1.58 KB
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, CreateView
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
3

Guilhem Saurel's avatar
Guilhem Saurel committed
4
from django_filters.views import FilterView
Guilhem Saurel's avatar
Guilhem Saurel committed
5
from django_tables2 import RequestConfig
Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
6
from django_tables2.views import SingleTableMixin, SingleTableView
Guilhem Saurel's avatar
Guilhem Saurel committed
7

Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
8
9
from . import models
from . import tables
Guilhem Saurel's avatar
Guilhem Saurel committed
10
from .filters import ProjectFilter
Guilhem Saurel's avatar
Guilhem Saurel committed
11
12


Guilhem Saurel's avatar
Guilhem Saurel committed
13
14
15
16
17
18
19
20
21
22
class ArticlesView(SingleTableView):
    model = models.Article
    table_class = tables.ArticleTable


class ArticleCreateView(CreateView):
    model = models.Article
    fields = ('name', 'authors', 'year', 'url', 'pdf')


Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
23
24
25
26
27
28
29
30
class ForgesView(SingleTableView):
    model = models.Forge
    table_class = tables.ForgeTable


class NamespacesView(SingleTableView):
    model = models.Namespace
    table_class = tables.NamespaceTable
Guilhem Saurel's avatar
Guilhem Saurel committed
31
32


Guilhem Saurel's avatar
Guilhem Saurel committed
33
class ProjectsView(SingleTableMixin, FilterView):
Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
34
35
    model = models.Project
    table_class = tables.ProjectTable
Guilhem Saurel's avatar
Guilhem Saurel committed
36
37
38
    filterset_class = ProjectFilter


Guilhem Saurel's avatar
Guilhem Saurel committed
39
class ProjectView(DetailView):
Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
40
    model = models.Project
Guilhem Saurel's avatar
Guilhem Saurel committed
41
42
43

    def get_context_data(self, **kwargs):
        ctx = super().get_context_data(**kwargs)
Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
44
        repos = tables.RepoTable(self.object.repo_set.all())
Guilhem Saurel's avatar
Guilhem Saurel committed
45
46
47
        RequestConfig(self.request).configure(repos)
        ctx['repos'] = repos
        return ctx
Guilhem Saurel's avatar
Guilhem Saurel committed
48
49
50
51
52
53
54
55
56
57
58
59


class ProjectBranchesView(DetailView):
    model = models.Project
    template_name = 'rainboard/project_detail_branches.html'

    def get_context_data(self, **kwargs):
        ctx = super().get_context_data(**kwargs)
        branches = tables.BranchTable(self.object.branch_set.all())
        RequestConfig(self.request).configure(branches)
        ctx['branches'] = branches
        return ctx