Exemplo n.º 1
0
def get_version(version=None):
    "Return a PEP 386-compliant version number from VERSION."
    version = get_complete_version(version)

    # Now build the two parts of the version number:
    # main = X.Y[.Z]
    # sub = {a|b|rc}N - for alpha, beta and rc releases
    main = get_main_version(version)

    sub = ''
    if version[3] != 'final':
        mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'rc'}
        sub = mapping[version[3]] + str(version[4])

    return str(main + sub)
Exemplo n.º 2
0
def get_version(version=None):
    "Return a PEP 386-compliant version number from VERSION."
    version = get_complete_version(version)

    # Now build the two parts of the version number:
    # main = X.Y[.Z]
    # sub = {a|b|rc}N - for alpha, beta and rc releases
    main = get_main_version(version)

    sub = ""
    if version[3] != "final":
        mapping = {"alpha": "a", "beta": "b", "rc": "rc"}
        sub = mapping[version[3]] + str(version[4])

    return str(main + sub)
Exemplo n.º 3
0
 def history_view(self, request, object_id, extra_context=None):
     """The 'history' admin view for this model."""
     request.current_app = self.admin_site.name
     model = self.model
     opts = model._meta
     app_label = opts.app_label
     pk_name = opts.pk.attname
     history = getattr(model, model._meta.simple_history_manager_attribute)
     object_id = unquote(object_id)
     action_list = history.filter(**{pk_name: object_id})
     # If no history was found, see whether this object even exists.
     try:
         obj = model.objects.get(**{pk_name: object_id})
     except model.DoesNotExist:
         try:
             obj = action_list.latest('history_date').instance
         except action_list.model.DoesNotExist:
             raise http.Http404
     content_type = ContentType.objects.get_by_natural_key(
         *USER_NATURAL_KEY)
     admin_user_view = 'admin:%s_%s_change' % (content_type.app_label,
                                               content_type.model)
     context = {
         'title': _('Change history: %s') % force_text(obj),
         'action_list': action_list,
         'module_name': capfirst(force_text(opts.verbose_name_plural)),
         'object': obj,
         'root_path': getattr(self.admin_site, 'root_path', None),
         'app_label': app_label,
         'opts': opts,
         'admin_user_view': admin_user_view
     }
     context.update(extra_context or {})
     extra_kwargs = {}
     if get_complete_version() < (1, 8):
         extra_kwargs['current_app'] = request.current_app
     return render(request, self.object_history_template, context, **extra_kwargs)
Exemplo n.º 4
0
def status(request):
    template_data = {
        "Django_version": version.get_complete_version(),
        "Python_version": platform.python_version(),
    }
    return render(request, 'status.html', template_data)
Exemplo n.º 5
0
#
# Copyright (c) 2016 University of Dundee.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008.
#
# Version: 1.0

from django.apps import AppConfig
from django.utils.version import get_complete_version

if get_complete_version() < (1, 8):
    raise RuntimeError('MAPR requires Django 1.8+')


class MaprAppConfig(AppConfig):
    name = "omero_mapr"
    label = "mapr"
Exemplo n.º 6
0
    def history_form_view(self, request, object_id, version_id):
        request.current_app = self.admin_site.name
        original_opts = self.model._meta
        model = getattr(
            self.model,
            self.model._meta.simple_history_manager_attribute).model
        obj = get_object_or_404(model, **{
            original_opts.pk.attname: object_id,
            'history_id': version_id,
        }).instance
        obj._state.adding = False

        if not self.has_change_permission(request, obj):
            raise PermissionDenied

        if SIMPLE_HISTORY_EDIT:
            change_history = True
        else:
            change_history = False

        if '_change_history' in request.POST and SIMPLE_HISTORY_EDIT:
            obj = obj.history.get(pk=version_id).instance

        formsets = []
        form_class = self.get_form(request, obj)
        if request.method == 'POST':
            form = form_class(request.POST, request.FILES, instance=obj)
            if form.is_valid():
                new_object = self.save_form(request, form, change=True)
                self.save_model(request, new_object, form, change=True)
                form.save_m2m()

                self.log_change(request, new_object,
                                self.construct_change_message(
                                    request, form, formsets))
                return self.response_change(request, new_object)

        else:
            form = form_class(instance=obj)

        admin_form = helpers.AdminForm(
            form,
            self.get_fieldsets(request, obj),
            self.prepopulated_fields,
            self.get_readonly_fields(request, obj),
            model_admin=self,
        )

        model_name = original_opts.model_name
        url_triplet = self.admin_site.name, original_opts.app_label, model_name
        context = {
            'title': _('Revert %s') % force_text(obj),
            'adminform': admin_form,
            'object_id': object_id,
            'original': obj,
            'is_popup': False,
            'media': mark_safe(self.media + admin_form.media),
            'errors': helpers.AdminErrorList(form, formsets),
            'app_label': model._meta.app_label,
            'original_opts': original_opts,
            'changelist_url': reverse('%s:%s_%s_changelist' % url_triplet),
            'change_url': reverse('%s:%s_%s_change' % url_triplet,
                                  args=(obj.pk,)),
            'history_url': reverse('%s:%s_%s_history' % url_triplet,
                                   args=(obj.pk,)),
            'change_history': change_history,

            # Context variables copied from render_change_form
            'add': False,
            'change': True,
            'has_add_permission': self.has_add_permission(request),
            'has_change_permission': self.has_change_permission(request, obj),
            'has_delete_permission': self.has_delete_permission(request, obj),
            'has_file_field': True,
            'has_absolute_url': False,
            'form_url': '',
            'opts': model._meta,
            'content_type_id': ContentType.objects.get_for_model(
                self.model).id,
            'save_as': self.save_as,
            'save_on_top': self.save_on_top,
            'root_path': getattr(self.admin_site, 'root_path', None),
        }
        extra_kwargs = {}
        if get_complete_version() < (1, 8):
            extra_kwargs['current_app'] = request.current_app
        return render(request, self.object_history_form_template, context, **extra_kwargs)
Exemplo n.º 7
0
    PushSubscriptionView, mail_read_tracker, send_by_dbmail
)


dbmail_patterns = [
    url(r'^api/', send_by_dbmail, name='db-mail-api'),
    url(r'^mail_read_tracker/(.*?)/$',
        mail_read_tracker, name='db-mail-tracker'),

    url(r'^safari/v(?P<version>[0-9]{1})/pushPackages/(?P<site_pid>[.\w-]+)/?',
        SafariPushPackagesView.as_view()),
    url(r'^safari/v(?P<version>[0-9]{1})/devices/'
        r'(?P<device_token>[.\w-]+)/registrations/(?P<site_pid>[.\w-]+)/?',
        SafariSubscriptionView.as_view()),
    url(r'^safari/v(?P<version>[0-9]{1})/log/?', SafariLogView.as_view()),

    url(r'^(?P<reg_type>web-push|mobile)/subscribe/',
        PushSubscriptionView.as_view(), name='push-subscribe'),
    url(r'^(?P<reg_type>web-push|mobile)/unsubscribe/',
        PushSubscriptionView.as_view(), name='push-unsubscribe'),
]

if version.get_complete_version() >= (1,9):
    urlpatterns = dbmail_patterns
else:
    from django.conf.urls import patterns
    urlpatterns = patterns(
        '',
        *dbmail_patterns
    )
