Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gakamine committed Jan 24, 2023
0 parents commit 6573889
Show file tree
Hide file tree
Showing 64 changed files with 7,242 additions and 0 deletions.
Empty file added C2_EFREI/__init__.py
Empty file.
Binary file added C2_EFREI/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added C2_EFREI/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file added C2_EFREI/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file added C2_EFREI/__pycache__/wsgi.cpython-310.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions C2_EFREI/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for C2_EFREI project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'C2_EFREI.settings')

application = get_asgi_application()
125 changes: 125 additions & 0 deletions C2_EFREI/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""
Django settings for C2_EFREI project.
Generated by 'django-admin startproject' using Django 4.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-qmh8ex%85l4%z(y95wykw%yvrzy7#152bg@66lumi!4zyp074q'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'collector.apps.CollectorConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'C2_EFREI.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'C2_EFREI.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
22 changes: 22 additions & 0 deletions C2_EFREI/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""C2_EFREI URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.1/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')
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')
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.contrib import admin
from django.urls import include,path

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('collector.urls'))
]
16 changes: 16 additions & 0 deletions C2_EFREI/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for C2_EFREI project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'C2_EFREI.settings')

application = get_wsgi_application()
Empty file added collector/__init__.py
Empty file.
Binary file added collector/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added collector/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file added collector/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file added collector/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file added collector/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file added collector/__pycache__/views.cpython-310.pyc
Binary file not shown.
24 changes: 24 additions & 0 deletions collector/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.contrib import admin
from django.utils.html import format_html

# Register your models here.
from .models import Computer,Data

@admin.register(Computer)
class ComputerAdmin(admin.ModelAdmin):
def related_data(self, obj):
return format_html("<a href='../data/?computer__id__exact={}'>See related data</a>",obj.id)
list_display = ['hostname','ip_address','pub_date','related_data']
search_fields = ['hostname','ip_address']
list_filter = ('pub_date','hostname')

@admin.register(Data)
class DataAdmin(admin.ModelAdmin):
def data(self, obj):
if obj.is_file:
return format_html("<a href='data:application/octet-stream;base64,{}' download>Download</a>",obj.data_content)
else:
return obj.data_content
list_display = ['computer','data_type','pub_date','data','is_file']
search_fields = ['computer__hostname']
list_filter = ('pub_date','data_type','is_file')
6 changes: 6 additions & 0 deletions collector/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CollectorConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'collector'
33 changes: 33 additions & 0 deletions collector/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.1.5 on 2023-01-24 18:55

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Computer',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('hostname', models.CharField(max_length=200)),
('ip_address', models.CharField(max_length=200)),
('pub_date', models.DateTimeField(verbose_name='date')),
],
),
migrations.CreateModel(
name='Data',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('data_type', models.CharField(max_length=200)),
('data_content', models.CharField(max_length=200)),
('computer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='collector.computer')),
],
),
]
25 changes: 25 additions & 0 deletions collector/migrations/0002_data_pub_date_alter_computer_pub_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.1.5 on 2023-01-24 19:26

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('collector', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='data',
name='pub_date',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AlterField(
model_name='computer',
name='pub_date',
field=models.DateTimeField(auto_now_add=True),
),
]
18 changes: 18 additions & 0 deletions collector/migrations/0003_data_is_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.5 on 2023-01-24 20:51

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('collector', '0002_data_pub_date_alter_computer_pub_date'),
]

operations = [
migrations.AddField(
model_name='data',
name='is_file',
field=models.BooleanField(default=False),
),
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions collector/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import models

# Create your models here.
class Computer(models.Model):
hostname = models.CharField(max_length=200)
ip_address = models.CharField(max_length=200)
pub_date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.hostname

class Data(models.Model):
computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
data_type = models.CharField(max_length=200)
data_content = models.CharField(max_length=200)
pub_date = models.DateTimeField(auto_now_add=True)
is_file = models.BooleanField(default=False)
def __str__(self):
return self.computer.hostname
Loading

0 comments on commit 6573889

Please sign in to comment.