Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxMaSk committed Nov 11, 2017
1 parent 34d58c7 commit dc6c866
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 34 deletions.
31 changes: 2 additions & 29 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{py,rst,ini}]
indent_style = space
indent_size = 4

[*.py]
line_length=120
known_first_party=django_th
multi_line_output=3
default_section=THIRDPARTY

[*.{html,css,scss,json,yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab

[nginx.conf]
indent_style = space
indent_size = 2

[Dockerfile]
indent_size = 4
20 changes: 19 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.log
*.pot
*.pyc
local_settings.py
run.sh
*.sqlite3*
Expand All @@ -21,3 +20,22 @@ th_tox
django_th/.env
docs/_build
htmlcov

.DS_Store
node_modules/
webpack-stats.json
dist/
public/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
test/unit/coverage
test/e2e/reports
selenium-debug.log

# Editor directories and files
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
Empty file added django_th/api/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions django_th/api/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework import permissions


class DjangoModelPermissions(permissions.BasePermission):

perms_map = {
'GET': [],
'OPTIONS': [],
'HEAD': [],
'POST': ['orotangi.add_books', 'orotangi.add_notes'],
'PUT': ['orotangi.change_books', 'orotangi.change_notes'],
'PATCH': ['orotangi.change_books', 'orotangi.change_notes'],
'DELETE': ['orotangi.delete_books', 'orotangi.delete_notes'],
}
31 changes: 31 additions & 0 deletions django_th/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django_th.models import TriggerService, UserService
from rest_framework import serializers
from django.contrib.auth.models import User


class UserSerializer(serializers.ModelSerializer):

class Meta:
model = User
fields = '__all__'


class UserServiceSerializer(serializers.ModelSerializer):

class Meta:
model = UserService
fields = '__all__'


class UserServiceDurationSerializer(serializers.ModelSerializer):

class Meta:
model = UserService
fields = ('duration', )


class TriggerServiceSerializer(serializers.ModelSerializer):

class Meta:
model = TriggerService
fields = '__all__'
15 changes: 15 additions & 0 deletions django_th/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.conf.urls import url, include

from django_th.api.views import TriggerServiceViewSet, UserServiceViewSet
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register(r'triggers', TriggerServiceViewSet)
router.register(r'services', UserServiceViewSet)


urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls',
namespace='rest_framework'))
]
83 changes: 83 additions & 0 deletions django_th/api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from django_filters.rest_framework import DjangoFilterBackend

from django_th.api.serializers import TriggerServiceSerializer, UserServiceSerializer, UserServiceDurationSerializer
from django_th.api.permissions import DjangoModelPermissions
from django_th.models import TriggerService, UserService

from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination


class TriggerServiceResultsSetPagination(PageNumberPagination):
page_size = 20
max_page_size = 50


class UserServiceResultsSetPagination(PageNumberPagination):
page_size = 20
max_page_size = 50


class UserMixin(viewsets.GenericViewSet):

def get_queryset(self):
"""
get the data of the current user
:return:
"""
qs = super(UserMixin, self).get_queryset()
return qs.filter(user=self.request.user)


class TriggerServiceViewSet(UserMixin, viewsets.ModelViewSet):
"""
This viewset provides `list`, `create`, `retrieve`, `update`
and `destroy` actions.
"""
queryset = TriggerService.objects.all()
serializer_class = TriggerServiceSerializer
pagination_class = TriggerServiceResultsSetPagination
# filter the notes
filter_backends = (DjangoFilterBackend,)
permission_classes = (DjangoModelPermissions, )

def get_queryset(self):
queryset = TriggerService.objects.all()

return queryset


class UserServiceViewSet(UserMixin, viewsets.ModelViewSet):
"""
This viewset provides `list`, `create`, `retrieve`, `update`
and `destroy` actions.
"""
queryset = UserService.objects.all()
serializer_class = UserServiceSerializer
pagination_class = UserServiceResultsSetPagination
# filter the notes
filter_backends = (DjangoFilterBackend,)
permission_classes = (DjangoModelPermissions, )

def get_queryset(self):
queryset = UserService.objects.all()

return queryset


