def delete_upload(req): pid = req.GET.get('pid', 0) try: parsed = ParsedData.objects.get(pk=int(pid)) utils.cleanup(parsed) return render_json(req, {'success': True, 'msg': _('Data deleted')}) except Exception as e: msg = _('Failed: {}').format(str(e)) return render_json(req, {'success': False, 'msg': msg})
def save_coords(req): try: fs = FloorStorage.objects.get(pk=int(req.GET['sid'])) fs.x = int(req.GET['x']) fs.y = int(req.GET['y']) fs.save() return render_json(req, {'message': _('<b>Position saved</b>')}) except Exception as err: error = _('Error: {}').format(err) return render_json(req, {'message': error})
def save_basics(req): try: pk = int(req.GET.get('id', 0)) up = UploadedMSDS.objects.get(pk=pk) except Exception as e: msg = _('Failed: {}').format(str(e)) return render_json(req, {'success': False, 'msg': msg}) up.name = req.GET.get('name', up.name) up.cas = req.GET.get('cas', up.cas) up.save() return render_json(req, {'success': True, 'msg': _('Saved')})
def select_chemical(req): search = req.POST['search'] results = [] chems = search_chemical_by_name(search) for chem in chems: text = '{}, CAS: {}'.format(chem.formula or '-', chem.identifiers.cas or '-') results.append( dict(title=chem.display_name, text=text, url=reverse('oic:new', kwargs={'chem_id': chem.id}))) return render_json(req, {'results': results})
def get_related_text(req, chem_id): topic = req.GET.get('topic', '') chemical = Chemical.objects.select_related().get(pk=chem_id) pic_ids = list(chemical.pictograms.all().values_list('id', flat=True)) data = dict(same=[], similar=[]) for entry in OperatingInstructionDraft.objects.filter( chemical=chemical).values_list(topic, flat=True): if entry.strip(' -') and entry not in data['same']: data['same'].append(entry) for entry in OperatingInstructionDraft.objects.select_related().filter( chemical__pictograms__id__in=pic_ids).exclude( chemical=chemical).values_list(topic, flat=True): if entry.strip(' -') and entry not in data['similar']: data['similar'].append(entry) if not data['same']: data['same'].append('-') if not data['similar']: data['similar'].append('-') return render_json(req, data)