示例#1
0
文件: views.py 项目: h1ds/h1ds
    def get(self, request, *args, **kwargs):

        device_slug = kwargs.get("device")

        shot_str = kwargs.get("shot_str", DEFAULT_SHOT_REGEX)
        attr_str = kwargs.get("attr_str", DEFAULT_ATTR_STR)
        filter_str = kwargs.get("filter_str", DEFAULT_FILTER)

        device = Device.objects.get(slug=device_slug)
        table = SummaryTable(device)

        results = table.do_query_from_path_components(shot_str, attr_str, filter_str)
        # TODO: HTML version w/ templates...

        if request.accepted_renderer.format == 'html':
            if not results:
                return Response(template_name='h1ds_summary/no_data.html')

            inactive_attributes, active_attributes = self.get_attribute_links(request, *args, **kwargs)
            sql_form = RawSqlForm(initial={'device': device.slug})
            return Response({'data': results,
                             'device': device,
                             'inactive_attributes': inactive_attributes,
                             'active_attributes': active_attributes,
                             'sql_form': sql_form},
                            template_name='h1ds_summary/summary_table.html')

        serializer = SimpleSerializer(results)
        return Response(serializer.data)
示例#2
0
文件: tasks.py 项目: h1ds/h1ds
def test_signal(sender=None, task_id=None, task=None, args=None, kwargs=None, **kwds):
    if sender == 'h1ds.tasks.populate_tree_success':  #TODO should be able to put this in connect - but not working?
        from h1ds.models import Device
        from h1ds_summary.db import SummaryTable
        device_slug, shot_number, tree = args[0]
        # TODO: should this be a celery task?
        device = Device(slug=device_slug)
        db = SummaryTable(device)
        db.add_or_update_shot(shot_number)
示例#3
0
文件: views.py 项目: h1ds/h1ds
 def post(self, request, *args, **kwargs):
     return_path = request.POST.get("return_path")
     device = Device.objects.get(slug=kwargs['device'])
     table = SummaryTable(device)
     if 'shot' in request.POST:
         shot_instance = Shot(number=int(request.POST.get("shot")), device=device)
         table.update_shot(shot_instance)
     elif 'attribute' in request.POST:
         attribute = request.POST.get("attribute")
         table.update_attribute(attribute)
     return HttpResponseRedirect(return_path)
示例#4
0
文件: views.py 项目: h1ds/h1ds
 def post(self, request, *args, **kwargs):
     form = RawSqlForm(request.POST)
     if form.is_valid():
         device = Device.objects.get(slug=form.cleaned_data['device'])
         table = SummaryTable(device)
         select_list = [i.strip() for i in form.cleaned_data['select'].split(',')]
         if not 'shot' in select_list:
             select_list.insert(0, 'shot')
         results = table.do_query(select=select_list, where=form.cleaned_data['where'])
         # TODO: non html
         return Response({'data': results,
                          'device': device,
                          'inactive_attributes': [],
                          'active_attributes': [],
                          'sql_form': form},
                         template_name='h1ds_summary/summary_table.html')
     else:  # invalid form
         # TODO: proper handling here
         return HttpResponseRedirect("/")
示例#5
0
文件: views.py 项目: h1ds/h1ds
    def get_attribute_links(self, request, *args, **kwargs):
        """Get links and info about attributes which can be added or removed from the current table.

        Returns:
            showable_attributes, hideable_attributes - both are lists of dicts

        Both showable_attributes and hideableattributes have the format [attr_a, attr_b, ...], where attr_x is
        {slug:, url:, name:, description:}

        """
        # TODO: remove duplication here, we already have grabbed the device in self.get()
        device = Device.objects.get(slug=kwargs.get("device"))
        table = SummaryTable(device)
        all_attrs = table.get_attributes_from_table(filter_initial_attributes=True)
        shot_str = kwargs.get("shot_str", DEFAULT_SHOT_REGEX)
        attr_str = kwargs.get("attr_str", DEFAULT_ATTR_STR)
        filter_str = kwargs.get("filter_str", DEFAULT_FILTER)
        attr_variants = get_attribute_variants(device=device, all_attrs=all_attrs, attr_str=attr_str)

        showable_attribute = []
        hideable_attributes = []

        for attr in attr_variants:
            attr_instance = SummaryAttribute.objects.get(device=device, slug=attr['slug'])
            if filter_str:
                attr_url = reverse('sdfsummary', kwargs={'device': device.slug, 'shot_str': shot_str,
                                                         'attr_str': attr['attr_str'],
                                                         'filter_str': filter_str})
            else:
                attr_url = reverse('sdsummary', kwargs={'device': device.slug, 'shot_str': shot_str, 'attr_str': attr['attr_str']})

            attr_dict = {'slug': attr['slug'], 'url': attr_url,
                         'name': attr_instance.name, 'description': attr_instance.description}
            if attr['is_active']:
                hideable_attributes.append(attr_dict)
            else:
                showable_attribute.append(attr_dict)

        return showable_attribute, hideable_attributes
示例#6
0
文件: views.py 项目: h1ds/h1ds
 def get(self, request, *args, **kwargs):
     device = Device.objects.get(slug=kwargs['device'])
     #latest_shot = get_latest_shot_from_summary_table(device)
     table = SummaryTable(device)
     latest_shot = table.get_latest_shot()
     return HttpResponse('{"latest_shot":"%s"}' % latest_shot, 'application/javascript')
示例#7
0
文件: tasks.py 项目: h1ds/h1ds
def update_from_shot_slug(device_slug, shot_slug):
    from h1ds_summary.db import SummaryTable
    device = Device(slug=device_slug)
    db = SummaryTable(device)
    for shot in parse_shot_slug(device, shot_slug):
        db.add_or_update_shot(shot)
示例#8
0
文件: models.py 项目: h1ds/h1ds
 def delete(self, *args, **kwargs):
     table = SummaryTable(self.device)
     table.delete_attribute(self.slug)
     super(SummaryAttribute, self).delete(*args, **kwargs)
示例#9
0
文件: models.py 项目: h1ds/h1ds
 def save(self, *args, **kwargs):
     super(SummaryAttribute, self).save(*args, **kwargs)
     table = SummaryTable(self.device)
     table.create_attribute(self.slug)
     table.populate_attribute(self.slug)