Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Conflicts:
	setup.py
  • Loading branch information
f1nality committed Aug 30, 2015
2 parents 846d9f5 + 864c3f5 commit 773f3d3
Show file tree
Hide file tree
Showing 23 changed files with 589 additions and 39 deletions.
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
language: python
python:
- 2.6
- 2.7
- 3.2
- 3.3
- 3.4
- pypy
env:
- DJANGO=1.6.11
- DJANGO=1.7.7
- DJANGO=1.8.3
before_install:
- export DJANGO_SETTINGS_MODULE=jet.tests.settings
install:
- if [[ $TRAVIS_PYTHON_VERSION == 2.6 ]]; then pip install importlib; fi
- pip install -q Django==$DJANGO --use-mirrors
- pip install . --use-mirrors
- pip install coveralls
script:
- coverage run --source=jet --omit=*/migrations/*,*/south_migrations/*,*/tests/* manage.py test jet
after_success:
- coverage report
- coveralls
matrix:
exclude:
- python: 2.6
env: DJANGO=1.6.11
- python: 2.6
env: DJANGO=1.7.7
- python: 2.6
env: DJANGO=1.8.3
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

0.0.6
-----

* [Feature] Added initial unit tests
* [Fixes] Compatibility fixes


0.0.5
-----

Expand Down
2 changes: 1 addition & 1 deletion jet/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '0.0.5'
VERSION = '0.0.6'
17 changes: 9 additions & 8 deletions jet/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from jet.models import UserDashboardModule
from django.core.context_processors import csrf
from django.utils.translation import ugettext_lazy as _
from jet.ordered_set import OrderedSet
from jet.utils import get_admin_site_name


Expand Down Expand Up @@ -111,23 +112,23 @@ def render_tools(self):
return render_to_string('jet/dashboard/dashboard_tools.html', context)

def media(self):
unique_css = {}
unique_js = {}
unique_css = OrderedSet()
unique_js = OrderedSet()

for js in getattr(self.Media, 'js', ()):
unique_js[js] = True
unique_js.add(js)
for css in getattr(self.Media, 'css', ()):
unique_css[css] = True
unique_css.add(css)

for module in self.modules:
for js in getattr(module.Media, 'js', ()):
unique_js[js] = True
unique_js.add(js)
for css in getattr(module.Media, 'css', ()):
unique_css[css] = True
unique_css.add(css)

class Media:
css = unique_css.keys()
js = unique_js.keys()
css = list(unique_css)
js = list(unique_js)

return Media

Expand Down
16 changes: 12 additions & 4 deletions jet/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class Meta:
model = Bookmark
fields = ['url', 'title']

def clean(self):
data = super(AddBookmarkForm, self).clean()
if not self.request.user.is_authenticated():
raise ValidationError('error')
if not self.request.user.has_perm('jet.change_bookmark'):
raise ValidationError('error')
return data

def save(self, commit=True):
self.instance.user = self.request.user.pk
return super(AddBookmarkForm, self).save(commit)
Expand All @@ -37,12 +45,12 @@ class Meta:
fields = []

def clean(self):
cleaned_data = super(RemoveBookmarkForm, self).clean()

data = super(RemoveBookmarkForm, self).clean()
if not self.request.user.is_authenticated():
raise ValidationError('error')
if self.instance.user != self.request.user.pk:
raise ValidationError('error')

return cleaned_data
return data

def save(self, commit=True):
if commit:
Expand Down
8 changes: 4 additions & 4 deletions jet/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ def init_with_context(self, context):

for app in app_list:
app['models'] = filter(
lambda model: self.models is None or model['object_name'] in self.models or app['app_label'] + '.*' in self.models,
lambda model: self.models is None or model['object_name'] in self.models or app.get('app_label', app.get('name')) + '.*' in self.models,
app['models']
)
app['models'] = filter(
lambda model: self.exclude is None or model['object_name'] not in self.exclude and app['app_label'] + '.*' not in self.exclude,
lambda model: self.exclude is None or model['object_name'] not in self.exclude and app.get('app_label', app.get('name')) + '.*' not in self.exclude,
app['models']
)
app['models'] = list(app['models'])
Expand Down Expand Up @@ -218,11 +218,11 @@ def init_with_context(self, context):

for app in app_list:
app['models'] = filter(
lambda model: self.models is None or model['object_name'] in self.models or app['app_label'] + '.*' in self.models,
lambda model: self.models is None or model['object_name'] in self.models or app.get('app_label', app.get('name')) + '.*' in self.models,
app['models']
)
app['models'] = filter(
lambda model: self.exclude is None or model['object_name'] not in self.exclude and app['app_label'] + '.*' not in self.exclude,
lambda model: self.exclude is None or model['object_name'] not in self.exclude and app.get('app_label', app.get('name')) + '.*' not in self.exclude,
app['models']
)
app['models'] = list(app['models'])
Expand Down
67 changes: 67 additions & 0 deletions jet/ordered_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import collections


class OrderedSet(collections.MutableSet):
def __init__(self, iterable=None):
self.end = end = []
end += [None, end, end] # sentinel node for doubly linked list
self.map = {} # key --> [key, prev, next]
if iterable is not None:
self |= iterable

def __len__(self):
return len(self.map)

def __contains__(self, key):
return key in self.map

def add(self, key):
if key not in self.map:
end = self.end
curr = end[1]
curr[2] = end[1] = self.map[key] = [key, curr, end]

def discard(self, key):
if key in self.map:
key, prev, next = self.map.pop(key)
prev[2] = next
next[1] = prev

def __iter__(self):
end = self.end
curr = end[2]
while curr is not end:
yield curr[0]
curr = curr[2]

def __reversed__(self):
end = self.end
curr = end[1]
while curr is not end:
yield curr[0]
curr = curr[1]

def pop(self, last=True):
if not self:
raise KeyError('set is empty')
key = self.end[1][0] if last else self.end[2][0]
self.discard(key)
return key

def __repr__(self):
if not self:
return '%s()' % (self.__class__.__name__,)
return '%s(%r)' % (self.__class__.__name__, list(self))

def __eq__(self, other):
if isinstance(other, OrderedSet):
return len(self) == len(other) and list(self) == list(other)
return set(self) == set(other)


if __name__ == '__main__':
s = OrderedSet('abracadaba')
t = OrderedSet('simsalabim')
print(s | t)
print(s & t)
print(s - t)
2 changes: 1 addition & 1 deletion jet/templates/admin/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{% block object-tools-items %}
<li>
{% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
<a href="{% add_preserved_filters history_url %}" class="historylink">{% trans "History" %}</a>
<a href="{% jet_add_preserved_filters history_url %}" class="historylink">{% trans "History" %}</a>
</li>
{% if has_absolute_url %}
<li><a href="{{ absolute_url }}" class="viewsitelink">{% trans "View on site" %}</a></li>
Expand Down
4 changes: 2 additions & 2 deletions jet/templates/admin/submit_line.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n admin_urls %}
{% load i18n admin_urls jet_tags %}

<div class="submit-row">
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save" />{% endif %}
Expand All @@ -8,6 +8,6 @@

{% if show_delete_link %}
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
<p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink button button-red">{% trans "Delete" %}</a></p>
<p class="deletelink-box"><a href="{% jet_add_preserved_filters delete_url %}" class="deletelink button button-red">{% trans "Delete" %}</a></p>
{% endif %}
</div>
20 changes: 10 additions & 10 deletions jet/templatetags/jet_tags.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from distutils.version import StrictVersion
from __future__ import unicode_literals
from django import template
import django
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.core.urlresolvers import reverse
from django.db.models import OneToOneField
from django.forms import CheckboxInput, ModelChoiceField, Select, ModelMultipleChoiceField, SelectMultiple
from django.utils.encoding import smart_text
from django.utils.formats import get_format
from django.template import loader, Context
from jet import settings
from jet.models import Bookmark, PinnedApplication
from django.utils.translation import ugettext_lazy as _
import re
from jet.utils import get_app_list, get_model_instance_label, get_current_dashboard

Expand Down Expand Up @@ -48,7 +44,7 @@ def render(self, context):

regex = re.compile('<[^!(a>)]([^>]|\n)*[^!(/a)]>', re.IGNORECASE)
clean = re.sub(regex, '', output)
clean = clean.replace(u'\u203A', '&rsaquo;')
clean = clean.replace('\u203A', '&rsaquo;')
items = clean.split('&rsaquo;')

items = map(lambda i: i.strip(), items)
Expand Down Expand Up @@ -150,7 +146,7 @@ def get_menu(context):
app['current'] = True
current_found = True

if app['app_label'] in pinned:
if app.get('app_label', app.get('name')) in pinned:
pinned_apps.append(app)
else:
apps.append(app)
Expand Down Expand Up @@ -213,9 +209,13 @@ def select2_lookups(field):
@register.simple_tag(takes_context=True)
def jet_add_preserved_filters(context, url, popup=False, to_field=None):
try:
return add_preserved_filters(context, url, popup, to_field)
except TypeError:
return add_preserved_filters(context, url, popup) # old django
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
try:
return add_preserved_filters(context, url, popup, to_field)
except TypeError:
return add_preserved_filters(context, url, popup) # old django
except ImportError:
return url


@register.assignment_tag(takes_context=True)
Expand Down
3 changes: 0 additions & 3 deletions jet/tests.py

This file was deleted.

3 changes: 3 additions & 0 deletions jet/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from jet.tests.test_dashboard import DashboardTestCase
from jet.tests.test_utils import UtilsTestCase
from jet.tests.test_views import ViewsTestCase
33 changes: 33 additions & 0 deletions jet/tests/dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from jet import modules
from jet.dashboard import Dashboard


class TestIndexDashboard(Dashboard):
columns = 3
init_with_context_called = False

class Media:
js = ('file.js', 'file2.js')
css = ('file.css', 'file2.css')

def init_with_context(self, context):
self.init_with_context_called = True
self.available_children.append(modules.LinkList)
self.available_children.append(modules.Feed)

# append a recent actions module
self.children.append(modules.RecentActions(
'Recent Actions',
10,
column=0,
order=1
))

# append a feed module
self.children.append(modules.Feed(
'Latest Django News',
feed_url='http://www.djangoproject.com/rss/weblog/',
limit=5,
column=1,
order=1
))
11 changes: 11 additions & 0 deletions jet/tests/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.db import models
from django.utils.encoding import python_2_unicode_compatible


@python_2_unicode_compatible
class TestModel(models.Model):
field1 = models.CharField(max_length=255)
field2 = models.IntegerField()

def __str__(self):
return '%s%d' % (self.field1, self.field2)
Loading

0 comments on commit 773f3d3

Please sign in to comment.