Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • djangoldp-packages/djangoldp
  • decentral1se/djangoldp
  • femmefaytale/djangoldp
  • jvtrudel/djangoldp
4 results
Show changes
Showing
with 292 additions and 2 deletions
# {{ app_name }}
__version__ = '0.0.0'
from django.contrib import admin
from django.apps import AppConfig
class {{ camel_case_app_name }}Config(AppConfig):
name = '{{ app_name }}'
"""This module is loaded by DjangoLDP core during setup."""
# define an extra variable (should be prefix with package name)
MYPACKAGE_VAR = 'MY_DEFAULT_VAR'
# register an extra middleware
MIDDLEWARE = []
# register an extra installed app
INSTALLED_APPS = []
from django.urls import path
from .models import Dummy
from .views import DummyViewset
urlpatterns = [
path('dummy/', DummyViewset.urls(model_prefix="dummy", model=Dummy))
]
from django.db import models
from djangoldp.models import Model
class Dummy(Model):
name = models.CharField(max_length=255, blank=True)
class Meta(Model.Meta):
rdf_type = 'hd:dummy'
def __str__(self):
return self.name
from django.test import TestCase
# Create your tests here.
from djangoldp.views import LDPViewSet
from djangoldp.models import Model
from .models import Dummy
class DummyViewset(LDPViewSet):
pass
[metadata]
name = {{ app_name }}
version = attr: {{ app_name }}.__version__
description = {{ description }}
long_description = file: README.md
license = MIT
classifiers =
Programming Language :: Python :: 3
[options]
packages = find:
[semantic_release]
version_source = tag
version_variable = {{ app_name }}/__init__.py:__version__
commit_parser = commit_parser.parse
#!/usr/bin/env python
"""Setup script."""
from setuptools import setup
setup()
#!/usr/bin/env python
import os
import sys
from djangoldp.conf import ldpsettings
if __name__ == "__main__":
ldpsettings.configure('settings.yml')
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
"""{{ project_name }} URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.urls import include, path
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', include('djangoldp.urls')),
path('admin/', admin.site.urls),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
"""
WSGI config for SIB project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
from django.conf import settings as django_settings
from djangoldp.conf import ldpsettings
if not django_settings.configured:
ldpsettings.configure()
application = get_wsgi_application()
try:
from djangoldp.activities.services import ActivityQueueService
ActivityQueueService.start()
except:
pass
dependencies:
ldppackages:
server:
# DjangoLDP required settings
DEBUG: true
ALLOWED_HOSTS:
- '*'
SECRET_KEY: '{{secret_key}}'
DATABASES:
default:
ENGINE: django.db.backends.sqlite3
NAME: db.sqlite3
LDP_RDF_CONTEXT: https://cdn.startinblox.com/owl/context.jsonld
ROOT_URLCONF: server.urls
STATIC_ROOT: static
MEDIA_ROOT: media
import re
from importlib import import_module
from django.conf import settings
class WebFinger(object):
def uri(self, name, *args):
domain = settings.BASE_URL
return "{domain}{name}".format(domain=domain, name=name)
def response(self, response_dict, rel, acct):
return response_dict
for package in settings.DJANGOLDP_PACKAGES:
try:
import_module('{}.endpoints.webfinger'.format(package))
except ModuleNotFoundError:
pass
model_classes = {cls.__name__: cls for cls in WebFinger.__subclasses__()}
ACCT_RE = re.compile(
r'(?:acct:)?(?P<userinfo>[\w.!#$%&\'*+-/=?^_`{|}~]+)@(?P<host>[\w.:-]+)')
class Acct(object):
def __init__(self, acct):
m = ACCT_RE.match(acct)
if not m:
raise ValueError('invalid acct format')
(userinfo, host) = m.groups()
self.userinfo = userinfo
self.host = host
class WebFingerEndpoint(object):
"""
WebFinger endpoint
See https://tools.ietf.org/html/rfc7033
"""
def __init__(self, request):
self.request = request
self.params = {}
self.acct = None
self._extract_params()
def _extract_params(self):
# Because in this endpoint we handle both GET
# and POST request.
query_dict = (self.request.POST if self.request.method == 'POST'
else self.request.GET)
self.params['resource'] = query_dict.get('resource', None)
self.params['rel'] = query_dict.get('rel', None)
def validate_params(self):
"""
A resource must be set.
"""
if self.params['resource'] is None:
raise WebFingerError('invalid_request')
try:
self.acct = Acct(self.params['resource'])
except ValueError:
raise WebFingerError('invalid_acct_format')
def response(self):
"""
This endpoint only reply to rel="http://openid.net/specs/connect/1.0/issuer"
:return: a dict representing the Json response
"""
dict = {
'subject': self.params['resource'],
'aliases': [],
'links': []
}
for class_name in model_classes:
model_class = model_classes[class_name]
webfinger = model_class()
dict = webfinger.response(dict, self.params['rel'], self.acct)
return dict
class WebFingerError(Exception):
_errors = {
'invalid_request': "The request provider parameter must contains an url or an email",
'invalid_acct_format': "Invalid acct format"
}
def __init__(self, error=None, dict=None):
if dict is None:
self.error = error
self.description = self._errors.get(error)
else:
self.error = dict['error']
self.description = dict['error_description']
def create_dict(self):
dic = {
'error': self.error,
'error_description': self.description,
}
return dic
import factory
from django.contrib.auth.models import User
from django.conf import settings
from django.db.models.signals import post_save
@factory.django.mute_signals(post_save)
class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = User
model = settings.AUTH_USER_MODEL
username = factory.Faker('user_name')
first_name = factory.Faker('first_name')
......
import requests
from django.db import models
from rest_framework import fields
class IdURLField (fields.URLField):
def to_representation(self, value):
str = super(IdURLField, self).to_representation(value)
return {'@id': str}
def get(self, value):
url = super(IdURLField, self).to_representation(value)
datas = requests.get(url).json()
return datas
class LDPUrlField (models.URLField):
pass