Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
WiKoDa - Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
innohs_one
WiKoDa - Server
Commits
cb0c508e
Commit
cb0c508e
authored
3 years ago
by
Jan Bernoth
Browse files
Options
Downloads
Patches
Plain Diff
user id
parent
f64c2f88
No related branches found
No related tags found
1 merge request
!122
User centric api
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
articles/apps.py
+7
-0
7 additions, 0 deletions
articles/apps.py
articles/test_api.py
+7
-1
7 additions, 1 deletion
articles/test_api.py
articles/views.py
+30
-3
30 additions, 3 deletions
articles/views.py
with
44 additions
and
4 deletions
articles/apps.py
+
7
−
0
View file @
cb0c508e
...
...
@@ -17,5 +17,12 @@ class ArticlesConfig(AppConfig):
# pylint: disable=import-outside-toplevel
# pylint: disable=unused-import
import
articles.signals
# noqa: F401
from
articles.models
import
User
,
Tag
# noqa: F401
# pylint: enable=unused-import
# pylint: enable=import-outside-toplevel
if
User
.
objects
.
filter
(
id_tag
=
1
).
count
()
==
0
:
user
=
User
(
id_tag
=
1
)
user
.
save
()
for
tag
in
Tag
.
objects
.
all
():
user
.
favorite_tags
.
add
(
tag
)
user
.
save
()
This diff is collapsed.
Click to expand it.
articles/test_api.py
+
7
−
1
View file @
cb0c508e
...
...
@@ -6,7 +6,7 @@ from unittest import mock
from
django.db.models.signals
import
post_save
from
django.test
import
TransactionTestCase
from
articles.models
import
Article
,
MediumType
,
Medium
,
Files
from
articles.models
import
Article
,
MediumType
,
Medium
,
Files
,
User
from
articles.serializers
import
MediumTypeSerializer
,
MediumSerializer
,
ArticleSerializer
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -103,3 +103,9 @@ class ArticleTest(TransactionTestCase):
input_data_
=
{
'
medium
'
:
medium
,
**
input_data
}
ArticleSerializer
().
create
(
input_data_
)
self
.
assertEqual
(
Article
.
objects
.
count
(),
2
)
class
OverviewTest
(
TransactionTestCase
):
def
test_user
(
self
):
user
=
User
.
objects
.
get
(
id_tag
=
1
)
self
.
assertTrue
(
user
.
activated
)
This diff is collapsed.
Click to expand it.
articles/views.py
+
30
−
3
View file @
cb0c508e
...
...
@@ -2,7 +2,9 @@
import
datetime
import
logging
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.db.models
import
Q
from
django.http
import
JsonResponse
from
django.shortcuts
import
render
from
django.utils
import
timezone
from
django.utils.decorators
import
method_decorator
...
...
@@ -10,6 +12,7 @@ from django.views import View
from
django.views.generic
import
TemplateView
from
drf_yasg.utils
import
swagger_auto_schema
from
rest_framework
import
generics
from
rest_framework.views
import
APIView
from
articles.forms
import
FileUploadForm
from
articles.models
import
Article
,
Timeline
,
Medium
,
MediumType
,
Overview
,
TopMedia
,
Tag
,
TopTags
,
Files
,
User
...
...
@@ -92,12 +95,36 @@ class TimelineList(generics.ListAPIView):
serializer_class
=
TimelineSerializer
class
OverviewList
(
generics
.
ListAPIView
):
def
user_tags
(
id_tag
):
try
:
user
=
User
.
objects
.
get
(
id_tag
=
id_tag
)
except
ObjectDoesNotExist
:
logger
.
error
(
'
User with id_tag %s does not exists
'
,
str
(
id_tag
))
return
[]
tag_names
=
[]
for
tag
in
user
.
favorite_tags
.
all
():
tag_names
.
append
(
tag
.
name
)
return
tag_names
class
OverviewList
(
APIView
):
"""
List all overview objects
"""
today
=
datetime
.
datetime
.
today
()
datetime_recent
=
today
-
datetime
.
timedelta
(
days
=
90
)
queryset
=
Overview
.
objects
.
filter
(
date_of_publication__range
=
[
datetime_recent
,
today
])
serializer_class
=
OverviewSerializer
# queryset = Overview.objects.filter(date_of_publication__range=[datetime_recent, today])
# serializer_class = OverviewSerializer
def
get
(
self
,
request
):
"""
get overview, a user can be selected with user=user_id
"""
tag_names
=
user_tags
(
1
)
if
request
.
query_params
.
__contains__
(
'
user
'
):
tag_names
=
user_tags
(
request
.
query_params
[
'
user
'
])
overview_objects
=
Overview
.
objects
.
filter
(
date_of_publication__range
=
[
self
.
datetime_recent
,
self
.
today
]).
filter
(
name__in
=
tag_names
)
overview_serializer
=
OverviewSerializer
(
overview_objects
,
many
=
True
)
return
JsonResponse
(
overview_serializer
.
data
,
safe
=
False
)
class
Home
(
TemplateView
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment