Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarcos committed Jun 8, 2018
2 parents 31cc9bb + 0e67305 commit 926aaa5
Show file tree
Hide file tree
Showing 56 changed files with 6,106 additions and 7,914 deletions.
22 changes: 21 additions & 1 deletion CHANGELOG.md
Expand Up @@ -8,6 +8,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Always reference the ticket number at the end of the issue description.


## 1.2.0

### Added

- added data attribute data-id in base_data_table row to easily distinct rows [#296][296]
- added collapsible and collapsible_gettext helper functions to help define
form layouts.
- added confirmation dialog support in Form actions [#294][294]
- added modal iFrame support in Lists (`tool_links`, `field_links`,
`action_links`) and Forms (`actions`) [#243][243]
- extended tutorial documentation of Forms.

## Changed

- changed format of list items, simplified and moved to dict-like structure

[296]: //github.com/sanoma/django-arctic/issues/296
[294]: //github.com/sanoma/django-arctic/issues/294
[243]: //github.com/sanoma/django-arctic/issues/243


## 1.1.1

### Changed
Expand Down Expand Up @@ -68,7 +89,6 @@ Always reference the ticket number at the end of the issue description.
## 1.0.1 (2017-03-01)

### Fixed

- Search form JS submitting selector - [#248][248]
- Float Label styling for a number of HTML5 inputs - [#247][247]
- confirm_links feature in ListViews now works properly - [#54][54].
Expand Down
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at opensource@sanoma.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
156 changes: 61 additions & 95 deletions arctic/generics.py
Expand Up @@ -24,11 +24,21 @@
from django.utils.translation import get_language
from django.views import generic as base

from .mixins import (FormMediaMixin, FormMixin, LinksMixin, ListMixin,
from .mixins import (FormMediaMixin, FormMixin, ListMixin,
RoleAuthentication, SuccessMessageMixin)
from .paginator import IndefinitePaginator
from .utils import (arctic_setting, find_attribute, get_field_class,
find_field_meta, get_attribute, menu, view_from_url)
from .utils import (append_query_parameter, arctic_setting, find_attribute,
get_field_class, find_field_meta, menu, reverse_url,
view_from_url)


def collapsible(fiedset_name, collapsed=False):
""" Utility method for Form layouts """
return '{}{}'.format('-' if collapsed else '+', fiedset_name)


def collapsible_gettext(fiedset_name, collapsed=False):
return collapsible(_(fiedset_name), collapsed)


class View(RoleAuthentication, base.View):
Expand Down Expand Up @@ -73,7 +83,6 @@ def get_context_data(self, **kwargs):
context['page_title'] = self.get_page_title()
context['page_description'] = self.get_page_description()
context['menu'] = menu(user=self.request.user, request=self.request)
context['urls'] = self.get_urls()
context['breadcrumbs'] = self.get_breadcrumbs()
context['tabs'] = self.get_tabs()
context['index_url'] = self.get_index_url()
Expand All @@ -92,24 +101,6 @@ def get_context_data(self, **kwargs):
context['form_display'] = self.get_form_display()
return context

def get_urls(self):
"""
Used for resolving urls when displaying nested objects, see arctic_url.
For example, generally you just have /foo/create as
a url, but with nested, you may have: /foo/<id>/bar/create/ and <id>
would be a parent id. These are then required to resolve urls.
@returns
{named_url, (url_param, url_param),}
|| {named_url, [url_param, url_param],}
if you provide a list and in this list there are strings, it will try
to get field of that item. This is especially useful for listviews with
action_links and field_links.
"""
return self.urls

def get_breadcrumbs(self):
"""
Breadcrumb format: (('name', 'url'), ...) or None if not used.
Expand All @@ -126,7 +117,8 @@ def get_breadcrumbs(self):
breadcrumb[1]).has_permission(self.request.user):
continue

allowed_breadcrumbs.append(breadcrumb)
url = None if not breadcrumb[1] else reverse(breadcrumb[1])
allowed_breadcrumbs.append({'name': breadcrumb[0], 'url': url})
return allowed_breadcrumbs

def get_tabs(self):
Expand All @@ -143,7 +135,11 @@ def get_tabs(self):
if not view_from_url(tab[1]).has_permission(self.request.user):
continue

allowed_tabs.append(tab)
obj = self if not hasattr(self, 'object') else self.object
url = reverse_url(tab[1], obj)
allowed_tabs.append({'name': tab[0],
'active': self.request.path == url,
'url': self.in_modal(url)})
return allowed_tabs

def get_page_title(self):
Expand Down Expand Up @@ -263,12 +259,17 @@ def get_form_display(self):
valid_options))
return arctic_setting('ARCTIC_FORM_DISPLAY', valid_options)

def in_modal(self, url):
if self.request.GET.get('inmodal'):
return append_query_parameter(url, {'inmodal': 'True'})
return url


class TemplateView(View, base.TemplateView):
pass


class DetailView(View, LinksMixin, base.DetailView):
class DetailView(View, base.DetailView):
"""
Custom detail view.
"""
Expand Down Expand Up @@ -353,27 +354,8 @@ def get_object_list(self):
qs = qs.filter(form.get_search_filter())

self.object_list = qs

return self.object_list

def _reverse_field_link(self, url, obj):
if type(url) in (list, tuple):
named_url = url[0]
args = []
for arg in url[1:]:
args.append(find_attribute(obj, arg))
else:
named_url = url
args = [get_attribute(obj, self.primary_key)]

# Instead of giving NoReverseMatch exception
# its more desirable, for field_links in listviews
# to just ignore the link.
if None in args:
return ''

return reverse(named_url, args=args)

def get_list_header(self):
"""
Creates a list of dictionaries with the field names, labels,
Expand Down Expand Up @@ -422,8 +404,6 @@ def get_list_header(self):
return result

def get_list_items(self, objects): # noqa: C901
self.has_action_links = False
has_modal_links = hasattr(self, 'modal_links')
items = []
if not self.get_fields():
for obj in objects:
Expand All @@ -437,7 +417,12 @@ def get_list_items(self, objects): # noqa: C901

for obj in objects:
field_classes = self.get_field_classes(obj)
row = []
row = {
'id': getattr(obj, self.primary_key), # for row data id attr
'fields': [],
'actions': [],
'sorting_field': None
}

for field_name in fields:
field = {'type': 'field', 'field': field_name}
Expand All @@ -456,31 +441,26 @@ def get_list_items(self, objects): # noqa: C901
embeded_list = embeded_list[:-1] + ['...']
field['value'] = embeded_list
if field_name in field_links.keys():
field['url'] = self._reverse_field_link(
field_links[field_name], obj)
self.add_confirm_link(has_modal_links, field,
field_links[field_name])
field['confirm'] = self.get_confirm_link(
field['url'] = self.in_modal(reverse_url(
field_links[field_name], obj, self.primary_key))
field['modal'] = self.get_modal_link(
field_links[field_name], obj)
if field_name in field_classes:
field['class'] = field_classes[field_name]
row.append(field)
row['fields'].append(field)

actions = self._get_field_actions(obj)
if actions:
row.append(actions)
self.has_action_links = True
row['actions'].extend(actions)
if self.sorting_field:
sort = {'type': 'sorting',
'id': getattr(obj, self.primary_key),
'value': getattr(obj, self.sorting_field)}
row.insert(0, sort)
row['sorting_field'] = {
'type': 'sorting',
'id': getattr(obj, self.primary_key),
'value': getattr(obj, self.sorting_field)
}
items.append(row)
return items

def add_confirm_link(self, has_confirm_link, field, field_url_name):
if has_confirm_link and field_url_name in self.modal_links:
field['confirm'] = self.modal_links[field_url_name]

def get_field_value(self, field_name, obj):
# first try to find a virtual field
virtual_field_name = "get_{}_field".format(field_name)
Expand Down Expand Up @@ -530,8 +510,6 @@ def get_context_data(self, **kwargs):
context['list_header'] = self.get_list_header()
context['list_items'] = self.get_list_items(context['object_list'])
context['tool_links'] = self.get_tool_links()
# self.has_action_links is set in get_list_items
context['has_action_links'] = self.has_action_links
context['sorting_url'] = self.sorting_url
context['tool_links_icon'] = self.get_tool_links_icon()
context['tool_links_collapse'] = self.tool_links_collapse - \
Expand Down Expand Up @@ -580,8 +558,6 @@ def get_context_data(self, **kwargs):
context['list_header'] = self.get_list_header()
context['list_items'] = self.get_list_items(object_list)
context['tool_links'] = self.get_tool_links()
# self.has_action_links is set in get_list_items
context['has_action_links'] = self.has_action_links
context['tool_links_icon'] = self.get_tool_links_icon()
context['tool_links_collapse'] = self.tool_links_collapse - \
int(len(context['tool_links']) == self.tool_links_collapse + 1)
Expand Down Expand Up @@ -634,7 +610,6 @@ def get_objects(self):
return objects

def get_list_items(self, objects):
self.has_action_links = False
items = []
fields = []
field_links = self.get_field_links()
Expand All @@ -643,21 +618,24 @@ def get_list_items(self, objects):
else field)
for obj in objects:
field_classes = self.get_field_classes(obj)
row = []
row = {
'id': getattr(obj, 'id', ''),
'fields': [],
'actions': []
}
for field_name in fields:
field = {'field': field_name, 'type': 'field'}
field['value'] = self.get_field_value(field_name, obj)
if field_name in field_links.keys():
field['url'] = self._reverse_field_link(
field_links[field_name], obj, self.primary_key)
field['url'] = reverse_url(field_links[field_name], obj,
self.primary_key)
if field_name in field_classes:
field['class'] = field_classes[field_name]
row.append(field)
row['fields'].append(field)
items.append(row)
actions = self._get_field_actions(obj)
if actions:
row.append(actions)
self.has_action_links = True
row['actions'].append(actions)
return items

def get_field_value(self, field_name, obj):
Expand Down Expand Up @@ -698,24 +676,6 @@ def paginate_dataset(self, dataset, page_size):
'message': str(e)
})

def _reverse_field_link(self, url, obj):
if type(url) in (list, tuple):
named_url = url[0]
args = []
for arg in url[1:]:
args.append(obj[arg])
else:
named_url = url
args = [obj[self.primary_key]]

# Instead of giving NoReverseMatch exception
# its more desirable, for field_links in listviews
# to just ignore the link.
if None in args:
return ''

return reverse(named_url, args=args)


class CreateView(FormMediaMixin, View, SuccessMessageMixin,
FormMixin, extra_views.CreateWithInlinesView):
Expand All @@ -736,7 +696,7 @@ def get_context_data(self, **kwargs):


class UpdateView(FormMediaMixin, SuccessMessageMixin, FormMixin, View,
LinksMixin, extra_views.UpdateWithInlinesView):
extra_views.UpdateWithInlinesView):
template_name = 'arctic/base_create_update.html'
success_message = _('"%(object)s" was successfully updated')

Expand Down Expand Up @@ -781,6 +741,13 @@ def confirm_dialog():
'cancel': _('Cancel'),
}

def get_success_url(self):
if self.success_url:
return self.success_url
if self.request.GET.get('inmodal'):
return reverse('arctic:redirect_to_parent')
return self.request.META.get('HTTP_REFERER')

def get_success_message(self, obj):
return _('"{}" was successfully deleted.').format(str(obj))

Expand All @@ -804,8 +771,7 @@ def get(self, request, *args, **kwargs):
if can_delete and self.redirect:
messages.success(request, self.get_success_message(self.object))
self.delete(request, *args, **kwargs)
return redirect(self.request.META.get('HTTP_REFERER',
self.get_success_url()))
return redirect(self.get_success_url())

context = self.get_context_data(object=self.object,
can_delete=can_delete,
Expand Down

0 comments on commit 926aaa5

Please sign in to comment.