forked from enviPath/enviPy
Added news entries
This commit is contained in:
+31
-10
@@ -1,10 +1,12 @@
|
||||
from typing import List
|
||||
from uuid import uuid4
|
||||
import urllib.parse
|
||||
import nh3
|
||||
from django.conf import settings as s
|
||||
from django.db import models, transaction
|
||||
from django.db.models import QuerySet
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
from epdb.models import (
|
||||
EnviPathModel,
|
||||
@@ -27,7 +29,7 @@ class Package(EnviPathModel):
|
||||
|
||||
class Classification(models.IntegerChoices):
|
||||
INTERNAL = 0, "Internal"
|
||||
RESTRICTED = 10 , "Restricted"
|
||||
RESTRICTED = 10, "Restricted"
|
||||
SECRET = 20, "Secret"
|
||||
|
||||
classification_level = models.IntegerField(
|
||||
@@ -109,7 +111,7 @@ class PESCompound(Compound):
|
||||
@staticmethod
|
||||
@transaction.atomic
|
||||
def create(
|
||||
package: "Package", pes_data: dict, name: str = None, description: str = None, *args, **kwargs
|
||||
package: "Package", pes_data: dict, name: str = None, description: str = None, *args, **kwargs
|
||||
) -> "Compound":
|
||||
|
||||
pes_url = pes_data["pes_url"]
|
||||
@@ -161,7 +163,6 @@ class PESCompound(Compound):
|
||||
normalized_structure=True,
|
||||
)
|
||||
|
||||
|
||||
cs = PESStructure.create(
|
||||
c,
|
||||
pes_url,
|
||||
@@ -218,13 +219,13 @@ class PESStructure(CompoundStructure):
|
||||
|
||||
@transaction.atomic
|
||||
def add_structure(
|
||||
self,
|
||||
smiles: str,
|
||||
name: str = None,
|
||||
description: str = None,
|
||||
default_structure: bool = False,
|
||||
*args,
|
||||
**kwargs,
|
||||
self,
|
||||
smiles: str,
|
||||
name: str = None,
|
||||
description: str = None,
|
||||
default_structure: bool = False,
|
||||
*args,
|
||||
**kwargs,
|
||||
) -> "CompoundStructure":
|
||||
raise ValueError("Not supported!")
|
||||
|
||||
@@ -236,3 +237,23 @@ class PESStructure(CompoundStructure):
|
||||
"image": f"{reverse('depict_pes')}?pesLink={urllib.parse.quote(self.pes_link)}",
|
||||
"image_type": "png",
|
||||
}
|
||||
|
||||
|
||||
class NewsEntry(models.Model):
|
||||
uuid = models.UUIDField(
|
||||
null=False, blank=False, verbose_name="UUID of this object", unique=True, default=uuid4
|
||||
)
|
||||
title = models.TextField(verbose_name="Title")
|
||||
publication_date = models.DateTimeField(verbose_name="Date", default=timezone.now)
|
||||
content = models.TextField(verbose_name="Content")
|
||||
author = models.ForeignKey("epdb.User", on_delete=models.SET_NULL, blank=True, null=True)
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return f"{s.SERVER_URL}/news/{self.uuid}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.url:
|
||||
self.url = self._url()
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user