Commit 4e81e33a authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

filters & forked_from

parent 9702ed66
......@@ -25,7 +25,7 @@ SECRET_KEY = 'mgun706*g8lq6voa#1n*)cfk7t4m%8s@4my^al#@8tzis+#v5e'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['hagurosan', 'hagurosan.laas.fr']
ALLOWED_HOSTS = ['hagurosan', 'hagurosan.laas.fr', 'localhost']
# Application definition
......@@ -39,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'django.contrib.sites',
'django_tables2',
'django_filters',
'bootstrap3',
'rainboard',
]
......
import django_filters
from .models import Project
class ProjectFilter(django_filters.FilterSet):
class Meta:
model = Project
fields = ('name',)
# Generated by Django 2.0.1 on 2018-01-05 16:21
# Generated by Django 2.0.1 on 2018-01-10 15:53
import autoslug.fields
from django.db import migrations, models
import django.db.models.deletion
import ndh.models
class Migration(migrations.Migration):
......@@ -53,6 +54,7 @@ class Migration(migrations.Migration):
options={
'abstract': False,
},
bases=(ndh.models.Links, models.Model),
),
migrations.CreateModel(
name='License',
......@@ -95,6 +97,7 @@ class Migration(migrations.Migration):
options={
'abstract': False,
},
bases=(ndh.models.Links, models.Model),
),
migrations.CreateModel(
name='Repo',
......@@ -110,6 +113,7 @@ class Migration(migrations.Migration):
('open_issues', models.PositiveSmallIntegerField(blank=True, null=True)),
('open_pr', models.PositiveSmallIntegerField(blank=True, null=True)),
('repo_id', models.PositiveIntegerField()),
('forked_from', models.PositiveIntegerField(blank=True, null=True)),
('forge', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rainboard.Forge')),
('license', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='rainboard.License')),
('namespace', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rainboard.Namespace')),
......
......@@ -97,15 +97,26 @@ class Forge(Links, NamedModel):
project.save()
def get_projects_gitlab(self):
for data in self.api_data('/projects'):
def update_gitlab(data):
project, created = Project.objects.get_or_create(name=data['name'])
namespace, _ = Namespace.objects.get_or_create(name=data['namespace']['name'])
if created and not 'forked_from_project' in data:
project.main_namespace = namespace
repo, _ = Repo.objects.get_or_create(forge=self, namespace=namespace, project=project,
defaults={'repo_id': data['id'], 'name': data['name'],
'url': data['web_url']})
if 'forked_from_project' in data:
repo.forked_from = data['forked_from_project']['id']
repo.save()
elif created or project.main_namespace is None:
project.main_namespace = namespace
project.save()
api = self.api_data('/projects')
for data in api:
update_gitlab(data)
for orphan in Project.objects.filter(main_namespace=None):
repo = orphan.repo_set.get(forge__source=SOURCES.gitlab)
update_gitlab(self.api_data(f'/projects/{repo.forked_from}'))
def get_projects_redmine(self):
pass # TODO
......@@ -124,6 +135,7 @@ class Repo(TimeStampedModel):
open_issues = models.PositiveSmallIntegerField(blank=True, null=True)
open_pr = models.PositiveSmallIntegerField(blank=True, null=True)
repo_id = models.PositiveIntegerField()
forked_from = models.PositiveIntegerField(blank=True, null=True)
def api_url(self):
if self.forge.source == SOURCES.github:
......
{% extends 'base.html' %}
{% load django_tables2 bootstrap3 %}
{% block content %}
<h1>Projects</h1>
{% if filter %}
<form action="" method="get" class="form form-inline">
{% bootstrap_form filter.form layout='inline' %}
{% bootstrap_button 'filter' %}
</form>
{% endif %}
{% render_table table %}
{% endblock %}
......@@ -7,7 +7,8 @@ from . import views
app_name = 'rainboard'
urlpatterns = [
path(r'', views.home, name='home'),
# path(r'', views.home, name='home'),
path(r'', views.ProjectsView.as_view(), 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'),
......
......@@ -2,9 +2,12 @@ from django.shortcuts import render
from django.views.generic import DetailView
from django_tables2 import RequestConfig
from django_tables2.views import SingleTableMixin
from django_filters.views import FilterView
from .models import Forge, Namespace, Project
from .tables import ProjectTable, RepoTable
from .filters import ProjectFilter
def home(request):
......@@ -17,6 +20,12 @@ def home(request):
})
class ProjectsView(SingleTableMixin, FilterView):
model = Project
table_class = ProjectTable
filterset_class = ProjectFilter
class ProjectView(DetailView):
model = Project
......
Django
django-bootstrap3
django-filter
django-tables2
psycopg2
requests
......
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