|
34 | 34 | from django.core.exceptions import ValidationError |
35 | 35 | from django.core.validators import URLValidator |
36 | 36 | from django.urls import reverse,reverse_lazy |
37 | | -from django.db.models import Min, Max, Q |
| 37 | +from django.db.models import Min, Max, Q, F |
38 | 38 | from django.forms.models import modelform_factory, inlineformset_factory |
39 | 39 | from django.template import TemplateDoesNotExist |
40 | 40 | from django.template.loader import render_to_string |
|
67 | 67 | from ietf.meeting.helpers import send_interim_cancellation_notice |
68 | 68 | from ietf.meeting.helpers import send_interim_approval_request |
69 | 69 | from ietf.meeting.helpers import send_interim_announcement_request |
70 | | -from ietf.meeting.utils import finalize |
71 | | -from ietf.meeting.utils import sort_accept_tuple |
| 70 | +from ietf.meeting.utils import finalize, sort_accept_tuple, condition_slide_order |
72 | 71 | from ietf.message.utils import infer_message |
73 | 72 | from ietf.secr.proceedings.utils import handle_upload_file |
74 | 73 | from ietf.secr.proceedings.proc_utils import (get_progress_stats, post_process, import_audio_files, |
@@ -1663,31 +1662,119 @@ def remove_sessionpresentation(request, session_id, num, name): |
1663 | 1662 |
|
1664 | 1663 | return render(request,'meeting/remove_sessionpresentation.html', {'sp': sp }) |
1665 | 1664 |
|
1666 | | -def set_slide_order(request, session_id, num, name): |
1667 | | - # num is redundant, but we're dragging it along an artifact of where we are in the current URL structure |
| 1665 | +def ajax_add_slides_to_session(request, session_id, num): |
1668 | 1666 | session = get_object_or_404(Session,pk=session_id) |
1669 | | - if not Document.objects.filter(type_id='slides',name=name).exists(): |
1670 | | - raise Http404 |
| 1667 | + |
1671 | 1668 | if not session.can_manage_materials(request.user): |
1672 | 1669 | return HttpResponseForbidden("You don't have permission to upload slides for this session.") |
1673 | 1670 | if session.is_material_submission_cutoff() and not has_role(request.user, "Secretariat"): |
1674 | 1671 | return HttpResponseForbidden("The materials cutoff for this session has passed. Contact the secretariat for further action.") |
1675 | 1672 |
|
1676 | 1673 | if request.method != 'POST' or not request.POST: |
1677 | 1674 | return HttpResponse(json.dumps({ 'success' : False, 'error' : 'No data submitted or not POST' }),content_type='application/json') |
1678 | | - order_str = request.POST.get('order', None) |
| 1675 | + |
| 1676 | + order_str = request.POST.get('order', None) |
1679 | 1677 | try: |
1680 | 1678 | order = int(order_str) |
1681 | | - except ValueError: |
| 1679 | + except (ValueError, TypeError): |
1682 | 1680 | return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied order is not valid' }),content_type='application/json') |
1683 | | - if order <=0 or order > 32767 : |
| 1681 | + if order < 1 or order > session.sessionpresentation_set.filter(document__type_id='slides').count() + 1 : |
1684 | 1682 | return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied order is not valid' }),content_type='application/json') |
1685 | | - |
1686 | | - sp = session.sessionpresentation_set.get(document__name = name) |
1687 | | - sp.order = order |
| 1683 | + |
| 1684 | + name = request.POST.get('name', None) |
| 1685 | + doc = Document.objects.filter(name=name).first() |
| 1686 | + if not doc: |
| 1687 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied name is not valid' }),content_type='application/json') |
| 1688 | + |
| 1689 | + if not session.sessionpresentation_set.filter(document=doc).exists(): |
| 1690 | + condition_slide_order(session) |
| 1691 | + session.sessionpresentation_set.filter(document__type_id='slides', order__gte=order).update(order=F('order')+1) |
| 1692 | + session.sessionpresentation_set.create(document=doc,rev=doc.rev,order=order) |
| 1693 | + DocEvent.objects.create(type="added_comment", doc=doc, rev=doc.rev, by=request.user.person, desc="Added to session: %s" % session) |
| 1694 | + |
| 1695 | + return HttpResponse(json.dumps({'success':True}), content_type='application/json') |
| 1696 | + |
| 1697 | + |
| 1698 | +def ajax_remove_slides_from_session(request, session_id, num): |
| 1699 | + session = get_object_or_404(Session,pk=session_id) |
| 1700 | + |
| 1701 | + if not session.can_manage_materials(request.user): |
| 1702 | + return HttpResponseForbidden("You don't have permission to upload slides for this session.") |
| 1703 | + if session.is_material_submission_cutoff() and not has_role(request.user, "Secretariat"): |
| 1704 | + return HttpResponseForbidden("The materials cutoff for this session has passed. Contact the secretariat for further action.") |
| 1705 | + |
| 1706 | + if request.method != 'POST' or not request.POST: |
| 1707 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'No data submitted or not POST' }),content_type='application/json') |
| 1708 | + |
| 1709 | + oldIndex_str = request.POST.get('oldIndex', None) |
| 1710 | + try: |
| 1711 | + oldIndex = int(oldIndex_str) |
| 1712 | + except (ValueError, TypeError): |
| 1713 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied index is not valid' }),content_type='application/json') |
| 1714 | + if oldIndex < 1 or oldIndex > session.sessionpresentation_set.filter(document__type_id='slides').count() : |
| 1715 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied index is not valid' }),content_type='application/json') |
| 1716 | + |
| 1717 | + name = request.POST.get('name', None) |
| 1718 | + doc = Document.objects.filter(name=name).first() |
| 1719 | + if not doc: |
| 1720 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied name is not valid' }),content_type='application/json') |
| 1721 | + |
| 1722 | + condition_slide_order(session) |
| 1723 | + affected_presentations = session.sessionpresentation_set.filter(document=doc).first() |
| 1724 | + if affected_presentations: |
| 1725 | + if affected_presentations.order == oldIndex: |
| 1726 | + affected_presentations.delete() |
| 1727 | + session.sessionpresentation_set.filter(document__type_id='slides', order__gt=oldIndex).update(order=F('order')-1) |
| 1728 | + DocEvent.objects.create(type="added_comment", doc=doc, rev=doc.rev, by=request.user.person, desc="Removed from session: %s" % session) |
| 1729 | + return HttpResponse(json.dumps({'success':True}), content_type='application/json') |
| 1730 | + else: |
| 1731 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Name does not match index' }),content_type='application/json') |
| 1732 | + else: |
| 1733 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'SessionPresentation not found' }),content_type='application/json') |
| 1734 | + |
| 1735 | + |
| 1736 | +def ajax_reorder_slides_in_session(request, session_id, num): |
| 1737 | + session = get_object_or_404(Session,pk=session_id) |
| 1738 | + |
| 1739 | + if not session.can_manage_materials(request.user): |
| 1740 | + return HttpResponseForbidden("You don't have permission to upload slides for this session.") |
| 1741 | + if session.is_material_submission_cutoff() and not has_role(request.user, "Secretariat"): |
| 1742 | + return HttpResponseForbidden("The materials cutoff for this session has passed. Contact the secretariat for further action.") |
| 1743 | + |
| 1744 | + if request.method != 'POST' or not request.POST: |
| 1745 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'No data submitted or not POST' }),content_type='application/json') |
| 1746 | + |
| 1747 | + num_slides_in_session = session.sessionpresentation_set.filter(document__type_id='slides').count() |
| 1748 | + oldIndex_str = request.POST.get('oldIndex', None) |
| 1749 | + try: |
| 1750 | + oldIndex = int(oldIndex_str) |
| 1751 | + except (ValueError, TypeError): |
| 1752 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied index is not valid' }),content_type='application/json') |
| 1753 | + if oldIndex < 1 or oldIndex > num_slides_in_session : |
| 1754 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied index is not valid' }),content_type='application/json') |
| 1755 | + |
| 1756 | + newIndex_str = request.POST.get('newIndex', None) |
| 1757 | + try: |
| 1758 | + newIndex = int(newIndex_str) |
| 1759 | + except (ValueError, TypeError): |
| 1760 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied index is not valid' }),content_type='application/json') |
| 1761 | + if newIndex < 1 or newIndex > num_slides_in_session : |
| 1762 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied index is not valid' }),content_type='application/json') |
| 1763 | + |
| 1764 | + if newIndex == oldIndex: |
| 1765 | + return HttpResponse(json.dumps({ 'success' : False, 'error' : 'Supplied index is not valid' }),content_type='application/json') |
| 1766 | + |
| 1767 | + condition_slide_order(session) |
| 1768 | + sp = session.sessionpresentation_set.get(order=oldIndex) |
| 1769 | + if oldIndex < newIndex: |
| 1770 | + session.sessionpresentation_set.filter(order__gt=oldIndex, order__lte=newIndex).update(order=F('order')-1) |
| 1771 | + else: |
| 1772 | + session.sessionpresentation_set.filter(order__gte=newIndex, order__lt=oldIndex).update(order=F('order')+1) |
| 1773 | + sp.order = newIndex |
1688 | 1774 | sp.save() |
1689 | 1775 |
|
1690 | | - return HttpResponse(json.dumps({'success':True}),content_type='application/json') |
| 1776 | + return HttpResponse(json.dumps({'success':True}), content_type='application/json') |
| 1777 | + |
1691 | 1778 |
|
1692 | 1779 | @role_required('Secretariat') |
1693 | 1780 | def make_schedule_official(request, num, owner, name): |
|
0 commit comments