Skip to content

Commit 5c093cd

Browse files
committed
wip files
1 parent 9b57cd4 commit 5c093cd

File tree

7 files changed

+331
-100
lines changed

7 files changed

+331
-100
lines changed

baseapp-files/baseapp_files/admin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class FileInlineAdmin(GenericStackedInline):
1313

1414
@admin.register(File)
1515
class FileAdmin(admin.ModelAdmin):
16-
list_display = ("pk", "file_type", "parent", "created_by", "created")
16+
list_display = ("pk", "name", "content_type", "parent", "created_by", "created")
1717
search_fields = ("name",)
1818
raw_id_fields = ("created_by",)

baseapp-files/baseapp_files/apps.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.apps import AppConfig
22

33

4-
class BaseAppPagesConfig(AppConfig):
5-
name = "baseapp_pages"
6-
verbose_name = "BaseApp Pages"
4+
class BaseAppFilesConfig(AppConfig):
5+
name = "baseapp_files"
6+
verbose_name = "BaseApp Files"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from graphene import Field, NonNull
2+
from ..models import File
3+
from graphene_django.debug import DjangoDebug
4+
from graphene_django_cud.mutations import DjangoCreateMutation, DjangoDeleteMutation, DjangoPatchMutation
5+
from baseapp_core.graphql.errors import Errors
6+
7+
from .object_types import FileNode
8+
9+
10+
class FileCreateMutation(DjangoCreateMutation):
11+
errors = Errors()
12+
debug = Field(DjangoDebug, name="_debug")
13+
file = Field(FileNode._meta.connection.Edge)
14+
# files = Field("files.object_types.FileNode", required=False)
15+
16+
class Meta:
17+
model = File
18+
login_required = True
19+
auto_context_fields = {"user": "user"}
20+
exclude_fields = ("user", "created", "modified")
21+
# field_types = {"file_type": NonNull(FileTypeEnum)}
22+
23+
24+
class PatchFileMutation(DjangoPatchMutation):
25+
class Meta:
26+
model = File
27+
login_required = True
28+
exclude_fields = ("user", "created", "modified")
29+
30+
31+
class DeleteFileMutation(DjangoDeleteMutation):
32+
class Meta:
33+
model = File
34+
login_required = True
35+
exclude_fields = ("user", "created", "modified")
36+
37+
38+
class FilesMutations(object):
39+
file_create = FileCreateMutation.Field()
40+
file_patch = PatchFileMutation.Field()
41+
file_delete = DeleteFileMutation.Field()
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,62 @@
1+
import django_filters
12
import graphene
2-
import swapper
3-
from baseapp_core.graphql import CountedConnection
4-
from baseapp_pages.models import Language, Metadata, URLPath
53
from graphene import relay
6-
from graphene_django import DjangoObjectType
4+
from graphene.types.generic import GenericScalar
5+
from baseapp_core.graphql import DjangoObjectType
6+
from graphene_django.filter import DjangoFilterConnectionField
7+
from django.contrib.contenttypes.models import ContentType
78

8-
Page = swapper.load_model("baseapp_pages", "Page")
9+
from ..models import File
910

10-
LanguageEnum = graphene.Enum.from_enum(Language)
11+
# FileTypeEnum = graphene.Enum.from_enum(FileType)
1112

1213

13-
class PageInterface(relay.Node):
14-
url_paths = graphene.List(lambda: URLPathNode)
15-
meta_title = graphene.String()
16-
meta_description = graphene.String(required=False)
17-
meta_canonical = graphene.String(required=False)
18-
meta_robots = graphene.String(required=False)
19-
meta_og_type = graphene.String(required=False)
20-
meta_og_image = graphene.String(required=False)
14+
class FileFilter(django_filters.FilterSet):
15+
no_parent = django_filters.BooleanFilter(field_name='parent_object_id', lookup_expr='isnull')
2116

