Пример #1
0
 def get(self, request, *args, **kwargs):
     instance = self.get_object()
     f = instance.localization_file.open("rb")
     response = http.HttpResponse()
     response.write(f.read())
     response['Content-Type'] = 'application/octet-stream'
     return response
Пример #2
0
 def get(self, request, *args, **kwargs):
     """
     handles the get request
     """
     instance = self.get_object()
     f = instance.audiofile.open("rb")
     response = HttpResponse()
     response.write(f.read())
     response['Content-Type'] = 'audio/wav'
     response['Content-Length'] = instance.audiofile.size
     return response
Пример #3
0
    def rdp(self, request, uuid=None):
        vm = self.get_object()

        try:
            rdp_endpoint = vm.endpoints.get(
                name=models.InstanceEndpoint.Name.RDP)
        except models.InstanceEndpoint.DoesNotExist:
            raise exceptions.NotFound(
                "This virtual machine doesn't run remote desktop")

        response = HttpResponse(content_type='application/x-rdp')
        response[
            'Content-Disposition'] = 'attachment; filename="{}.rdp"'.format(
                vm.name)
        response.write("full address:s:%s.cloudapp.net:%s\n"
                       "prompt for credentials:i:1\n\n" %
                       (vm.service_project_link.cloud_service_name,
                        rdp_endpoint.public_port))

        return response
Пример #4
0
def outputResult(request, pk):
    context = {}
    context['pk'] = pk
    try:
        event = common.get_user_event(request.user, pk)
        context['event'] = event
        task_arrary = event_models.EventTask.objects.filter(event=pk)
        all_score = 0
        all_count = 0
        for t in task_arrary:
            all_count += 1
            all_score = all_score + t.task_score
        context['all_score'] = all_score
        context['all_count'] = all_count
    except event_models.Event.DoesNotExist as e:
        return default_views.Http404Page(request, e)
    events = event_models.Event.objects.get(pk=pk)
    eventset = SubmitRecord.objects.filter(event=events)
    queryset = eventset.values('user__id').annotate(
        obj_id=F('user__id'),
        obj_name=F('user__first_name'),
        obj_username=F('user__username'))
    write_up_list = []
    tash_list = []
    # for task in task_arrary:
    #     task_hash = str(task.task_hash)
    #
    #     write_up_di_lict = Note.objects.filter(resource=task_hash)
    #     tash_list.append(task_hash)
    #     write_up_list.append(write_up_di_lict)

    queryset = queryset.annotate(
        start_time=Min('submit_time'),
        sum_score=Sum('score'),
        submit_time=Max('submit_time'),
    ).order_by('-sum_score', 'submit_time')

    for qs in queryset:
        note = Note.objects.filter(resource=events.hash,
                                   user_id=qs['obj_id']).first()
        wr_score = qs['sum_score']
        if note:
            qs['sum_score'] = wr_score + note.score
            qs['writeup_score'] = note.score

    wb = xlwt.Workbook(encoding='utf-8')
    sheet = wb.add_sheet('考试结果')
    pattern = xlwt.Pattern()  # Create the Pattern
    pattern.pattern = xlwt.Pattern.SOLID_PATTERN  # May be: NO_PATTERN, SOLID_PATTERN, or 0x00 through 0x12
    pattern.pattern_fore_colour = 5  # 0 = Black, 1 = White, 2 = Red, 3 = Green, 4 = Blue, 5 = YelloW
    borders = xlwt.Borders()  # Create Borders
    borders.left = xlwt.Borders.THIN  # NO_LINE, THIN, MEDIUM, DASHED, DOTTED, THICK, DOUBLE,
    borders.right = xlwt.Borders.THIN
    borders.top = xlwt.Borders.THIN
    borders.bottom = xlwt.Borders.THIN
    style_border = xlwt.XFStyle()  # Create Style
    style_border_color = xlwt.XFStyle()
    style_border.borders = borders  # Add Borders to Style
    style_border_color.borders = borders
    style_border_color.pattern = pattern
    sheet = excelHead(sheet, context, style_border, style_border_color)
    sheet = excelContent(sheet, queryset, style_border)

    wb.save('report.xls')
    sio = StringIO.StringIO()
    wb.save(sio)
    sio.seek(0)
    response = HttpResponse(sio.getvalue(),
                            content_type='application/vnd.ms-excel')
    response['Content-Disposition'] = 'attachment; filename=report.xls'
    response.write(sio.getvalue())
    return response