Skip to content

Commit

Permalink
some initial copied work
Browse files Browse the repository at this point in the history
  • Loading branch information
benzkji committed Mar 18, 2017
1 parent 9ce62e3 commit 38134b6
Show file tree
Hide file tree
Showing 33 changed files with 1,267 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .idea/django-separate-users.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

556 changes: 556 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

==== 0.xxx (not yet) ===

- fix for djangocms-admin-styles


==== 0.0.1 (not yet) ===

- support for django 1.9
- refactored tests, to use default manage.py test command

7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include LICENSES
include README.rst
global-exclude *.orig *.pyc *.log *.swp

recursive-include separate_users/templates *
recursive-include separate_users/static *
recursive-include separate_users/locale *
4 changes: 4 additions & 0 deletions compilemessages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

cd separate_users
django-admin.py compilemessages
cd ..
5 changes: 5 additions & 0 deletions makemessages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


cd separate_users
django-admin.py makemessages -l en
cd ..
11 changes: 11 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'separate_users.tests.settings_runtestapp')

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
12 changes: 12 additions & 0 deletions release.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


git flow release start 0.xxx
version bump in separate_users/__init__.py
git flow release finish 0.xxx
git push --all; git push --tags
python setup.py sdist
# no wheel for now?! python setup.py bdist_wheel --universal
python setup.py register -r pypitest
twine upload dist/* -r pypitest
python setup.py register -r pypi
twine upload dist/*
2 changes: 2 additions & 0 deletions separate_users/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version__ = '0.1.2'
__author__ = 'benzkji'
61 changes: 61 additions & 0 deletions separate_users/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from django.conf.urls import url
from django.contrib import admin
from django.db import models
from django.http import JsonResponse


class DjangoLinkAdmin(admin.ModelAdmin):

def get_model_perms(self, request):
"""
http://stackoverflow.com/questions/2431727/django-admin-hide-a-model
Return empty perms dict thus hiding the model from admin index.
"""
return {}

def get_urls(self):
"""
add verify url.
"""
my_urls = [
url(
r'^verify/$',
self.admin_site.admin_view(self.verify),
name=self._get_verify_url_name()
),
]
return my_urls + super(DjangoLinkAdmin, self).get_urls()

def _get_verify_url_name(self):
return '{0}_{1}_verify'.format(self.model._meta.app_label,
self.model._meta.model_name)

def verify(self, request):
"""
verify data with modelform, send through data.
:param request:
:return:
"""
form = self.get_form(request, )(request.POST)
if form.is_valid():
verified_data = form.cleaned_data
obj = self.model(**verified_data)
link_value = ''
# prepopulate href
if (getattr(obj, 'get_link', None)):
link_value = obj.get_link()
# basic serialize only
for key, value in verified_data.items():
if isinstance(value, models.Model):
verified_data[key] = value.id
return_data = {"valid": 'true', 'data': verified_data, 'link_value': link_value}
else:
errors = form.errors
return_data = {"valid": 'false', 'errors': errors}
return JsonResponse(return_data)

def save_model(self, request, obj, form, change):
"""
no save!
"""
return False
Empty file added separate_users/models.py
Empty file.
1 change: 1 addition & 0 deletions separate_users/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'benzkji'
13 changes: 13 additions & 0 deletions separate_users/tests/settings_runtestapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
These settings are used by the ``manage.py`` command.
"""

from .settings_test import * # NOQA


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite',
}
}
151 changes: 151 additions & 0 deletions separate_users/tests/settings_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"""Settings that need to be set in order to run the tests."""
import os
import sys
import tempfile
import logging

from django.core.urlresolvers import reverse_lazy


DEBUG = True

logging.getLogger("factory").setLevel(logging.WARN)

# from selenium.webdriver.firefox import webdriver
from selenium.webdriver.phantomjs import webdriver
SELENIUM_WEBDRIVER = webdriver


separate_users_MODEL = 'separate_users.tests.test_app.models.LinkModel'
separate_users_IFRAME_URL = reverse_lazy('admin:test_app_linkmodel_add')
separate_users_VERIFY_URL = reverse_lazy('admin:test_app_linkmodel_verify')

CKEDITOR_CONFIGS = {
'default': {
'djangolinkIframeURL': separate_users_IFRAME_URL,
'djangolinkVerifyURL': separate_users_VERIFY_URL,
'linkShowAdvancedTab': False,
'extraPlugins': ','.join(
[
# your extra plugins here
'djangolink',
'autolink',
'autoembed',
'embedsemantic',
'autogrow',
'devtools',
'widget',
'lineutils',
'clipboard',
'dialog',
'dialogui',
'elementspath'
]),
'toolbar': 'Custom',
'toolbar_Custom': [
['Bold', 'Underline'],
['DjangoLink', 'Unlink'],
['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
['Link', 'Unlink'],
['RemoveFormat', 'Source']
]
}
}

SITE_ID = 1

APP_ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), ".."))

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}

LANGUAGE_CODE = 'en'
LANGUAGES = (
('en', 'ENGLISHS' ),
)

ROOT_URLCONF = 'separate_users.tests.urls'

# media root is overridden when needed in tests
MEDIA_ROOT = tempfile.mkdtemp(suffix='ckeditor_media_root')
MEDIA_URL = "/media/"
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(APP_ROOT, '../test_app_static')
STATICFILES_DIRS = (
os.path.join(APP_ROOT, 'static'),
)

# TEMPLATE_DIRS = (
# os.path.join(APP_ROOT, 'tests/test_app/templates'),
# )

COVERAGE_REPORT_HTML_OUTPUT_DIR = os.path.join(
os.path.join(APP_ROOT, 'tests/coverage'))
COVERAGE_MODULE_EXCLUDES = [
'tests$', 'settings$', 'urls$', 'locale$',
'migrations', 'fixtures', 'admin$', 'django_extensions',
]

EXTERNAL_APPS = (
'django.contrib.admin',
# 'django.contrib.admindocs',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
'django.contrib.sites',
'ckeditor',
# 'djangocms_text_ckeditor',
# 'cms',
# 'treebeard',
# 'menus',
)

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.i18n',
'django.template.context_processors.request',
'django.template.context_processors.media',
'django.template.context_processors.static',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
],
}
},
]


INTERNAL_APPS = (
'separate_users',
'separate_users.tests.test_app',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.locale.LocaleMiddleware',
)

INSTALLED_APPS = EXTERNAL_APPS + INTERNAL_APPS
COVERAGE_MODULE_EXCLUDES += EXTERNAL_APPS

SECRET_KEY = 'foobarXXXxxsvXY'
Empty file.
18 changes: 18 additions & 0 deletions separate_users/tests/test_app/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django import forms
from django.contrib import admin
from django.forms.extras.widgets import SelectDateWidget

from separate_users.admin import DjangoLinkAdmin

from .models import TestModel, LinkModel


class LinkModelForm(forms.ModelForm):
when = forms.DateField(widget=SelectDateWidget, required=False)


class CKLinkModelAdmin(DjangoLinkAdmin):
form = LinkModelForm

admin.site.register(TestModel)
admin.site.register(LinkModel, CKLinkModelAdmin)
1 change: 1 addition & 0 deletions separate_users/tests/test_app/fixtures/test_app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"model": "test_app.testmodel", "pk": 1, "fields": {"title": "Test 2", "richtext": "<p>None</p>", "richtext_second": ""}}, {"model": "test_app.testmodel", "pk": 2, "fields": {"title": "Testing different Link Form Widgets", "richtext": "<p>One Two <a data-ckeditor-link=\"true\" data-email=\"\" data-external_url=\"\" data-target=\"_blank\" data-when=\"2018-02-03\" href=\"http://no-link-given.com/\">Link One (Date Link, haha)</a></p>\r\n\r\n<p><a data-ckeditor-link=\"true\" data-email=\"\" data-external_url=\"\" data-target=\"\" data-testmodel=\"1\" href=\"http://no-link-given.com/\">Link Two (Foreign Key)</a></p>\r\n\r\n<p>what</p>", "richtext_second": "<p><a data-ckeditor-link=\"true\" data-email=\"\" data-external_url=\"\" data-target=\"asdvads\" data-testmodel=\"2\" href=\"http://no-link-given.com/\">sdvasdva</a>&nbsp;<a data-ckeditor-link=\"true\" data-email=\"\" data-external_url=\"sadv\" data-target=\"sdvatest\" data-testmodel=\"1\" href=\"sadv\">link</a></p>"}}]
Loading

0 comments on commit 38134b6

Please sign in to comment.