Exemplo n.º 8
0
    def history_form_view(self, request, object_id, version_id):
        request.current_app = self.admin_site.name
        original_opts = self.model._meta
        model = getattr(
            self.model,
            self.model._meta.simple_history_manager_attribute).model
        obj = get_object_or_404(model, **{
            original_opts.pk.attname: object_id,
            'history_id': version_id,
        }).instance
        obj._state.adding = False

        if not self.has_change_permission(request, obj):
            raise PermissionDenied

        if SIMPLE_HISTORY_EDIT:
            change_history = True
        else:
            change_history = False

        if '_change_history' in request.POST and SIMPLE_HISTORY_EDIT:
            obj = obj.history.get(pk=version_id).instance

        formsets = []
        form_class = self.get_form(request, obj)
        if request.method == 'POST':
            form = form_class(request.POST, request.FILES, instance=obj)
            if form.is_valid():
                new_object = self.save_form(request, form, change=True)
                self.save_model(request, new_object, form, change=True)
                form.save_m2m()

                self.log_change(request, new_object,
                                self.construct_change_message(
                                    request, form, formsets))
                return self.response_change(request, new_object)

        else:
            form = form_class(instance=obj)

        admin_form = helpers.AdminForm(
            form,
            self.get_fieldsets(request, obj),
            self.prepopulated_fields,
            self.get_readonly_fields(request, obj),
            model_admin=self,
        )

        model_name = original_opts.model_name
        url_triplet = self.admin_site.name, original_opts.app_label, model_name
        context = {
            'title': _('Revert %s') % force_text(obj),
            'adminform': admin_form,
            'object_id': object_id,
            'original': obj,
            'is_popup': False,
            'media': mark_safe(self.media + admin_form.media),
            'errors': helpers.AdminErrorList(form, formsets),
            'app_label': original_opts.app_label,
            'original_opts': original_opts,
            'changelist_url': reverse('%s:%s_%s_changelist' % url_triplet),
            'change_url': reverse('%s:%s_%s_change' % url_triplet,
                                  args=(obj.pk,)),
            'history_url': reverse('%s:%s_%s_history' % url_triplet,
                                   args=(obj.pk,)),
            'change_history': change_history,

            # Context variables copied from render_change_form
            'add': False,
            'change': True,
            'has_add_permission': self.has_add_permission(request),
            'has_change_permission': self.has_change_permission(request, obj),
            'has_delete_permission': self.has_delete_permission(request, obj),
            'has_file_field': True,
            'has_absolute_url': False,
            'form_url': '',
            'opts': model._meta,
            'content_type_id': ContentType.objects.get_for_model(
                self.model).id,
            'save_as': self.save_as,
            'save_on_top': self.save_on_top,
            'root_path': getattr(self.admin_site, 'root_path', None),
        }
        extra_kwargs = {}
        if get_complete_version() < (1, 8):
            extra_kwargs['current_app'] = request.current_app
        return render(request, self.object_history_form_template, context, **extra_kwargs)
Exemplo n.º 9
0
def status(request):
    template_data = {
        "Django_version": version.get_complete_version(),
        "Python_version": platform.python_version(),
    }
    return render(request, 'status.html', template_data)
