-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented working django rest framework
- Loading branch information
Showing
36 changed files
with
280 additions
and
1,874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
import environ | ||
|
||
env = environ.Env() | ||
env.read_env(".env") | ||
env.read_env("../.env") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Generated by Django 3.2.16 on 2023-01-25 13:43 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Dependency', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100, unique=True)), | ||
], | ||
options={ | ||
'ordering': ['name'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='DependencyVersion', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('version', models.CharField(max_length=100)), | ||
('release_date', models.DateField()), | ||
('end_of_life_date', models.DateField()), | ||
('dependency', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='outdated.dependency')), | ||
], | ||
options={ | ||
'ordering': ['end_of_life_date'], | ||
'unique_together': {('dependency', 'version')}, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Project', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100, unique=True)), | ||
('repo', models.URLField(unique=True)), | ||
('dependency_versions', models.ManyToManyField(blank=True, to='outdated.DependencyVersion')), | ||
], | ||
options={ | ||
'ordering': ['status'], | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 3.2.16 on 2023-01-25 14:02 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('outdated', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='project', | ||
options={'ordering': ['name']}, | ||
), | ||
] |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ProjectsConfig(AppConfig): | ||
class OutdatedConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "projects" | ||
name = "outdatedf" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from datetime import date, timedelta | ||
from django.db import models | ||
|
||
# Create your models here. | ||
|
||
|
||
class Dependency(models.Model): | ||
name = models.CharField(max_length=100, unique=True) | ||
|
||
class Meta: | ||
ordering = ["name"] | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class DependencyVersion(models.Model): | ||
|
||
dependency = models.ForeignKey(Dependency, on_delete=models.CASCADE) | ||
version = models.CharField(max_length=100) | ||
release_date = models.DateField() | ||
end_of_life_date = models.DateField() | ||
|
||
class Meta: | ||
ordering = ["end_of_life_date"] | ||
unique_together = ("dependency", "version") | ||
|
||
def __str__(self): | ||
return self.dependency.name + " " + self.version | ||
|
||
@property | ||
def status(self): | ||
if date.today() >= self.end_of_life_date: | ||
return "OUTDATED" | ||
elif date.today() + timedelta(days=30) >= self.end_of_life_date: | ||
return "WARNING" | ||
return "UP-TO-DATE" | ||
|
||
|
||
class Project(models.Model): | ||
|
||
name = models.CharField(max_length=100, unique=True) | ||
repo = models.URLField(max_length=200, unique=True) | ||
dependency_versions = models.ManyToManyField(DependencyVersion, blank=True) | ||
|
||
class Meta: | ||
ordering = ["name"] | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
@property | ||
def status(self) -> str: | ||
return self.dependency_versions.first().status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from outdated.outdated.models import Dependency, DependencyVersion, Project | ||
from rest_framework_json_api import serializers | ||
|
||
|
||
class DependencySerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = Dependency | ||
fields = "__all__" | ||
|
||
|
||
class DependencyVersionSerializer(serializers.HyperlinkedModelSerializer): | ||
status = serializers.ReadOnlyField() | ||
|
||
class Meta: | ||
model = DependencyVersion | ||
fields = "__all__" | ||
|
||
|
||
class ProjectSerializer(serializers.HyperlinkedModelSerializer): | ||
status = serializers.ReadOnlyField() | ||
|
||
class Meta: | ||
model = Project | ||
fields = "__all__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from outdated.outdated.models import Dependency, DependencyVersion, Project | ||
from outdated.outdated.serializers import ( | ||
DependencySerializer, | ||
DependencyVersionSerializer, | ||
ProjectSerializer, | ||
) | ||
from rest_framework import viewsets | ||
|
||
|
||
class ProjectViewSet(viewsets.ModelViewSet): | ||
queryset = Project.objects.all() | ||
serializer_class = ProjectSerializer | ||
|
||
|
||
class DependencyVersionViewSet(viewsets.ModelViewSet): | ||
queryset = DependencyVersion.objects.all() | ||
serializer_class = DependencyVersionSerializer | ||
|
||
|
||
class DependencyViewSet(viewsets.ModelViewSet): | ||
queryset = Dependency.objects.all() | ||
serializer_class = DependencySerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
from django.contrib import admin | ||
from django.urls import include, path | ||
from outdated.outdated import views | ||
from rest_framework import routers | ||
|
||
urlpatterns = [ | ||
path("admin/", admin.site.urls), | ||
path("", include("projects.urls")), | ||
] | ||
router = routers.DefaultRouter() | ||
router.register(r"projects", views.ProjectViewSet) | ||
router.register(r"dependencies", views.DependencyViewSet) | ||
router.register(r"dependency-versions", views.DependencyVersionViewSet) | ||
|
||
urlpatterns = [path("admin/", admin.site.urls), path("", include(router.urls))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.