def set_working_tree(self, working_tree): self.unset_current_working_tree() new_working_tree, created = Config.get_or_create(**{ 'type': 'working_tree', 'status': 0, 'data': working_tree.replace('%', '*') }) new_working_tree.status = 1 new_working_tree.save()
def load_function(self, name, function_source): if not is_identifier(name): raise NameError('{} invalid identifier for python module'.format(name)) new_function, created = Config.get_or_create(**{ 'type': 'function', 'status': 0, 'name': name, 'data': function_source }) return new_function, created
def save_task_item(request, item, task): ''' get field and subfield data from the request and save to an item ''' greenstone_conf = Config.get_or_create("greenstone") fields_images = [] for key, field, value, sfields, tema3 in task.write_item_fields(): id = field['id'] fields = item.fields_properties[id] if fields['type'] == 'int': field_value = [int(i) for i in request.POST.getlist(id)] elif fields['type'] == 'image': #TODO: validate type of file images = [i for i in request.FILES.getlist(id)] fields_images += images field_value = [i.name for i in request.FILES.getlist(id)] elif fields['type'] == 'greenstone': template = greenstone_conf.values['template'] expanded_template = template tags = { '%item_type%': item.item_type, '%date%': time.strftime("%Y-%m-%d"), '%urn%': item.urn, } for key, value in tags.iteritems(): expanded_template = expanded_template.replace(key, value) full_path = os.path.join(greenstone_conf.values['upload_path'], expanded_template) if expanded_template.count("/"): try: os.makedirs(os.path.dirname(full_path)) except OSError: # includes errno.EEXIST pass with open(full_path, 'wb') as fp: for chunk in request.FILES[id].chunks(): fp.write(chunk) field_value = expanded_template else: field_value = request.POST.getlist(id) fields.first['exec_value'] = field_value for i in [1, 2]: attrname = "indicator%s" % i value = request.POST.get("%s_%s" % (id, attrname), '') fields.first[attrname] = value if sfields: for sf, value in sfields: sfs_data = request.POST.getlist('sf_' + id + '_' + sf['field_name']) try: fields.first['subfields']\ [sf['field_name']]['exec_value'] = sfs_data except KeyError: pass for field in request.POST.getlist("reference_input"): fid, sfid, _, value = simplejson.loads(field) fields = item.fields_properties[fid] if not sfid: fields.first['exec_value'] = value else: fields.first['subfields'][sfid]['exec_value'] = value return fields_images
def save_task_item(request, item, task): ''' get field and subfield data from the request and save to an item ''' greenstone_conf = Config.get_or_create("greenstone") fields_images = [] for key, field, value, sfields, tema3 in task.write_item_fields(): id = field['id'] fields = item.fields_properties[id] if fields['type'] == 'int': field_value = [int(i) for i in request.POST.getlist(id)] elif fields['type'] == 'image': #TODO: validate type of file images = [i for i in request.FILES.getlist(id)] fields_images += images field_value = [i.name for i in request.FILES.getlist(id)] elif fields['type'] == 'greenstone': template = greenstone_conf.values['template'] expanded_template = template tags = { '%item_type%': item.item_type, '%date%': time.strftime("%Y-%m-%d"), '%urn%': item.urn, } for key, value in tags.iteritems(): expanded_template = expanded_template.replace(key, value) full_path = os.path.join(greenstone_conf.values['upload_path'], expanded_template) if expanded_template.count("/"): try: os.makedirs(os.path.dirname(full_path)) except OSError: # includes errno.EEXIST pass with open(full_path, 'wb') as fp: for chunk in request.FILES[id].chunks(): fp.write(chunk) field_value = expanded_template else: field_value = request.POST.getlist(id) fields.first['exec_value'] = field_value for i in [1, 2]: attrname = "indicator%s" % i value = request.POST.get("%s_%s" % (id, attrname), '') fields.first[attrname] = value if sfields: for sf, value in sfields: sfs_data = request.POST.getlist( 'sf_'+id+'_'+sf['field_name']) try: fields.first['subfields']\ [sf['field_name']]['exec_value'] = sfs_data except KeyError: pass for field in request.POST.getlist("reference_input"): fid, sfid, _, value = simplejson.loads(field) fields = item.fields_properties[fid] if not sfid: fields.first['exec_value'] = value else: fields.first['subfields'][sfid]['exec_value'] = value return fields_images
def _get_config(): _config, created = Config.get_or_create(name='password', defaults={'value': 'dummy'}) return _config