Exemplo n.º 10
0
    def history_form_view(self, request, object_id, version_id):
        request.current_app = self.admin_site.name
        original_opts = self.model._meta
        model = getattr(
            self.model,
            self.model._meta.simple_history_manager_attribute).model
        historical_obj = get_object_or_404(
            model, **{
                original_opts.pk.attname: object_id,
                'history_id': version_id,
            })
        obj = historical_obj.instance
        obj._state.adding = False

        if not self.has_change_permission(request, obj):
            raise PermissionDenied

        if SIMPLE_HISTORY_EDIT:
            change_history = True
        else:
            change_history = False

        if '_change_history' in request.POST and SIMPLE_HISTORY_EDIT:
            obj = obj.history.get(pk=version_id).instance

        formsets = []
        form_class = self.get_form(request, obj)
        if request.method == 'POST':
            form = form_class(request.POST, request.FILES, instance=obj)
            if form.is_valid():
                new_object = self.save_form(request, form, change=True)
                self.save_model(request, new_object, form, change=True)
                form.save_m2m()

                self.log_change(
                    request, new_object,
                    self.construct_change_message(request, form, formsets))
                return self.response_change(request, new_object)

        else:
            form = form_class(instance=obj)

        admin_form = helpers.AdminForm(
            form,
            self.get_fieldsets(request, obj),
            self.prepopulated_fields,
            self.get_readonly_fields(request, obj),
            model_admin=self,
        )

        model_name = original_opts.model_name
        url_triplet = self.admin_site.name, original_opts.app_label, model_name

        inline_instances = self.get_inline_instances(request, obj)
        prefixes = {}
        formset = []

        historical_date = historical_obj.history_date
        adjusted_historical_date = historical_date + datetime.timedelta(
            seconds=5)
        for FormSet, inline in self.get_admin_formsets_with_inline(*[request]):
            prefix = FormSet.get_default_prefix()
            prefixes[prefix] = prefixes.get(prefix, 0) + 1
            if prefixes[prefix] != 1 or not prefix:
                prefix = "%s-%s" % (prefix, prefixes[prefix])

            inline_qs = inline.get_queryset(request)
            inline_ids = inline_qs.values_list('id', flat=True)
            history_inline_model = inline_qs.first().history.model
            historical_ids = history_inline_model.objects\
                                    .filter(id__in=inline_ids, history_date__lte=adjusted_historical_date)\
                                    .order_by('-history_date')[:inline_qs.count()]\
                                    .values_list('history_id', flat=True)
            historical_queryset = history_inline_model.objects.filter(
                history_id__in=historical_ids)

            formset_params = {
                'instance': obj,
                'prefix': prefix,
                'queryset': historical_queryset,
            }
            if request.method == 'POST':
                formset_params.update({
                    'data':
                    request.POST.copy(),
                    'files':
                    request.FILES,
                    'save_as_new':
                    '_saveasnew' in request.POST
                })
            formset.append(FormSet(**formset_params))

        inline_formsets = self.get_admin_inline_formsets(
            request, formset, inline_instances, obj)
        context = {
            'title':
            _('Revert %s') % force_text(obj),
            'adminform':
            admin_form,
            'object_id':
            object_id,
            'original':
            obj,
            'is_popup':
            False,
            'media':
            mark_safe(self.media + admin_form.media),
            'errors':
            helpers.AdminErrorList(form, formsets),
            'app_label':
            original_opts.app_label,
            'original_opts':
            original_opts,
            'changelist_url':
            reverse('%s:%s_%s_changelist' % url_triplet),
            'change_url':
            reverse('%s:%s_%s_change' % url_triplet, args=(obj.pk, )),
            'history_url':
            reverse('%s:%s_%s_history' % url_triplet, args=(obj.pk, )),
            'change_history':
            change_history,
            'inline_admin_formsets':
            inline_formsets,
            # Context variables copied from render_change_form
            'add':
            False,
            'change':
            True,
            'has_add_permission':
            self.has_add_permission(request),
            'has_change_permission':
            self.has_change_permission(request, obj),
            'has_delete_permission':
            self.has_delete_permission(request, obj),
            'has_file_field':
            True,
            'has_absolute_url':
            False,
            'form_url':
            '',
            'opts':
            model._meta,
            'content_type_id':
            ContentType.objects.get_for_model(self.model).id,
            'save_as':
            self.save_as,
            'save_on_top':
            self.save_on_top,
            'root_path':
            getattr(self.admin_site, 'root_path', None),
        }
        extra_kwargs = {}
        if get_complete_version() < (1, 8):
            extra_kwargs['current_app'] = request.current_app
        return render(request, self.object_history_form_template, context,
                      **extra_kwargs)
"""
Tests for the `drf-rw-serializers` viewsets module.
"""

from __future__ import absolute_import, unicode_literals

from django.utils import version as django_version
from model_bakery import baker

from test_utils.base_tests import (
    BaseTestCase, TestListRequestSuccess, TestRetrieveRequestSuccess,
    TestCreateRequestSuccess, TestUpdateRequestSuccess)
from example_app.serializers import OrderCreateSerializer, OrderListSerializer


if django_version.get_complete_version() < (2, 0, 0):
    from django.core.urlresolvers import reverse  # pylint: disable=no-name-in-module,import-error
else:
    from django.urls import reverse  # pylint: disable=no-name-in-module,import-error


class OrderViewsetListCreateTests(
        BaseTestCase, TestListRequestSuccess, TestCreateRequestSuccess):

    def setUp(self):
        super(OrderViewsetListCreateTests, self).setUp()
        self.view_url = reverse('viewset_list_create')
        self.list_serializer_class = OrderListSerializer
        self.create_in_serializer_class = OrderCreateSerializer
        self.create_out_serializer_class = OrderListSerializer