class UserServiceDurationViewSet(UserMixin, viewsets.ModelViewSet):
"""
This viewset provides `list`, `create`, `retrieve`, `update`
and `destroy` actions.
"""
queryset = UserService.objects.all()
serializer_class = UserServiceDurationSerializer
pagination_class = UserServiceResultsSetPagination
# filter the notes
filter_backends = (DjangoFilterBackend,)
permission_classes = (DjangoModelPermissions, )

def get_queryset(self):
queryset = UserService.objects.all()

return queryset
65 changes: 62 additions & 3 deletions django_th/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
Expand All @@ -71,7 +71,23 @@
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(BASE_DIR, 'dist'),
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'public')

WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': '',
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
}
}
if not DEBUG:
WEBPACK_LOADER['DEFAULT'].update({
'BUNDLE_DIR_NAME': 'dist/',
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats-prod.json')
})


# List of finder classes that know how to find static files in
# various locations.
Expand All @@ -84,9 +100,9 @@
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
Expand Down Expand Up @@ -134,6 +150,8 @@
'th_tumblr',
'th_twitter',
'th_wallabag',
'corsheaders',
'webpack_loader',

)

Expand Down Expand Up @@ -259,7 +277,48 @@

TEST_RUNNER = 'django_th.runner.DiscoverRunnerTriggerHappy'
# Unit Test are buggy for this app ; so do not make them
TEST_RUNNER_WHITELIST = ('oauth2_provider', 'corsheaders')
TEST_RUNNER_WHITELIST = ('oauth2_provider', 'corsheaders', 'webpack_loader')

#########################
# Rest Framework Settings
#########################
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
'rest_framework.permissions.DjangoModelPermissions'
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication'
),
'TEST_REQUEST_DEFAULT_FORMAT': 'json'
}

#########################
# CORS settings
#########################
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_HEADERS = (
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
'access-control-allow-headers',
'access-control-allow-origin ',
'cookiename',
)

CORS_ORIGIN_WHITELIST = (
'localhost:8001',
'localhost:8000',
'127.0.0.1:8001',
'127.0.0.1:8000',
)

# local settings management
try:
Expand Down
2 changes: 2 additions & 0 deletions django_th/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% load staticfiles %}
{% load i18n %}
{% load django_th_extras %}
{% load render_bundle from webpack_loader %}
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Expand All @@ -22,6 +23,7 @@
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js" integrity="sha384-0s5Pv64cNZJieYFkXYOTId2HMA2Lfb6q2nAcx2n0RTLUnCAoTTsS0nKEO27XyKcY" crossorigin="anonymous"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js" integrity="sha384-ZoaMbDF+4LeFxg6WdScQ9nnR1QC2MIRxA1O9KWEXQwns1G8UNyIEZIQidzb0T1fo" crossorigin="anonymous"></script>
<![endif]-->
{% render_bundle 'app' %}
</head>
<body role="document">
{% block navbar %}
Expand Down
5 changes: 4 additions & 1 deletion django_th/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.conf.urls import include, url
from django.conf import settings
from django.urls import path
from django.views.generic import TemplateView
from django_th.forms.wizard import DummyForm, ProviderForm
from django_th.forms.wizard import ConsumerForm, ServicesDescriptionForm

Expand All @@ -27,6 +28,7 @@
admin.autodiscover()

urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='spa.html'), name='home'),
# url(r'^jsreverse/$', urls_js, name='js_reverse'),
# ****************************************
# admin module
Expand Down Expand Up @@ -99,7 +101,8 @@
path("th/callbackmastodon/$", finalcallback, {'service_name': 'ServiceMastodon', }, name="mastodon_callback",),
url(r'^th/myfeeds/', include(('th_rss.urls', 'th_rss'), namespace='th-rss')),
url(r'^th/api/taiga/webhook/', include(('th_taiga.urls', "th_taiga"), namespace='th-taiga')),
url(r'^th/api/slack/webhook/', include(('th_slack.urls', "th_slack"), namespace='th-slack'))
url(r'^th/api/slack/webhook/', include(('th_slack.urls', "th_slack"), namespace='th-slack')),
url(r'^th/api/v1/', include(('django_th.api.urls', "django_th"), namespace='th-api'))
]

if settings.DJANGO_TH.get('fire'):
Expand Down

0 comments on commit dc6c866

Please sign in to comment.