22-
# TO DO: URL alternates for SEO:
23-
# https://developers.google.com/search/docs/specialty/international/localized-versions
24-
25-
@classmethod
26-
def resolve_meta_title(cls, instance, info, **kwargs):
27-
raise NotImplementedError
28-
29-
@classmethod
30-
def resolve_meta_description(cls, instance, info, **kwargs):
31-
raise NotImplementedError
32-
33-
@classmethod
34-
def resolve_meta_canonical(cls, instance, info, **kwargs):
35-
# TO DO: implement here in the interface
36-
37-
# return active url path in this language the user is visiting from
38-
# we can use this to make 301 redirects?
39-
raise NotImplementedError
40-
41-
@classmethod
42-
def resolve_meta_robots(cls, instance, info, **kwargs):
43-
raise NotImplementedError
44-
45-
@classmethod
46-
def resolve_meta_og_type(cls, instance, info, **kwargs):
47-
raise NotImplementedError
48-
49-
@classmethod
50-
def resolve_meta_og_image(cls, instance, info, **kwargs):
51-
raise NotImplementedError
17+
class Meta:
18+
model = File
19+
fields = ['no_parent']
20+
# fields = {
21+
# "id": ["exact"],
22+
# "file_type": ["exact"],
23+
# "file": ["exact"],
24+
# "file__icontains": ["exact"],
25+
# }
5226

5327

54-
class URLPathNode(DjangoObjectType):
55-
target = graphene.Field(PageInterface)
56-
language = graphene.Field(LanguageEnum)
28+
class FileNode(DjangoObjectType):
29+
parent = graphene.Field(relay.Node)
30+
file = graphene.String()
31+
# file_type = graphene.Field(FileTypeEnum)
5732

5833
class Meta:
5934
interfaces = (relay.Node,)
60-
model = URLPath
61-
fields = (
62-
"id",
63-
"path",
64-
"language",
65-
"is_active",
66-
"created",
67-
"modified",
68-
"target",
69-
)
70-
filter_fields = {
71-
"id": ["exact"],
72-
}
73-
name = "URLPath"
74-
connection_class = CountedConnection
75-
76-
77-
class MetadataNode(DjangoObjectType):
78-
class Meta:
79-
interfaces = (relay.Node, PageInterface)
80-
model = Metadata
81-
# fields = ("id", "meta_title", "meta_description", "meta_robots", "meta_og_type", "meta_og_image", "meta_canonical")
82-
fields = ("id",)
83-
name = "Metadata"
84-
connection_class = CountedConnection
35+
model = File
36+
filterset_class = FileFilter
37+
38+
def resolve_file(self, info, **kwargs):
39+
return self.file.url
40+
41+
# @classmethod
42+
# def get_node(cls, info, id):
43+
# if not info.context.user.is_authenticated:
44+
# return None
45+
46+
# try:
47+
# queryset = cls.get_queryset(cls._meta.model.objects, info)
48+
# return queryset.get(id=id, recipient=info.context.user)
49+
# except cls._meta.model.DoesNotExist:
50+
# return None
51+
52+
53+
class FilesNode(relay.Node):
54+
files_count = GenericScalar()
55+
files = DjangoFilterConnectionField(lambda: FileNode)
56+
57+
def resolve_files(self, info, **kwargs):
58+
parent_content_type = ContentType.objects.get_for_model(self)
59+
return File.objects.filter(
60+
parent_content_type=parent_content_type,
61+
parent_object_id=self.pk,
62+
).order_by("-created")
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import graphene
2-
from graphene import relay
1+
from graphene_django.filter import DjangoFilterConnectionField
32

4-
from ..models import URLPath
5-
from .object_types import PageInterface, URLPathNode
3+
from .object_types import FileNode
64

75

8-
class PagesQuery:
9-
url_path = graphene.Field(URLPathNode, path=graphene.String(required=True))
10-
11-
def resolve_url_path(self, info, path):
12-
return URLPath.objects.get(path=path)
6+
class FilesQueries:
7+
my_files = DjangoFilterConnectionField(FileNode)

0 commit comments

Comments
 (0)