feat(core): notes model added to core

!8 #7
This commit is contained in:
2024-05-21 01:18:37 +09:30
parent cad2bfe7da
commit 8e0df948d5
8 changed files with 274 additions and 0 deletions

15
app/core/forms/comment.py Normal file
View File

@ -0,0 +1,15 @@
from django import forms
from app import settings
from core.models.notes import Notes
class AddNoteForm(forms.ModelForm):
prefix = 'note'
class Meta:
model = Notes
fields = [
'note'
]

View File

@ -0,0 +1,41 @@
# Generated by Django 5.0.6 on 2024-05-20 15:44
import access.fields
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('access', '0001_initial'),
('itam', '0007_device_inventorydate'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Notes',
fields=[
('is_global', models.BooleanField(default=False)),
('id', models.AutoField(primary_key=True, serialize=False, unique=True)),
('created', access.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False)),
('modified', access.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False)),
('serial_number', models.CharField(blank=True, default=None, max_length=50, null=True, verbose_name='Serial Number')),
('note', models.TextField(default=None, null=True, verbose_name='Note')),
('device', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='itam.device')),
('operatingsystem', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='itam.operatingsystem')),
('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='access.organization')),
('software', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='itam.software')),
('usercreated', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, related_name='usercreated', to=settings.AUTH_USER_MODEL, verbose_name='Added By')),
('usermodified', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, related_name='usermodified', to=settings.AUTH_USER_MODEL, verbose_name='Edited By')),
],
options={
'ordering': ['-created'],
},
),
]

View File

109
app/core/models/notes.py Normal file
View File

@ -0,0 +1,109 @@
from django.contrib.auth.models import User
from django.db import models
from access.fields import *
from access.models import TenancyObject
from itam.models.device import Device
from itam.models.software import Software
from itam.models.operating_system import OperatingSystem
class NotesCommonFields(TenancyObject, models.Model):
class Meta:
abstract = True
id = models.AutoField(
primary_key=True,
unique=True,
blank=False
)
created = AutoCreatedField()
modified = AutoLastModifiedField()
class Notes(NotesCommonFields):
""" Notes that can be left against a model
Currently supported models are:
- Device
- Operating System
- Software
"""
class Meta:
ordering = [
'-created'
]
serial_number = models.CharField(
verbose_name = 'Serial Number',
max_length = 50,
default = None,
null = True,
blank = True
)
note = models.TextField(
verbose_name = 'Note',
blank = False,
default = None,
null = True
)
usercreated = models.ForeignKey(
User,
verbose_name = 'Added By',
related_name = 'usercreated',
on_delete=models.SET_DEFAULT,
default = None,
null = True,
blank= True
)
usermodified = models.ForeignKey(
User,
verbose_name = 'Edited By',
related_name = 'usermodified',
on_delete=models.SET_DEFAULT,
default = None,
null = True,
blank= True
)
device = models.ForeignKey(
Device,
on_delete=models.SET_DEFAULT,
default = None,
null = True,
blank= True
)
software = models.ForeignKey(
Software,
on_delete=models.SET_DEFAULT,
default = None,
null = True,
blank= True
)
operatingsystem = models.ForeignKey(
OperatingSystem,
on_delete=models.SET_DEFAULT,
default = None,
null = True,
blank= True
)
def __str__(self):
return 'Note ' + str(self.id)

View File

@ -0,0 +1,35 @@
{% load markdown %}
<div class="comment">
<div class="comment-header">
<svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 -960 960 960" width="16px">
<path
d="M480-400q-17 0-28.5-11.5T440-440q0-17 11.5-28.5T480-480q17 0 28.5 11.5T520-440q0 17-11.5 28.5T480-400Zm-160 0q-17 0-28.5-11.5T280-440q0-17 11.5-28.5T320-480q17 0 28.5 11.5T360-440q0 17-11.5 28.5T320-400Zm320 0q-17 0-28.5-11.5T600-440q0-17 11.5-28.5T640-480q17 0 28.5 11.5T680-440q0 17-11.5 28.5T640-400ZM480-240q-17 0-28.5-11.5T440-280q0-17 11.5-28.5T480-320q17 0 28.5 11.5T520-280q0 17-11.5 28.5T480-240Zm-160 0q-17 0-28.5-11.5T280-280q0-17 11.5-28.5T320-320q17 0 28.5 11.5T360-280q0 17-11.5 28.5T320-240Zm320 0q-17 0-28.5-11.5T600-280q0-17 11.5-28.5T640-320q17 0 28.5 11.5T680-280q0 17-11.5 28.5T640-240ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Z" />
</svg>
<span>{{ note.created }}</span>
<svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 -960 960 960" width="16px" style="">
<path
d="M480-480q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47ZM160-160v-112q0-34 17.5-62.5T224-378q62-31 126-46.5T480-440q66 0 130 15.5T736-378q29 15 46.5 43.5T800-272v112H160Z" />
</svg>
<span style="">{{ note.usercreated }}</span>
<span style="display: inline; margin-right: auto">&nbsp;</span>
</div>
<div class="comment-body">{{ note.note | markdown | safe }}</div>
<div class="comment-footer">
<span>edited by: </span>
<svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 -960 960 960" width="16px">
<path
d="M480-400q-17 0-28.5-11.5T440-440q0-17 11.5-28.5T480-480q17 0 28.5 11.5T520-440q0 17-11.5 28.5T480-400Zm-160 0q-17 0-28.5-11.5T280-440q0-17 11.5-28.5T320-480q17 0 28.5 11.5T360-440q0 17-11.5 28.5T320-400Zm320 0q-17 0-28.5-11.5T600-440q0-17 11.5-28.5T640-480q17 0 28.5 11.5T680-440q0 17-11.5 28.5T640-400ZM480-240q-17 0-28.5-11.5T440-280q0-17 11.5-28.5T480-320q17 0 28.5 11.5T520-280q0 17-11.5 28.5T480-240Zm-160 0q-17 0-28.5-11.5T280-280q0-17 11.5-28.5T320-320q17 0 28.5 11.5T360-280q0 17-11.5 28.5T320-240Zm320 0q-17 0-28.5-11.5T600-280q0-17 11.5-28.5T640-320q17 0 28.5 11.5T680-280q0 17-11.5 28.5T640-240ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Z" />
</svg>
<span>date </span>
<svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 -960 960 960" width="16px" style="">
<path
d="M480-480q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47ZM160-160v-112q0-34 17.5-62.5T224-378q62-31 126-46.5T480-440q66 0 130 15.5T736-378q29 15 46.5 43.5T800-272v112H160Z" />
</svg>
<span>username</span>
<span style="display: inline; margin-right: auto">&nbsp;</span>
</div>
</div>

View File

@ -0,0 +1,12 @@
from django import template
from django.template.defaultfilters import stringfilter
import markdown as md
register = template.Library()
@register.filter()
@stringfilter
def markdown(value):
return md.markdown(value, extensions=['markdown.extensions.fenced_code'])