mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-24 21:23:26 +00:00
Docstring checks in QC checks (#3089)
* Add pre-commit to the stack * exclude static * Add locales to excludes * fix style errors * rename pipeline steps * also wait on precommit * make template matching simpler * Use the same code for python setup everywhere * use step and cache for python setup * move regular settings up into general envs * just use full update * Use invoke instead of static references * make setup actions more similar * use python3 * refactor names to be similar * fix runner version * fix references * remove incidential change * use matrix for os * Github can't do this right now * ignore docstyle errors * Add seperate docstring test * update flake call * do not fail on docstring * refactor setup into workflow * update reference * switch to action * resturcture * add bash statements * remove os from cache * update input checks * make code cleaner * fix boolean * no relative paths * install wheel by python * switch to install * revert back to simple wheel * refactor import export tests * move setup keys back to not disturbe tests * remove docstyle till that is fixed * update references * continue on error * add docstring test * use relativ action references * Change step / job docstrings * update to merge * reformat comments 1 * fix docstrings 2 * fix docstrings 3 * fix docstrings 4 * fix docstrings 5 * fix docstrings 6 * fix docstrings 7 * fix docstrings 8 * fix docstirns 9 * fix docstrings 10 * docstring adjustments * update the remaining docstrings * small docstring changes * fix function name * update support files for docstrings * Add missing args to docstrings * Remove outdated function * Add docstrings for the 'build' app * Make API code cleaner * add more docstrings for plugin app * Remove dead code for plugin settings No idea what that was even intended for * ignore __init__ files for docstrings * More docstrings * Update docstrings for the 'part' directory * Fixes for related_part functionality * Fix removed stuff from merge99676ee* make more consistent * Show statistics for docstrings * add more docstrings * move specific register statements to make them clearer to understant * More docstrings for common * and more docstrings * and more * simpler call * docstrings for notifications * docstrings for common/tests * Add docs for common/models * Revert "move specific register statements to make them clearer to understant" This reverts commitca96654622. * use typing here * Revert "Make API code cleaner" This reverts commit24fb68bd3e. * docstring updates for the 'users' app * Add generic Meta info to simple Meta classes * remove unneeded unique_together statements * More simple metas * Remove unnecessary format specifier * Remove extra json format specifiers * Add docstrings for the 'plugin' app * Docstrings for the 'label' app * Add missing docstrings for the 'report' app * Fix build test regression * Fix top-level files * docstrings for InvenTree/InvenTree * reduce unneeded code * add docstrings * and more docstrings * more docstrings * more docstrings for stock * more docstrings * docstrings for order/views * Docstrings for various files in the 'order' app * Docstrings for order/test_api.py * Docstrings for order/serializers.py * Docstrings for order/admin.py * More docstrings for the order app * Add docstrings for the 'company' app * Add unit tests for rebuilding the reference fields * Prune out some more dead code * remove more dead code Co-authored-by: Oliver Walters <oliver.henry.walters@gmail.com>
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
"""
|
||||
Provides a JSON API for common components.
|
||||
"""
|
||||
"""Provides a JSON API for common components."""
|
||||
|
||||
import json
|
||||
|
||||
@@ -24,25 +22,23 @@ from plugin.serializers import NotificationUserSettingSerializer
|
||||
|
||||
|
||||
class CsrfExemptMixin(object):
|
||||
"""
|
||||
Exempts the view from CSRF requirements.
|
||||
"""
|
||||
"""Exempts the view from CSRF requirements."""
|
||||
|
||||
@method_decorator(csrf_exempt)
|
||||
def dispatch(self, *args, **kwargs):
|
||||
return super(CsrfExemptMixin, self).dispatch(*args, **kwargs)
|
||||
"""Overwrites dispatch to be extempt from csrf checks."""
|
||||
return super().dispatch(*args, **kwargs)
|
||||
|
||||
|
||||
class WebhookView(CsrfExemptMixin, APIView):
|
||||
"""
|
||||
Endpoint for receiving webhooks.
|
||||
"""
|
||||
"""Endpoint for receiving webhooks."""
|
||||
authentication_classes = []
|
||||
permission_classes = []
|
||||
model_class = common.models.WebhookEndpoint
|
||||
run_async = False
|
||||
|
||||
def post(self, request, endpoint, *args, **kwargs):
|
||||
"""Process incomming webhook."""
|
||||
# get webhook definition
|
||||
self._get_webhook(endpoint, request, *args, **kwargs)
|
||||
|
||||
@@ -101,6 +97,10 @@ class WebhookView(CsrfExemptMixin, APIView):
|
||||
|
||||
|
||||
class SettingsList(generics.ListAPIView):
|
||||
"""Generic ListView for settings.
|
||||
|
||||
This is inheritted by all list views for settings.
|
||||
"""
|
||||
|
||||
filter_backends = [
|
||||
DjangoFilterBackend,
|
||||
@@ -120,24 +120,17 @@ class SettingsList(generics.ListAPIView):
|
||||
|
||||
|
||||
class GlobalSettingsList(SettingsList):
|
||||
"""
|
||||
API endpoint for accessing a list of global settings objects
|
||||
"""
|
||||
"""API endpoint for accessing a list of global settings objects."""
|
||||
|
||||
queryset = common.models.InvenTreeSetting.objects.all()
|
||||
serializer_class = common.serializers.GlobalSettingsSerializer
|
||||
|
||||
|
||||
class GlobalSettingsPermissions(permissions.BasePermission):
|
||||
"""
|
||||
Special permission class to determine if the user is "staff"
|
||||
"""
|
||||
"""Special permission class to determine if the user is "staff"."""
|
||||
|
||||
def has_permission(self, request, view):
|
||||
"""
|
||||
Check that the requesting user is 'admin'
|
||||
"""
|
||||
|
||||
"""Check that the requesting user is 'admin'."""
|
||||
try:
|
||||
user = request.user
|
||||
|
||||
@@ -152,8 +145,7 @@ class GlobalSettingsPermissions(permissions.BasePermission):
|
||||
|
||||
|
||||
class GlobalSettingsDetail(generics.RetrieveUpdateAPIView):
|
||||
"""
|
||||
Detail view for an individual "global setting" object.
|
||||
"""Detail view for an individual "global setting" object.
|
||||
|
||||
- User must have 'staff' status to view / edit
|
||||
"""
|
||||
@@ -163,10 +155,7 @@ class GlobalSettingsDetail(generics.RetrieveUpdateAPIView):
|
||||
serializer_class = common.serializers.GlobalSettingsSerializer
|
||||
|
||||
def get_object(self):
|
||||
"""
|
||||
Attempt to find a global setting object with the provided key.
|
||||
"""
|
||||
|
||||
"""Attempt to find a global setting object with the provided key."""
|
||||
key = self.kwargs['key']
|
||||
|
||||
if key not in common.models.InvenTreeSetting.SETTINGS.keys():
|
||||
@@ -181,18 +170,13 @@ class GlobalSettingsDetail(generics.RetrieveUpdateAPIView):
|
||||
|
||||
|
||||
class UserSettingsList(SettingsList):
|
||||
"""
|
||||
API endpoint for accessing a list of user settings objects
|
||||
"""
|
||||
"""API endpoint for accessing a list of user settings objects."""
|
||||
|
||||
queryset = common.models.InvenTreeUserSetting.objects.all()
|
||||
serializer_class = common.serializers.UserSettingsSerializer
|
||||
|
||||
def filter_queryset(self, queryset):
|
||||
"""
|
||||
Only list settings which apply to the current user
|
||||
"""
|
||||
|
||||
"""Only list settings which apply to the current user."""
|
||||
try:
|
||||
user = self.request.user
|
||||
except AttributeError: # pragma: no cover
|
||||
@@ -206,12 +190,10 @@ class UserSettingsList(SettingsList):
|
||||
|
||||
|
||||
class UserSettingsPermissions(permissions.BasePermission):
|
||||
"""
|
||||
Special permission class to determine if the user can view / edit a particular setting
|
||||
"""
|
||||
"""Special permission class to determine if the user can view / edit a particular setting."""
|
||||
|
||||
def has_object_permission(self, request, view, obj):
|
||||
|
||||
"""Check if the user that requested is also the object owner."""
|
||||
try:
|
||||
user = request.user
|
||||
except AttributeError: # pragma: no cover
|
||||
@@ -221,8 +203,7 @@ class UserSettingsPermissions(permissions.BasePermission):
|
||||
|
||||
|
||||
class UserSettingsDetail(generics.RetrieveUpdateAPIView):
|
||||
"""
|
||||
Detail view for an individual "user setting" object
|
||||
"""Detail view for an individual "user setting" object.
|
||||
|
||||
- User can only view / edit settings their own settings objects
|
||||
"""
|
||||
@@ -232,10 +213,7 @@ class UserSettingsDetail(generics.RetrieveUpdateAPIView):
|
||||
serializer_class = common.serializers.UserSettingsSerializer
|
||||
|
||||
def get_object(self):
|
||||
"""
|
||||
Attempt to find a user setting object with the provided key.
|
||||
"""
|
||||
|
||||
"""Attempt to find a user setting object with the provided key."""
|
||||
key = self.kwargs['key']
|
||||
|
||||
if key not in common.models.InvenTreeUserSetting.SETTINGS.keys():
|
||||
@@ -249,18 +227,13 @@ class UserSettingsDetail(generics.RetrieveUpdateAPIView):
|
||||
|
||||
|
||||
class NotificationUserSettingsList(SettingsList):
|
||||
"""
|
||||
API endpoint for accessing a list of notification user settings objects
|
||||
"""
|
||||
"""API endpoint for accessing a list of notification user settings objects."""
|
||||
|
||||
queryset = NotificationUserSetting.objects.all()
|
||||
serializer_class = NotificationUserSettingSerializer
|
||||
|
||||
def filter_queryset(self, queryset):
|
||||
"""
|
||||
Only list settings which apply to the current user
|
||||
"""
|
||||
|
||||
"""Only list settings which apply to the current user."""
|
||||
try:
|
||||
user = self.request.user
|
||||
except AttributeError:
|
||||
@@ -272,8 +245,7 @@ class NotificationUserSettingsList(SettingsList):
|
||||
|
||||
|
||||
class NotificationUserSettingsDetail(generics.RetrieveUpdateAPIView):
|
||||
"""
|
||||
Detail view for an individual "notification user setting" object
|
||||
"""Detail view for an individual "notification user setting" object.
|
||||
|
||||
- User can only view / edit settings their own settings objects
|
||||
"""
|
||||
@@ -287,6 +259,8 @@ class NotificationUserSettingsDetail(generics.RetrieveUpdateAPIView):
|
||||
|
||||
|
||||
class NotificationList(generics.ListAPIView):
|
||||
"""List view for all notifications of the current user."""
|
||||
|
||||
queryset = common.models.NotificationMessage.objects.all()
|
||||
serializer_class = common.serializers.NotificationMessageSerializer
|
||||
|
||||
@@ -313,10 +287,7 @@ class NotificationList(generics.ListAPIView):
|
||||
]
|
||||
|
||||
def filter_queryset(self, queryset):
|
||||
"""
|
||||
Only list notifications which apply to the current user
|
||||
"""
|
||||
|
||||
"""Only list notifications which apply to the current user."""
|
||||
try:
|
||||
user = self.request.user
|
||||
except AttributeError:
|
||||
@@ -328,8 +299,7 @@ class NotificationList(generics.ListAPIView):
|
||||
|
||||
|
||||
class NotificationDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
"""
|
||||
Detail view for an individual notification object
|
||||
"""Detail view for an individual notification object.
|
||||
|
||||
- User can only view / delete their own notification objects
|
||||
"""
|
||||
@@ -342,9 +312,7 @@ class NotificationDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
|
||||
|
||||
class NotificationReadEdit(generics.CreateAPIView):
|
||||
"""
|
||||
general API endpoint to manipulate read state of a notification
|
||||
"""
|
||||
"""General API endpoint to manipulate read state of a notification."""
|
||||
|
||||
queryset = common.models.NotificationMessage.objects.all()
|
||||
serializer_class = common.serializers.NotificationReadSerializer
|
||||
@@ -354,12 +322,14 @@ class NotificationReadEdit(generics.CreateAPIView):
|
||||
]
|
||||
|
||||
def get_serializer_context(self):
|
||||
"""Add instance to context so it can be accessed in the serializer."""
|
||||
context = super().get_serializer_context()
|
||||
if self.request:
|
||||
context['instance'] = self.get_object()
|
||||
return context
|
||||
|
||||
def perform_create(self, serializer):
|
||||
"""Set the `read` status to the target value."""
|
||||
message = self.get_object()
|
||||
try:
|
||||
message.read = self.target
|
||||
@@ -369,23 +339,17 @@ class NotificationReadEdit(generics.CreateAPIView):
|
||||
|
||||
|
||||
class NotificationRead(NotificationReadEdit):
|
||||
"""
|
||||
API endpoint to mark a notification as read.
|
||||
"""
|
||||
"""API endpoint to mark a notification as read."""
|
||||
target = True
|
||||
|
||||
|
||||
class NotificationUnread(NotificationReadEdit):
|
||||
"""
|
||||
API endpoint to mark a notification as unread.
|
||||
"""
|
||||
"""API endpoint to mark a notification as unread."""
|
||||
target = False
|
||||
|
||||
|
||||
class NotificationReadAll(generics.RetrieveAPIView):
|
||||
"""
|
||||
API endpoint to mark all notifications as read.
|
||||
"""
|
||||
"""API endpoint to mark all notifications as read."""
|
||||
|
||||
queryset = common.models.NotificationMessage.objects.all()
|
||||
|
||||
@@ -394,6 +358,7 @@ class NotificationReadAll(generics.RetrieveAPIView):
|
||||
]
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""Set all messages for the current user as read."""
|
||||
try:
|
||||
self.queryset.filter(user=request.user, read=False).update(read=True)
|
||||
return Response({'status': 'ok'})
|
||||
|
||||
Reference in New Issue
Block a user