mirror of
https://github.com/kristoferssolo/FOSSDB.git
synced 2025-10-21 17:50:35 +00:00
Merge branch 'development' into login
This commit is contained in:
commit
8df44c7ee9
@ -1,3 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
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})
|
||||
|
||||
@ -36,6 +36,7 @@ ALLOWED_HOSTS = config["ALLOWED_HOSTS"]
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"fossdb",
|
||||
"account",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
@ -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"],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,11 +13,16 @@ 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"))
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
path("", include("fossdb.urls")),
|
||||
path("admin/", admin.site.urls),
|
||||
path("", include("django.contrib.auth.urls")),
|
||||
path("account/", include("account.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>
|
||||
Loading…
Reference in New Issue
Block a user