def post(self, request): status = 'ok' error = [0, ''] url = '' if request.user.is_authenticated(): room = request.POST.get('room', '') time = request.POST.get('time', '') date = request.POST.get('date', '') try: r = Room.objects.get(id=room) t = Time.objects.get(id=time) students = Student.objects.filter(room=r) except: status = 'fail' error = [110, 'error con la integridad de los datos de la db'] else: #try: zip_name = (r.name + '_logs.zip').replace(' ', '_').lower() zip_file_path = os.path.join(settings.MEDIA_ROOT + settings.STUDENT_LOG_DIR, zip_name) zip_file = zipfile.ZipFile(zip_file_path, 'w') url = os.path.join(settings.STUDENT_LOG_URL, zip_name) for item in students: pdf_name = (item.get_name_complete() + '.pdf').replace(' ', '_').lower() pdf_file_path = os.path.join(settings.MEDIA_ROOT + settings.STUDENT_LOG_DIR, pdf_name) pdf = Log(pdf_file_path) pdf.time = t.name.upper().encode('UTF-8', 'ignore') + ' 2014' pdf.student_name = '%s %s' % (item.lastname, item.name) pdf.date = datetime.datetime.strptime(date, '%Y-%m-%d').strftime('%d/%m/%Y') pdf.grade = r.grade.name pdf.group = r.group.name pdf.director = item.user.get_full_name() for i in range(0,50): pdf.drawExample() pdf.drawCommentBox() pdf.drawSignature() pdf.render() zip_file.write(pdf_file_path, pdf_name) zip_file.close() #except: # status = 'fail' # error = [100, 'error generando el PDF'] else: status = 'fail' error = [401, 'permiso denegado'] return HttpResponse(json.dumps({'status':status, 'error':error, 'file_url':url}), content_type='application/json')
def normalize(self, normalizer, timestamp=-1, interval=-1, is_log=True, debug_context=False, normalized_logs=None): last_valid_time = 0 min = timestamp - interval max = timestamp + interval for line in self.raw: if not is_log: self.data.append(normalizer.normalize({'raw': line[:-1] if not self.content else line})) else: l = Log(self, normalizer.normalize({'raw': line[:-1] if not self.content else line})) if not l.date: l.date = last_valid_time else: last_valid_time = l.date if timestamp == -1 or interval == -1 or l.is_in_interval((min, max)): self.data.append(l) if normalized_logs: # increase current number of normalized logs normalized_logs['number'] += 1 # increase chunk counter if needed, seen by load display thread if normalized_logs['number'] % normalized_logs['chunk_size'] == 0: normalized_logs['current_chunk'] += 1 return self