Merge branch 'fossdb' into hosting-platform

This commit is contained in:
Kristofers Solo 2023-04-08 13:52:03 +03:00
commit 21ef4a0154
23 changed files with 173 additions and 62 deletions

View File

@ -1,12 +1,7 @@
from django.contrib import admin from django.contrib import admin
from programming_language.admin import ProjectProgrammingLanguageInline
from .models import (HostingPlatform, License, ProgrammingLanguage, Project, from .models import HostingPlatform, License, Project, ProjectHostingPlatform
ProjectHostingPlatform, ProjectProgrammingLanguage)
class ProjectProgrammingLanguageInline(admin.TabularInline):
model = ProjectProgrammingLanguage
extra = 1
class ProjectHostingPlatformInline(admin.TabularInline): class ProjectHostingPlatformInline(admin.TabularInline):
@ -25,7 +20,7 @@ class ProjectAdmin(admin.ModelAdmin):
return " | ".join([i.hosting_platform.hosting_platform for i in object.projecthostingplatform_set.all()]) return " | ".join([i.hosting_platform.hosting_platform for i in object.projecthostingplatform_set.all()])
admin.site.register(License)
admin.site.register(ProgrammingLanguage) admin.site.register(ProgrammingLanguage)
admin.site.register(HostingPlatform) admin.site.register(HostingPlatform)
admin.site.register(Project, ProjectAdmin) admin.site.register(Project, ProjectAdmin)
admin.site.register(Tag)

View File

@ -1,7 +1,6 @@
from django import forms from django import forms
from .models import (HostingPlatform, License, ProgrammingLanguage, Project, from .models import HostingPlatform, Project, ProjectHostingPlatform
ProjectHostingPlatform, ProjectProgrammingLanguage)
class ProjectForm(forms.ModelForm): class ProjectForm(forms.ModelForm):
@ -23,29 +22,6 @@ class ProjectForm(forms.ModelForm):
} }
class LicenseForm(forms.ModelForm):
class Meta:
model = License
fields = ["short_name", "full_name", "url", "description"]
class ProgrammingLanguageForm(forms.ModelForm):
percentage = forms.IntegerField(min_value=0, max_value=100)
class Meta:
model = ProgrammingLanguage
fields = ["language", "percentage"]
ProjectProgrammingLanguageFormSet = forms.inlineformset_factory(
Project,
ProjectProgrammingLanguage,
form=ProgrammingLanguageForm,
extra=1,
can_delete=True,
)
class HostingPlatformForm(forms.ModelForm): class HostingPlatformForm(forms.ModelForm):
url = forms.URLField() url = forms.URLField()

View File

@ -0,0 +1,22 @@
# Generated by Django 4.1.7 on 2023-04-08 10:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('license', '0001_initial'),
('fossdb', '0001_initial'),
]
operations = [
migrations.DeleteModel(
name='License',
),
migrations.AlterField(
model_name='project',
name='licenses',
field=models.ManyToManyField(to='license.license'),
),
]

View File

@ -1,33 +1,11 @@
import uuid import uuid
from django.contrib.auth.models import User from django.conf import settings
from django.db import models from django.db import models
from license.models import License
from programming_language.models import ProgrammingLanguage
User = settings.AUTH_USER_MODEL
class License(models.Model):
short_name = models.CharField(max_length=50)
full_name = models.CharField(max_length=100, null=True, blank=True)
url = models.URLField(null=True, blank=True)
description = models.TextField(null=True, blank=True)
def __str__(self):
return self.short_name
class ProgrammingLanguage(models.Model):
language = models.CharField(max_length=100)
def __str__(self):
return self.language
class ProjectProgrammingLanguage(models.Model):
project = models.ForeignKey("Project", on_delete=models.CASCADE)
language = models.ForeignKey(ProgrammingLanguage, on_delete=models.CASCADE)
percentage = models.PositiveIntegerField()
def __str__(self):
return f"{self.project} | {self.language} | {self.percentage}%"
class HostingPlatform(models.Model): class HostingPlatform(models.Model):
@ -46,6 +24,12 @@ class ProjectHostingPlatform(models.Model):
return f"{self.project} | {self.hosting_platform}" return f"{self.project} | {self.hosting_platform}"
class Tag(models.Model):
name = models.CharField(max_length=100)
description = models.TextField(null=True, blank=True)
icon = models.ImageField(upload_to="types/icons/", null=True, blank=True)
class Project(models.Model): class Project(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
author = models.ForeignKey(User, on_delete=models.CASCADE) author = models.ForeignKey(User, on_delete=models.CASCADE)
@ -54,6 +38,7 @@ class Project(models.Model):
licenses = models.ManyToManyField(License) licenses = models.ManyToManyField(License)
programming_languages = models.ManyToManyField(ProgrammingLanguage, through="ProjectProgrammingLanguage", related_name="projects") programming_languages = models.ManyToManyField(ProgrammingLanguage, through="ProjectProgrammingLanguage", related_name="projects")
hosting_platform = models.ManyToManyField(HostingPlatform, through="ProjectHostingPlatform", related_name="projects") hosting_platform = models.ManyToManyField(HostingPlatform, through="ProjectHostingPlatform", related_name="projects")
project_type = models.ForeignKey(Tag, on_delete=models.CASCADE, blank=True, null=True)
date_created = models.DateTimeField(auto_now_add=True) date_created = models.DateTimeField(auto_now_add=True)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):

View File

@ -1,8 +1,8 @@
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from programming_language.forms import ProjectProgrammingLanguageFormSet
from .forms import (ProjectForm, ProjectHostingPlatformFormSet, from .forms import ProjectForm, ProjectHostingPlatformFormSet
ProjectProgrammingLanguageFormSet)
from .models import Project from .models import Project

View File

View File

@ -0,0 +1,5 @@
from django.contrib import admin
from .models import License
admin.site.register(License)

View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class LicenseConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'license'

View File

@ -0,0 +1,9 @@
from django import forms
from .models import License
class LicenseForm(forms.ModelForm):
class Meta:
model = License
fields = ["short_name", "full_name", "url", "description"]

View File

@ -0,0 +1,24 @@
# Generated by Django 4.1.7 on 2023-04-08 10:14
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='License',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('short_name', models.CharField(max_length=50)),
('full_name', models.CharField(blank=True, max_length=100, null=True)),
('url', models.URLField(blank=True, null=True)),
('description', models.TextField(blank=True, null=True)),
],
),
]

View File

@ -0,0 +1,11 @@
from django.db import models
class License(models.Model):
short_name = models.CharField(max_length=50)
full_name = models.CharField(max_length=100, null=True, blank=True)
url = models.URLField(null=True, blank=True)
description = models.TextField(null=True, blank=True)
def __str__(self):
return self.short_name

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

View File

@ -0,0 +1,11 @@
from django.contrib import admin
from .models import ProgrammingLanguage, ProjectProgrammingLanguage
class ProjectProgrammingLanguageInline(admin.TabularInline):
model = ProjectProgrammingLanguage
extra = 1
admin.site.register(ProgrammingLanguage)

View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ProgrammingLanguageConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'programming_language'

View File

@ -0,0 +1,21 @@
from django import forms
from fossdb.models import Project
from .models import ProgrammingLanguage, ProjectProgrammingLanguage
class ProgrammingLanguageForm(forms.ModelForm):
percentage = forms.IntegerField(min_value=0, max_value=100)
class Meta:
model = ProgrammingLanguage
fields = ["language", "percentage"]
ProjectProgrammingLanguageFormSet = forms.inlineformset_factory(
Project,
ProjectProgrammingLanguage,
form=ProgrammingLanguageForm,
extra=1,
can_delete=True,
)

View File

@ -0,0 +1,17 @@
from django.db import models
class ProgrammingLanguage(models.Model):
language = models.CharField(max_length=100)
def __str__(self):
return self.language
class ProjectProgrammingLanguage(models.Model):
project = models.ForeignKey("Project", on_delete=models.CASCADE)
language = models.ForeignKey(ProgrammingLanguage, on_delete=models.CASCADE)
percentage = models.PositiveIntegerField()
def __str__(self):
return f"{self.project} | {self.language} | {self.percentage}%"

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@ -37,7 +37,9 @@ ALLOWED_HOSTS = config["ALLOWED_HOSTS"]
INSTALLED_APPS = [ INSTALLED_APPS = [
"fossdb", "fossdb",
"license",
"account", "account",
"programming_language",
"hosting_platform", "hosting_platform",
"django.contrib.admin", "django.contrib.admin",
"django.contrib.auth", "django.contrib.auth",
@ -83,7 +85,7 @@ WSGI_APPLICATION = "FOSSDB_web.wsgi.application"
DATABASES = { DATABASES = {
"default": { "default": {
"ENGINE": "django.db.backends.mysql", "ENGINE": f"django.db.backends.{config['DATABASE']['ENGINE']}",
"NAME": config["DATABASE"]["NAME"], "NAME": config["DATABASE"]["NAME"],
"USER": config["DATABASE"]["USER"], "USER": config["DATABASE"]["USER"],
"PASSWORD": config["DATABASE"]["PASSWORD"], "PASSWORD": config["DATABASE"]["PASSWORD"],
@ -129,6 +131,7 @@ USE_TZ = True
STATIC_URL = "/static/" STATIC_URL = "/static/"
STATIC_ROOT = BASE_PATH.joinpath("static") STATIC_ROOT = BASE_PATH.joinpath("static")
MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_PATH.joinpath("media") MEDIA_ROOT = BASE_PATH.joinpath("media")
# Default primary key field type # Default primary key field type
@ -137,3 +140,14 @@ MEDIA_ROOT = BASE_PATH.joinpath("media")
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
LOGIN_REDIRECT_URL = "/" LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/" LOGOUT_REDIRECT_URL = "/"
# HTTPS settings
# SESSION_COOKIE_SECURE = True
# CSRF_COOKIE_SECURE = True
# SECURE_SSL_REDIRECT = True
# HSTS settings
# SECURE_HSTS_SECONDS = 31536000 # 1 year
# SECURE_HSTS_SECONDS = 1 # 1 year
# SECURE_HSTS_PRELOAD = True
# SECURE_HSTS_INCLUDE_SUBDOMAINS = True