コード例 #1
0
 def get(self, request, *args, **kwargs):
     """
     Method that handles the GET requests for this view. Calls the management command to update the reduced data and
     adds a hint using the messages framework about automation.
     """
     # QueryDict is immutable, and we want to append the remaining params to the redirect URL
     query_params = request.GET.copy()
     target_id = query_params.pop('target_id', None)
     out = StringIO()
     if target_id:
         if isinstance(target_id, list):
             target_id = target_id[-1]
         call_command('updatereduceddata', target_id=target_id, stdout=out)
     else:
         call_command('updatereduceddata', stdout=out)
     messages.info(request, out.getvalue())
     add_hint(
         request,
         mark_safe(
             'Did you know updating observation statuses can be automated? Learn how in '
             '<a href=https://tom-toolkit.readthedocs.io/en/stable/customization/automation.html>'
             'the docs.</a>'))
     return HttpResponseRedirect(
         f'{self.get_redirect_url(*args, **kwargs)}?{urlencode(query_params)}'
     )
コード例 #2
0
ファイル: views.py プロジェクト: scottcoughlin2014/tom_base
    def get(self, request, *args, **kwargs):
        """
        Handles the GET requests to this view. If update_status is passed into the query parameters, calls the
        updatestatus management command to query for new statuses for ``ObservationRecord`` objects associated with this
        target.

        :param request: the request object passed to this view
        :type request: HTTPRequest
        """
        update_status = request.GET.get('update_status', False)
        if update_status:
            if not request.user.is_authenticated:
                return redirect(reverse('login'))
            target_id = kwargs.get('pk', None)
            out = StringIO()
            call_command('updatestatus', target_id=target_id, stdout=out)
            messages.info(request, out.getvalue())
            add_hint(request, mark_safe(
                              'Did you know updating observation statuses can be automated? Learn how in'
                              '<a href=https://tom-toolkit.readthedocs.io/en/stable/customization/automation.html>'
                              ' the docs.</a>'))
            return redirect(reverse('tom_targets:detail', args=(target_id,)))

        run_strategy_form = RunStrategyForm(request.GET)
        if run_strategy_form.is_valid():
            obs_strat = ObservingStrategy.objects.get(pk=run_strategy_form.cleaned_data['observing_strategy'].id)
            params = urlencode(obs_strat.parameters_as_dict)
            return redirect(
                reverse('tom_observations:create',
                        args=(obs_strat.facility,)) + f'?target_id={self.get_object().id}&' + params)

        return super().get(request, *args, **kwargs)
コード例 #3
0
    def get(self, request, *args, **kwargs):
        """
        Handles the GET requests to this view. If update_status is passed into the query parameters, calls the
        updatestatus management command to query for new statuses for ``ObservationRecord`` objects associated with this
        target.

        :param request: the request object passed to this view
        :type request: HTTPRequest
        """
        update_status = request.GET.get('update_status', False)
        if update_status:
            if not request.user.is_authenticated:
                return redirect(reverse('login'))
            target_id = kwargs.get('pk', None)
            out = StringIO()
            call_command('updatestatus', target_id=target_id, stdout=out)
            messages.info(request, out.getvalue())
            add_hint(
                request,
                mark_safe(
                    'Did you know updating observation statuses can be automated? Learn how in'
                    '<a href=https://tom-toolkit.readthedocs.io/en/stable/customization/automation.html>'
                    ' the docs.</a>'))
            return redirect(reverse('tom_targets:detail', args=(target_id, )))
        return super().get(request, *args, **kwargs)
コード例 #4
0
ファイル: views.py プロジェクト: rubyvanrooyen/tom_base
 def get(self, request, *args, **kwargs):
     target_id = request.GET.get('target_id', None)
     out = StringIO()
     if target_id:
         call_command('updatereduceddata', target_id=target_id, stdout=out)
     else:
         call_command('updatereduceddata', stdout=out)
     messages.info(request, out.getvalue())
     add_hint(
         request,
         mark_safe(
             'Did you know updating observation statuses can be automated? Learn how in '
             '<a href=https://tom-toolkit.readthedocs.io/en/stable/customization/automation.html>'
             'the docs.</a>'))
     return HttpResponseRedirect(self.get_redirect_url(*args, **kwargs))
コード例 #5
0
ファイル: views.py プロジェクト: rubyvanrooyen/tom_base
 def get(self, request, *args, **kwargs):
     update_status = request.GET.get('update_status', False)
     if update_status:
         if not request.user.is_authenticated:
             return redirect(reverse('login'))
         out = StringIO()
         call_command('updatestatus', stdout=out)
         messages.info(request, out.getvalue())
         add_hint(
             request,
             mark_safe(
                 'Did you know updating observation statuses can be automated? Learn how in '
                 '<a href=https://tom-toolkit.readthedocs.io/en/stable/customization/automation.html>'
                 'the docs.</a>'))
         return redirect(reverse('tom_observations:list'))
     return super().get(request, *args, **kwargs)
コード例 #6
0
ファイル: views.py プロジェクト: scottcoughlin2014/tom_base
 def get(self, request, *args, **kwargs):
     """
     Method that handles the GET requests for this view. Calls the management command to update the reduced data and
     adds a hint using the messages framework about automation.
     """
     target_id = request.GET.get('target_id', None)
     out = StringIO()
     if target_id:
         call_command('updatereduceddata', target_id=target_id, stdout=out)
     else:
         call_command('updatereduceddata', stdout=out)
     messages.info(request, out.getvalue())
     add_hint(
         request,
         mark_safe(
             'Did you know updating observation statuses can be automated? Learn how in '
             '<a href=https://tom-toolkit.readthedocs.io/en/stable/customization/automation.html>'
             'the docs.</a>'))
     return HttpResponseRedirect(self.get_redirect_url(*args, **kwargs))
コード例 #7
0
ファイル: views.py プロジェクト: TOMToolkit/tom_base
    def get(self, request, *args, **kwargs):
        """
        Handles the GET requests to this view. If update_status is passed in the query parameters, calls the
        updatestatus management command to query for new statuses for ``ObservationRecord`` objects.

        :param request: request object for this GET request
        :type request: HTTPRequest
        """
        # QueryDict is immutable, and we want to append the remaining parameters to the redirect URL
        query_params = request.GET.copy()
        update_status = query_params.pop('update_status', False)
        if update_status:
            if not request.user.is_authenticated:
                return redirect(reverse('login'))
            out = StringIO()
            call_command('updatestatus', stdout=out)
            messages.info(request, out.getvalue())
            add_hint(
                request,
                mark_safe(
                    'Did you know updating observation statuses can be automated? Learn how in '
                    '<a href=https://tom-toolkit.readthedocs.io/en/stable/customization/automation.html>'
                    'the docs.</a>'))
            return redirect(
                f'{reverse("tom_observations:list")}?{urlencode(query_params)}'
            )

        selected = request.GET.getlist('selected')
        observationgroups = request.GET.getlist('observationgroup')
        action = request.GET.get('action')
        if selected and observationgroups and action:
            observation_records = ObservationRecord.objects.filter(
                id__in=selected)
            groups = ObservationGroup.objects.filter(id__in=observationgroups)
            for group in groups:
                if action == 'add':
                    group.observation_records.add(*observation_records)
                if action == 'remove':
                    group.observation_records.remove(*observation_records)
                group.save()
            return redirect(reverse('tom_observations:list'))
        return super().get(request, *args, **kwargs)