diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 776c8ea..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 81c4998..25fa3fb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/FOSSDB_web/apps/fossdb/admin.py b/FOSSDB_web/apps/fossdb/admin.py index 8c38f3f..e69de29 100644 --- a/FOSSDB_web/apps/fossdb/admin.py +++ b/FOSSDB_web/apps/fossdb/admin.py @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/FOSSDB_web/apps/fossdb/apps.py b/FOSSDB_web/apps/fossdb/apps.py index 6c8b002..ba8e8cd 100644 --- a/FOSSDB_web/apps/fossdb/apps.py +++ b/FOSSDB_web/apps/fossdb/apps.py @@ -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" diff --git a/FOSSDB_web/apps/fossdb/forms.py b/FOSSDB_web/apps/fossdb/forms.py new file mode 100644 index 0000000..9603689 --- /dev/null +++ b/FOSSDB_web/apps/fossdb/forms.py @@ -0,0 +1,9 @@ +from django import forms + +from .models import Project + + +class ProjectForm(forms.ModelForm): + class Meta: + model = Project + fields = ["title", "description"] diff --git a/FOSSDB_web/apps/fossdb/migrations/0001_initial.py b/FOSSDB_web/apps/fossdb/migrations/0001_initial.py new file mode 100644 index 0000000..def7053 --- /dev/null +++ b/FOSSDB_web/apps/fossdb/migrations/0001_initial.py @@ -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)), + ], + ), + ] diff --git a/FOSSDB_web/apps/fossdb/models.py b/FOSSDB_web/apps/fossdb/models.py index 71a8362..e61e920 100644 --- a/FOSSDB_web/apps/fossdb/models.py +++ b/FOSSDB_web/apps/fossdb/models.py @@ -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}" diff --git a/FOSSDB_web/apps/fossdb/tests.py b/FOSSDB_web/apps/fossdb/tests.py index 7ce503c..e69de29 100644 --- a/FOSSDB_web/apps/fossdb/tests.py +++ b/FOSSDB_web/apps/fossdb/tests.py @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/FOSSDB_web/apps/fossdb/urls.py b/FOSSDB_web/apps/fossdb/urls.py new file mode 100644 index 0000000..11fbdee --- /dev/null +++ b/FOSSDB_web/apps/fossdb/urls.py @@ -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"), +] diff --git a/FOSSDB_web/apps/fossdb/views.py b/FOSSDB_web/apps/fossdb/views.py index 91ea44a..35c3d5a 100644 --- a/FOSSDB_web/apps/fossdb/views.py +++ b/FOSSDB_web/apps/fossdb/views.py @@ -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}) diff --git a/FOSSDB_web/settings.py b/FOSSDB_web/settings.py index 34fb5ca..cc0962b 100644 --- a/FOSSDB_web/settings.py +++ b/FOSSDB_web/settings.py @@ -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"], } } diff --git a/FOSSDB_web/urls.py b/FOSSDB_web/urls.py index 4025788..b4a15ab 100644 --- a/FOSSDB_web/urls.py +++ b/FOSSDB_web/urls.py @@ -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) diff --git a/templates/fossdb/index.html b/templates/fossdb/index.html new file mode 100644 index 0000000..c7843d8 --- /dev/null +++ b/templates/fossdb/index.html @@ -0,0 +1,13 @@ +{% extends "layout.html" %} +{% load static %} +{% block title %}{{ title }}{% endblock %} +{% block meta %}{% endblock %} +{% block content %} + {% for project in projects %} + @{{ project.author.username }} +
{{ project.description }}
+ {% empty %} +No projects yet (
+ {% endfor %} +{% endblock %} diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..08fe90d --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,15 @@ +{% load static %} + + + + + +