--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/CPspzgE33Dk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ac24306b-96d0-4eaa-ba23-3fedfa0a48ae%40googlegroups.com.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ac24306b-96d0-4eaa-ba23-3fedfa0a48ae%40googlegroups.com.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9a50c857-0e5b-4aac-8dfe-1ad79cbfef50%40googlegroups.com.
url(r'^gaas-wafer-designs/create/$', gaas_wafer_designs.GaasWaferDesignCreateView.as_view(), name='gaas_wafer_design_create'),
class GaasWaferDesignCreateView(LoginRequiredMixin, CreateView): fields = ("design_ui", "emitting", "contact_location", "optical_power", "design_date", "designer", "design_document", "designer_ui", "in_trash", "inactive_date", "notes") model = GaasWaferDesign template_name = 'engineering/gaas_wafer_designs/gaas_wafer_design_form_inner.html'
def form_valid(self, form): self.object = form.save() return render(self.request, 'engineering/gaas_wafer_designs/create_success.html', {'gaas_wafer_designs': self.object})
{% extends "pages/list_template.html" %}{% load static from staticfiles %}{% load widget_tweaks %}
{% block title %}GaAs Wafer Design List{% endblock %}{% block list_title %}GaAs Wafer Designs{% endblock %}{% block list_title_2 %}Design Inventory{% endblock %}
{% block extra_js%}<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script src="http://malsup.github.com/jquery.form.js"></script>{% endblock %}
{% block buttons %} <div class="btn-group" role="group" aria-label="Button group with nested dropdown" style="margin-bottom: -150px; z-index:1000;"> <!--<a class="btn btn-secondary js-create"><i class="fa fa-plus-circle fa-fw"></i> Add GaAs Wafer Design</a>--> <div class="btn-group" role="group"> <a id="btnGroupDrop1" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> View </a> <div class="dropdown-menu" aria-labelledby="btnGroupDrop1"> <a class="dropdown-item" href="#">Recycling Bin</a> </div> </div> </div> <p>Click <a data-toggle="modal" data-target="#modal" href="{% url 'engineering:gaas_wafer_design_create' %}">here</a> to show the modal</p> <div class="modal fade" id="modal"></div>{% endblock %}
{% block table %} <thead> <tr> <th> Wafer Design UI </th> <th> Emitting Type </th> <th> Contact Location </th> <th> Optical Power </th> <th> Design Date </th> <th> Designer </th> <th> Designer UI </th> <th> Created At </th> </tr> </thead> <tfoot> <tr> <th> Wafer Design UI </th> <th> Emitting Type </th> <th> Contact Location </th> <th> Optical Power </th> <th> Design Date </th> <th> Designer </th> <th> Designer UI </th> <th> Created At </th> </tr> </tfoot> <tbody> {% for gaas_wafer_design in gaas_wafer_designs %} <tr> <td><a href="{% url 'engineering:gaas_wafer_design_detail' pk=gaas_wafer_design.pk %}">{{ gaas_wafer_design.design_ui }}</a></td> <td>{{ gaas_wafer_design.get_emitting_display }}</td> <td>{{ gaas_wafer_design.contact_location }}</td> <td>{{ gaas_wafer_design.optical_power }}</td> <td>{{ gaas_wafer_design.design_date|date:"m/d/y" }}</td> <td>{{ gaas_wafer_design.designer }}</td> <td>{{ gaas_wafer_design.designer_ui }}</td> <td>{{ gaas_wafer_design.created_at }}</td> </tr> {% endfor %} </tbody>
<script> $('#modal').on('show.bs.modal', function (event) { var modal = $(this) $.ajax({ url: "{% url 'engineering:gaas_wafer_design_create' %}", context: document.body }).done(function(response) { modal.html(response); }); }) </script>{% endblock %}{% block modal %}
{% endblock %}
{% load i18n widget_tweaks %}<div class="modal-dialog modal-lg" role="document"> <form action="{% url 'engineering:gaas_wafer_design_create' %}" method="post" id="gaas-create" class="form">{% csrf_token %} <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> <span class="sr-only">Close</span> </button> <h4 class="modal-title">Add News</h4> </div> <div class="modal-body"> Test </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <input type="submit" class="btn btn-primary" value="Save changes" /> </div> </div><!-- /.modal-content --> </form></div><!-- /.modal-dialog --><script> var form_options = { target: '#modal', success: function(response) {} }; $('#gaas-create').ajaxForm(form_options);</script>
<div class="modal-dialog modal-lg" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> <span class="sr-only">Test</span> </button> <h4 class="modal-title">Test</h4> </div> <div class="modal-body"> <p class="alert alert-info">Succesfully created!</p> </div><!-- /.modal-body --> </div><!-- /.modal-content --></div><!-- /.modal-dialog --><script> // close the modal after 3 seconds setTimeout(function() { $('#modal').modal('hide'); }, 3000);</script>
<p>Click <a data-toggle="modal" data-target="#modal" href="{% url 'engineering:gaas_wafer_design_create' %}">here</a> to show the modal</p>
<button data-toggle="modal" data-target="#modal" %}">Create a new wafer design</button>
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/CPspzgE33Dk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/53d50894-98f7-4d92-a1c2-0a9d61e19fea%40googlegroups.com.
I have a lot of this stuff worked out, but for Bootstrap 3. I've done this in a UX library I've used for various projects, so it's kinda of a need-driven collection of widgets, CBV's and form components - not exactly something for general use.
I've made it available on Gitlab, so you can see how you add various modals to a single view. In my case I mostly used a context menu to launch the modals, but I never bothered with the Ajax part, instead the forms get submitted normally, generating a page reload. That part you have to do yourself, but there's a lot in there you can build on:
- Mixins to handle addtional forms
- Template tags to render a bootstrap 3 modal
- etcetera...
And here's an example of a view from a project management tool that I wrote with it:
class ProjectDetailView(DefaultPageMixin, AdditionalFormsMixin,
ContextMenuMixin, generic.DetailView):
model = models.Project
context_object_name = 'project'
template_name = 'view/project.html'
def generate_context_menu(self) -> None:
self.add_active_menu_link('view_project', _('View Project'), icon='eye')
self.add_context_menu_modal(
'edit_project', _('Edit Project'), 'edit-project', icon='pencil',
title=_('Edit current project')
)
self.add_context_menu_modal(
'add_task', _('Add Milestone'), 'add-task', icon='plus-square',
)
def generate_additional_forms(self):
proj_update_url = reverse('core:project_edit',
kwargs={'slug': self.object.slug})
task_create_url = reverse('core:project_task_create')
self.add_additional_form(
'project_update_form', forms.ProjectForm, proj_update_url,
model_instance=self.object,
)
self.add_additional_form(
'add_milestone_form', forms.NewProjectTaskForm, task_create_url,
initial={'project': self.object, 'is_milestone': True},
)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
del context['object']
project = self.object # type: models.Project
context['has_milestones'] = project.has_milestones
context['milestones'] = project.milestones.order_by('sequence', 'title')
return context
I may clean up the library for more general use, but in the mean time, hope this helps you along with your quest.
> > To post to this group, send email to django...@googlegroups.com.
> > Visit this group at https://groups.google.com/group/django-users.
> > To view this discussion on the web visit https://groups.google.com/d/
> > msgid/django-users/53d50894-98f7-4d92-a1c2-0a9d61e19fea%40googlegroups.com
> > <https://groups.google.com/d/msgid/django-users/53d50894-98f7-4d92-a1c2-0a
> > 9d61e19fea%40googlegroups.com?utm_medium=email&utm_source=footer> .
Melvyn Sopacua
> > To post to this group, send email to django...@googlegroups.com.
> > Visit this group at https://groups.google.com/group/django-users.
> > To view this discussion on the web visit https://groups.google.com/d/
> > msgid/django-users/53d50894-98f7-4d92-a1c2-0a9d61e19fea%40googlegroups.com
> > <https://groups.google.com/d/msgid/django-users/53d50894-98f7-4d92-a1c2-0a
> > 9d61e19fea%40googlegroups.com?utm_medium=email&utm_source=footer> .
> >
> > For more options, visit https://groups.google.com/d/optout.
--
Melvyn Sopacua
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/CPspzgE33Dk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2951285.rXdhm0d2eO%40fritzbook.
{% extends "pages/list_template.html" %}{% load static from staticfiles %}{% load widget_tweaks %}
{% block title %}GaAs Wafer Design List{% endblock %}{% block list_title %}GaAs Wafer Designs{% endblock %}{% block list_title_2 %}Design Inventory{% endblock %}
{% block extra_js%}<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--<script src="{% static 'js/jscreate.js' %}"></script>-->
<script src="http://malsup.github.com/jquery.form.js"></script>{% endblock %}
{% block buttons %} <div class="btn-group" role="group" aria-label="Button group with nested dropdown" style="margin-bottom: -150px; z-index:1000;">
<button class="btn btn-secondary" data-toggle="modal" data-target="#modal" %}>Create a new wafer design</button>
<div class="btn-group" role="group"> <a id="btnGroupDrop1" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> View </a> <div class="dropdown-menu" aria-labelledby="btnGroupDrop1"> <a class="dropdown-item" href="#">Recycling Bin</a> </div> </div> </div>
{% endblock %}
{% block table %}
<div class="modal fade" id="modal">
<div class="modal-dialog modal-lg" role="document"> <form action="{% url 'engineering:gaas_wafer_design_create' %}" method="post" id="gaas-create" class="form">{% csrf_token %} <div class="modal-content"> <div class="modal-header">
<h4 class="modal-title">Add Wafer Design</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> <span class="sr-only">Close</span> </button>
</div> <div class="modal-body"> Test </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <input type="submit" class="btn btn-primary" value="Save changes" /> </div> </div><!-- /.modal-content --> </form> </div><!-- /.modal-dialog -->
</div>
<script>/*
$('#modal').on('show.bs.modal', function (event) { var modal = $(this) $.ajax({
url: "create/",
context: document.body }).done(function(response) { modal.html(response); }); }) </script>{% endblock %}