Commit 9702ed66 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

ProjectView

parent 88e680e8
from django.db import models
from django.urls import reverse
from autoslug import AutoSlugField
from ndh.models import NamedModel, TimeStampedModel
from ndh.models import NamedModel, TimeStampedModel, Links
from ndh.utils import enum_to_choices, query_sum
import requests
......@@ -22,19 +23,25 @@ class License(NamedModel):
return self.spdx_id or self.name
class Project(NamedModel, TimeStampedModel):
class Project(Links, NamedModel, TimeStampedModel):
private = models.BooleanField(default=False)
main_namespace = models.ForeignKey(Namespace, on_delete=models.SET_NULL, null=True, blank=True)
license = models.ForeignKey(License, on_delete=models.SET_NULL, blank=True, null=True)
homepage = models.URLField(max_length=200, blank=True, null=True)
def get_absolute_url(self):
return reverse('rainboard:project', kwargs={'slug': self.slug})
class Forge(NamedModel):
class Forge(Links, NamedModel):
source = models.PositiveSmallIntegerField(choices=enum_to_choices(SOURCES))
url = models.URLField(max_length=200)
token = models.CharField(max_length=50, blank=True, null=True)
verify = models.BooleanField(default=True)
def get_absolute_url(self):
return self.url
def api_data(self, url=''):
return requests.get(self.api_url() + url, verify=self.verify, headers=self.headers()).json()
......
from django.utils.safestring import mark_safe
import django_tables2 as tables
from .models import Project
from .models import Project, Repo
class ProjectTable(tables.Table):
......@@ -7,3 +10,18 @@ class ProjectTable(tables.Table):
model = Project
fields = ('main_namespace', 'name', 'license', 'homepage')
attrs = {'class': 'table table-striped'}
def render_name(self, record):
return record.get_link()
class RepoTable(tables.Table):
class Meta:
model = Repo
fields = ('forge', 'namespace', 'license', 'homepage', 'default_branch', 'open_issues', 'open_pr')
def render_forge(self, value):
return value.get_link()
def render_namespace(self, record):
return mark_safe(f'<a href="{record.url}">{record.namespace}</a>')
{% extends 'base.html' %}
{% load django_tables2 bootstrap3 %}
{% block content %}
<div class="clearfix">
{% if project.main_namespace %}<h2 class="pull-right">{{ project.main_namespace }}</h2>{% endif %}
<h1>{{ project }}</h1>
<div class="pull-right">
{% if project.license %}
{% bootstrap_label project.license label_class='label label-primary' %}
{% else %}
{% bootstrap_label 'UNLICENSED' label_class='label label-warning' %}
{% endif %}
{% if project.private %}
{% bootstrap_label 'private' label_class='label label-danger' %}
{% else %}
{% bootstrap_label 'public' label_class='label label-success' %}
{% endif %}
</div>
{% if project.homepage %}<a href="{{ project.homepage }}">{{ project.homepage }}</a>{% endif %}
</div>
{% render_table repos %}
{% endblock %}
......@@ -5,10 +5,11 @@ from django.views.generic import ListView
from .models import Forge, Namespace, Project
from . import views
app_name = 'cine'
app_name = 'rainboard'
urlpatterns = [
path(r'', views.home, name='home'),
path(r'forges', ListView.as_view(model=Forge), name='forges'),
path(r'namespaces', ListView.as_view(model=Namespace), name='namespaces'),
path(r'projects', ListView.as_view(model=Project), name='projects'),
path(r'project/<str:slug>', views.ProjectView.as_view(), name='project'),
]
from django.shortcuts import render
from django.views.generic import DetailView
from django_tables2 import RequestConfig
from .models import Forge, Namespace, Project
from .tables import ProjectTable
from .tables import ProjectTable, RepoTable
def home(request):
......@@ -14,3 +15,14 @@ def home(request):
'namespaces': Namespace.objects.all(),
'projects': projects,
})
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment