def fsm_submit_row(context): """ Additional context added to an overridded submit row that adds links to change the state of an FSMField. """ original = context.get('original', None) model_name = original.__class__._meta.verbose_name if original else '' def button_name(transition): if hasattr(transition, 'custom') and 'button_name' in transition.custom: return transition.custom['button_name'] else: # Make the function name the button title, but prettier return '{0} {1}'.format(transition.name.replace('_', ' '), model_name).title() # The model admin defines which field we're dealing with # and has some utils for getting the transitions. request = context['request'] model_admin = context.get('adminform').model_admin transitions = model_admin._fsm_get_transitions(original, request) ctx = submit_row(context) ctx['transitions'] = [] for field, field_transitions in iter(transitions.items()): ctx['transitions'] += sorted([(field, button_name(t), t.name) for t in field_transitions], key=lambda e: e[1], reverse=True) ctx['perms'] = context['perms'] return ctx
def fsm_submit_row(context): ''' Additional context added to an overridded submit row that adds links to change the state of an FSMField. ''' original = context.get('original', None) model_name = original.__class__._meta.verbose_name if original else '' def button_name(transition): if hasattr(transition, 'custom') and 'button_name' in transition.custom: return transition.custom['button_name'] else: return '{} {}'.format(transition.name.replace('_', ' '), model_name).title() # The model admin defines which field we're dealing with # and has some utils for getting the transitions. model_admin = context.get('adminform').model_admin transitions = model_admin._fsm_get_transitions(original) ctx = submit_row(context) # Make the function name the button title, but prettier ctx['transitions'] = [(button_name(t), t.name) for t in transitions] ctx['perms'] = context['perms'] return ctx
def fsm_submit_row(context): """ Additional context added to an overridded submit row that adds links to change the state of an FSMField. """ original = context.get('original', None) model_name = original.__class__._meta.verbose_name if original else '' def button_name(transition): if hasattr(transition, 'custom') and 'button_name' in transition.custom: return transition.custom['button_name'] else: # Make the function name the button title, but prettier return '{0} {1}'.format(transition.name.replace('_',' '), model_name).title() # The model admin defines which field we're dealing with # and has some utils for getting the transitions. request = context['request'] model_admin = context.get('adminform').model_admin transitions = model_admin._fsm_get_transitions(original, request) ctx = submit_row(context) ctx['transitions'] = [] for field,field_transitions in iter(transitions.items()): ctx['transitions'] += [(field, button_name(t), t.name) for t in field_transitions] ctx['perms'] = context['perms'] return ctx
def readonly_submit_row(context): """ Read only submit row templatetag. Get from: http://anupamshakya.blogspot.com/2013/07/create-readonly-permission-for-all.html. :param context: template context. :type context: django.template.RequestContext. :return: updated context. :rtype: django.template.RequestContext. """ ctx = submit_row(context) app, separator, model = str(context["opts"]).partition(".") user = context["request"].user for permission in user.get_all_permissions(): head, sep, tail = permission.partition(".") perm = "{prefix}_{model}".format(**{ "prefix": PERMISSION_PREFIX, "model": model, }) if str(perm) == str(tail): if user.has_perm(str(permission)) and not user.is_superuser: ctx.update({ "show_delete_link": False, "show_save_and_add_another": False, "show_save_and_continue": False, "show_save": False, }) return ctx return ctx
def my_submit_row(context): ctx = submit_row(context) # Get a new context from the original. # Override on the basis of what the passed context contains... for name in ('show_save_and_add_another', 'show_save_and_continue'): ctx[name] = context.get(name, ctx[name]) return ctx
def order_submit_row(context): """ Extend the default `submit_row` by adding an extra flag to show the cancel button. """ context = submit_row(context) context['show_cancel'] = context['show_save'] and context['change'] return context
def submit_row(context): """ Displays the row of buttons for delete and save. """ from django.contrib.admin.templatetags.admin_modify import submit_row row = submit_row(context) row['is_soft_deleted'] = context['original'].moderated == 'deleted' return row
def freditor_submit_row(context): ctx = submit_row(context) ctx.update({ 'preview': (context['has_add_permission'] or context['has_change_permission']) and not context['is_popup'] }) return ctx
def submit_row(context): """ Overriding default submit row admin template tag to use some additional actions from context. """ tag_context = admin_modify.submit_row(context) tag_context.update({ 'additional_actions': context.get('additional_actions', []) }) return tag_context
def submit_line_row(context): context = context or {} ctx= admin_modify.submit_row(context) if context.get("readonly", None) != None: ctx["readonly"] = context.get("readonly") else: ctx["readonly"] = False return ctx
def viewflow_task_submit_row(context): task = context.get('original', None) activation = task.activate() activation_cls = activation.__class__ transitions = [(transition.name.replace('_', ' ').capitalize(), transition.name) for transition in activation_cls.status.get_available_transtions(activation)] row_context = submit_row(context) row_context['transitions'] = transitions return row_context
def ralph_submit_row(context): """ Overriding the default templatetag Django and adding to it multi_add_url of context. Return context. """ ctx = submit_row(context) ctx['multi_add_url'] = context.get('multi_add_url', None) ctx['multi_add_field'] = context.get('multi_add_field', None) return ctx
def test_submit_row(self): """ submit_row template tag should pass whole context. """ request = self.request_factory.get(reverse('admin:auth_user_change', args=[self.superuser.pk])) request.user = self.superuser admin = UserAdmin(User, site) extra_context = {'extra': True} response = admin.change_view(request, str(self.superuser.pk), extra_context=extra_context) template_context = submit_row(response.context_data) self.assertIs(template_context['extra'], True) self.assertIs(template_context['show_save'], True)
def submit_row_undelete(context): result = submit_row(context) change = context['change'] active = context['original'].active() if change else True is_popup = context['is_popup'] result.update({ 'show_delete_link': (active and result['show_delete_link']), 'show_undelete_link': (not is_popup and context['has_undelete_permission'] and change and not active), }) return result
def explicit_submit_row(context, **kwargs): """ This template tag allows disabling buttons explicitly from templates. """ explicit_context = {} for option in ('show_delete_link', 'show_save_as_new', 'show_save_and_add_another', 'show_save_and_continue', 'show_save'): if option in kwargs and not kwargs[option] is None: explicit_context[option] = kwargs[option] original_context = submit_row(context) original_context.update(explicit_context) return original_context
def submit_row(context): """ Displays the row of buttons for delete and save. Including projectname here so projectadmin can redirect to correctproject after saving,deleting """ ctx = original.submit_row(context) if "site" in ctx: ctx["site"] = context["site"] if "projectadmin" in context: ctx["projectadmin"] = context["projectadmin"] return ctx
def test_override_show_save_and_add_another(self): request = self.request_factory.get( reverse('admin:auth_user_change', args=[self.superuser.pk]), ) request.user = self.superuser admin = UserAdmin(User, site) for extra_context, expected_flag in ( ({}, True), # Default. ({'show_save_and_add_another': False}, False), ): with self.subTest(show_save_and_add_another=expected_flag): response = admin.change_view( request, str(self.superuser.pk), extra_context=extra_context, ) template_context = submit_row(response.context_data) self.assertIs(template_context['show_save_and_add_another'], expected_flag)
def submit_buttons(context): """ Return the context variables needed to populate the admin change form submit buttons. Changed to add a variable to the context, instead of rendering a hard-coded template, to allow easy extension (adding buttons) entirely within the template system. You can create a new template in one of the paths searched by ModelAdmin.render_change_form. Make it extend admin/change_form.html, which comes from the binder app instead of the Django admin system, and contains a block called submit_buttons that uses this template tag to add variables to the context. You can override that submit_buttons block to contain whatever buttons you want. """ from django.contrib.admin.templatetags import admin_modify context['buttons'] = admin_modify.submit_row(context) return ""
def fsm_submit_row(context): ''' Additional context added to an overridded submit row that adds links to change the state of an FSMField. ''' original = context.get('original', None) model_name = original.__class__._meta.verbose_name if original else '' def button_name(name): return '{} {}'.format(name.replace('_', ' '), model_name).title() # The model admin defines which field we're dealing with # and has some utils for getting the transitions. model_admin = context.get('adminform').model_admin transitions = model_admin._fsm_get_transitions(original) ctx = submit_row(context) # Make the function name the button title, but prettier ctx['transitions'] = [(button_name(func.func_name), func.func_name) for target, func in transitions] ctx['perms'] = context['perms'] return ctx
def fsm_submit_row(context): """ Additional context added to an overridded submit row that adds links to change the state of an FSMField. """ original = context.get('original', None) model_name = '' if original is not None: # TODO: replace the following line by `original is models.DEFERRED` # after dropping support for Django-1.9 if getattr(original, '_deferred', False) or original is getattr(models, 'DEFERRED', None): model_name = type(original).__base__._meta.verbose_name else: model_name = original.__class__._meta.verbose_name def button_name(transition): if hasattr(transition, 'custom') and 'button_name' in transition.custom: return transition.custom['button_name'] else: # Make the function name the button title, but prettier return '{0} {1}'.format(transition.name.replace('_', ' '), model_name).title() # The model admin defines which field we're dealing with # and has some utils for getting the transitions. request = context['request'] model_admin = context.get('adminform').model_admin transitions = model_admin._fsm_get_transitions(original, request) ctx = submit_row(context) ctx['transitions'] = [] for field, field_transitions in iter(transitions.items()): ctx['transitions'] += sorted( [(field, button_name(t), t.name) for t in field_transitions], key=lambda e: e[1], reverse=True ) ctx['perms'] = context['perms'] return ctx
def mo_admin_submit_row(context): """ Override submit row to specify required mo_admin template """ return submit_row(context)
def submit_affiliate_row(context): return submit_row(context)
def component_submit_row(context): ctx = admin_modify.submit_row(context) return ctx
def custom_submit_row(context): o = submit_row(context) o['request'] = context['request'] return o
def django_ca_certificate_submit_row( context: template.context.RequestContext) -> template.context.Context: """Submit row for certificate change view.""" return submit_row(context)
def submit_row_custom(context): ctx = submit_row(context) ctx['show_save_and_add_another'] = False ctx['show_save_and_continue'] = False return ctx
def schedule_template_submit_row(context): return submit_row(context)
def custom_post_submit_row(context): return submit_row(context)
def extended_submit_row(context): _submit_row = submit_row(context) additional_buttons = context.get('additional_buttons', None) _submit_row['additional_buttons'] = additional_buttons return _submit_row
def publish_submit_row(context): ctx = submit_row(context) ctx['show_publish'] = context.get('has_publish_permission') \ and context.get('change') return ctx
def task_submit_row(context): return admin_modify.submit_row(context)
def document_submit_row(context): return admin_modify.submit_row(context)
def preference_submit_row(context): return admin_modify.submit_row(context)
def django_ca_certificate_submit_row(context): return submit_row(context)
def subadmin_submit_row(context): ctx = submit_row(context) ctx.update({'request': context['request']}) return ctx
def glitter_submit_row(context): return submit_row(context)
def django_ca_certificate_submit_row(context): """Submit row for certificate change view.""" return submit_row(context)