def psn_group_name(title): # a special group_name maker algorithm for psn # compresses MHPSS mhps = 'Mental Health and Psychosocial' if mhps in title: title = re.sub(mhps, 'mhpss', title) mhps = "Mental health and psychosocial" if mhps in title: title = re.sub(mhps, 'mhpss', title) r = re.compile('(.*?) Hosts$') m = r.match(title) if m: host_flag = True title = m.group(1) else: host_flag = False s = make_name(title) if len(s) > 33: s = s[:33] if host_flag: s = s + "_hosts" return s
def psn_group_name(title) : # a special group_name maker algorithm for psn # compresses MHPSS mhps = 'Mental Health and Psychosocial' if mhps in title : title = re.sub(mhps,'mhpss',title) mhps = "Mental health and psychosocial" if mhps in title : title = re.sub(mhps,'mhpss',title) r = re.compile('(.*?) Hosts$') m = r.match(title) if m : host_flag = True title = m.group(1) else : host_flag = False s = make_name(title) if len(s) > 33 : s = s[:33] if host_flag : s = s + "_hosts" return s
def clean_name(self): name = self.cleaned_data['name'] group_name=make_name(name) if TgGroup.objects.filter(group_name=group_name): raise forms.ValidationError(_("We already have a group with this name.")) self.cleaned_data['display_name'] = name self.cleaned_data['group_name'] = group_name return group_name
def import_group(f_name, group_type, fn_place) : groups = pickle.load(open(f_name)) admin = get_admin_user() site = get_site(admin) for g in groups: print g.keys() #print g['groupname'], g['body'], g['description'],g['joinpolicy'] if g['joinpolicy']== 'open' : permission_prototype='public' else : permission_prototype='private' description = "" if g['description'] : description = description + g['description'] if g['body'] : description = description + g['body'] if description == "" : description = 'About this group' group_name = make_name(g['groupname']) if len(group_name)>30 : group_name = group_name[30] display_name = g['groupname'] psn_id = g['uid'] keywords = g['keywords'] print group_name, display_name, psn_id, permission_prototype print description print keywords groups = TgGroup.objects.filter(group_name=group_name) if groups : group = groups[0] else : group = site.create_TgGroup( group_name = group_name, display_name = display_name, group_type = group_type , level = 'member', user = admin, description = description, permission_prototype = permission_prototype, ) group = group.get_inner() group.psn_id = psn_id group.place = fn_place(g) group.save()
def create_resource(top_container, creator, title_and_type, f_name, folder, tags=[]) : title = title_and_type.split('/')[-1] title = title.split('.',1)[0] name = make_name(title) print "Title %s, name %s, created by %s" % (title,name,creator.username) desc = '' license = 'not specified' author = '' try : f = File(open('mhpss_export/files/%s'%f_name,'rb')) except Exception, e: # in at least one case we seem to have a zip file instead of the file refered in the data f_name = swap_extension(f_name,'zip') f = File(open('mhpss_export/files/%s'%f_name,'rb'))
def create_resource(top_container, creator, title_and_type, f_name, folder, tags=[]): title = title_and_type.split('/')[-1] title = title.split('.', 1)[0] name = make_name(title) print "Title %s, name %s, created by %s" % (title, name, creator.username) desc = '' license = 'not specified' author = '' try: f = File(open('mhpss_export/files/%s' % f_name, 'rb')) except Exception, e: # in at least one case we seem to have a zip file instead of the file refered in the data f_name = swap_extension(f_name, 'zip') f = File(open('mhpss_export/files/%s' % f_name, 'rb'))
def create_resource(top_container, creator, val, f_name, folder) : try : print "Created by %s" % creator title = val.split('.',1)[0] name = make_name(title) print "Title %s, name %s" % (title,name) desc = '' license = 'Copyright 2009, Psychosocial Network' author = '' f = File(open('mhpss_export/files/%s'%f_name,'rb')) resource = get_or_create(creator, top_container, resource=f, title=val, name=name, description=desc, license=license, author=author, stub=False) resource.save() f.close() tag_with_folder_name(resource, creator, folder['title'], 'folder') return True except Exception, e: print "******%s",e return False
def test_make_name(self): self.assertEquals(make_name('hello world'),u'hello_world')