mirror of
https://github.com/kristoferssolo/FOSSDB.git
synced 2025-10-21 17:50:35 +00:00
commit
40a7c539db
23
.github/workflows/lint.yml
vendored
23
.github/workflows/lint.yml
vendored
@ -1,23 +0,0 @@
|
||||
name: Lint
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
python-version: ["3.10"]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install tox tox-gh-actions
|
||||
- name: Lint with tox
|
||||
run: tox
|
||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@ -18,6 +18,6 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install django
|
||||
pip install tox tox-gh-actions
|
||||
- name: Lint with tox
|
||||
run: python manage.py test
|
||||
run: tox
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@ -2,5 +2,5 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class FossdbConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'fossdb'
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "fossdb"
|
||||
|
||||
9
FOSSDB_web/apps/fossdb/forms.py
Normal file
9
FOSSDB_web/apps/fossdb/forms.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django import forms
|
||||
|
||||
from .models import Project
|
||||
|
||||
|
||||
class ProjectForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Project
|
||||
fields = ["title", "description"]
|
||||
27
FOSSDB_web/apps/fossdb/migrations/0001_initial.py
Normal file
27
FOSSDB_web/apps/fossdb/migrations/0001_initial.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Generated by Django 4.1 on 2023-03-27 17:46
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Project',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=255)),
|
||||
('description', models.TextField()),
|
||||
('create_date', models.DateTimeField(auto_now_add=True)),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
||||
@ -1,3 +1,15 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Project(models.Model):
|
||||
author = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
title = models.CharField(max_length=255)
|
||||
description = models.TextField()
|
||||
create_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.repo_name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return f"/projects/{self.id}"
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
8
FOSSDB_web/apps/fossdb/urls.py
Normal file
8
FOSSDB_web/apps/fossdb/urls.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
path("add", views.add_project, name="add-project"),
|
||||
]
|
||||
@ -1,3 +1,25 @@
|
||||
from django.shortcuts import render
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
# Create your views here.
|
||||
from .forms import ProjectForm
|
||||
from .models import Project
|
||||
|
||||
|
||||
def index(request):
|
||||
projects = Project.objects.all()
|
||||
return render(request, "fossdb/index.html", {"title": "FOSSDB", "projects": projects})
|
||||
|
||||
|
||||
@login_required(login_url="account/login/")
|
||||
@permission_required("fossdb.add_post)", login_url="account/login/", raise_exception=True)
|
||||
def add_project(request):
|
||||
if request.method == "POST":
|
||||
project = ProjectForm(request.POST)
|
||||
if project.is_valid():
|
||||
post = project.save(commit=False)
|
||||
post.author = request.user
|
||||
post.save()
|
||||
return redirect("")
|
||||
else:
|
||||
project = ProjectForm()
|
||||
return render(request, "main/create_project.html", {"title": "Add project", "form": project})
|
||||
|
||||
@ -37,6 +37,7 @@ ALLOWED_HOSTS = config["ALLOWED_HOSTS"]
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"fossdb",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
@ -86,7 +87,7 @@ DATABASES = {
|
||||
"USER": config["DATABASE"]["USER"],
|
||||
"PASSWORD": config["DATABASE"]["PASSWORD"],
|
||||
"HOST": config["DATABASE"]["HOST"],
|
||||
"PORT": config["DATABASE"]["PORT"]
|
||||
"PORT": config["DATABASE"]["PORT"],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,21 +1,27 @@
|
||||
"""OSSDB_web URL Configuration
|
||||
"""FOSSDB_web URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
2. Add a URL to urlpatterns: path("", views.home, name="home")
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
2. Add a URL to urlpatterns: path("", Home.as_view(), name="home")
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
2. Add a URL to urlpatterns: path("blog/", include("blog.urls"))
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
path("", include("fossdb.urls")),
|
||||
path("admin/", admin.site.urls),
|
||||
|
||||
]
|
||||
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
|
||||
13
templates/fossdb/index.html
Normal file
13
templates/fossdb/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
{% extends "layout.html" %}
|
||||
{% load static %}
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
{% block meta %}{% endblock %}
|
||||
{% block content %}
|
||||
{% for project in projects %}
|
||||
<b>@{{ project.author.username }}</b>
|
||||
<h5>{{ project.title }}</h5>
|
||||
<p>{{ project.description }}</p>
|
||||
{% empty %}
|
||||
<p>No projects yet (</p>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
15
templates/layout.html
Normal file
15
templates/layout.html
Normal file
@ -0,0 +1,15 @@
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-color-mode="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>
|
||||
{% block title %}{% endblock %}
|
||||
</title>
|
||||
{% block meta %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
12
tox.ini
12
tox.ini
@ -1,20 +1,14 @@
|
||||
[tox]
|
||||
minversion = 3.8.0
|
||||
envlist = py310, flake8, mypy
|
||||
envlist = django, flake8, mypy
|
||||
isolated_build = true
|
||||
|
||||
[gh-actions]
|
||||
python =
|
||||
3.10: py310, mypy, flake8
|
||||
|
||||
; [testenv]
|
||||
; setenv =
|
||||
; PYTHONPATH = {toxinidir}
|
||||
; deps =
|
||||
; -r{toxinidir}/requirements_dev.txt
|
||||
3.10: django, mypy, flake8
|
||||
|
||||
|
||||
[testenv]
|
||||
[testenv:django]
|
||||
basepython = python3.10
|
||||
deps = django
|
||||
commands = python manage.py test
|
||||
|
||||
Loading…
Reference in New Issue
Block a user