Exemplo n.º 1
0
def source_create(request, template_name='source/source_form.html'):
    if request.method == 'POST':
        form = SkipperForm(request.POST)
        if form.is_valid():
            source = Source()
            source.text = form.cleaned_data['text']
            source.title = form.cleaned_data['title']
            source.owner = request.user.first_name + ' ' + request.user.last_name
            source.save()

            # Now build it.
            build(user=request.user, sourceobj=source)

            cache.clear()
            return redirect('source_list')
        else:
            return render(request, template_name, {'form': form})
    else:
        default = '''
coordinator "Name" "Email" "Url"
contact "Email"
description {
}
    '''
        form = SkipperForm({'text': default, 'title': 'New Role'})
        return render(request, template_name, {'form': form})
Exemplo n.º 2
0
def source_create(request, template_name='source/source_form.html'):
    if request.method == 'POST' :
        form = SkipperForm(request.POST)
        if form.is_valid():
            source = Source()
            source.text = form.cleaned_data['text']
            source.title = form.cleaned_data['title']
            source.owner = request.user.first_name + ' ' + request.user.last_name
            source.save()
        
            # Now build it.
            build(user=request.user, sourceobj=source)

            cache.clear()
            return redirect('source_list')
        else:
            return render(request, template_name, {'form':form})            
    else:
        default = '''
coordinator "Name" "Email" "Url"
contact "Email"
description {
}
    ''' 
        form = SkipperForm( {'text': default, 'title': 'New Role'} )    
        return render(request, template_name, {'form':form})
Exemplo n.º 3
0
    def test_form_template(self):
        template_params =  {
                'name' : 'page12.html',
                'content' : 'test'
            }

        template = Template(**template_params)
        template.save()

        source_params = {
                'source' : 'test-source',
                'slug' : 'test-source'
                }

        source = Source(**source_params)
        source.save()

        form_params = {
            'name' : 'test',
            'slug' : 'test',
            'template' : template,
            'form_type' : source,
            'height' : '100',
            'width' : '200'
            }

        form = ContactForm(**form_params)

        embed_code = """<iframe style="border: none; 
        overflow: hidden;" src="page12.html" frameborder="0" 
        scrolling="no" width="200" height="100"></iframe>"""

        assert form.embed_code == embed_code, True
Exemplo n.º 4
0
def upload_opml_file(request):
    if request.method == 'POST':
        form = UploadOpmlFileForm(request.POST, request.FILES)
        if form.is_valid():
        	#opml_file = request.FILES['file'].read()
        	#tree = ET.parse(opml_file)
        	#root = tree.getroot()
        	#for outline in root.iter('outline'):
			#	source = Source(user=request.user, xml_url=outline.get('xmlUrl'))
			#	source.save()

			Source.objects.all().delete()
			Group.objects.all().delete()

			group = None
			for event, elem in ET.iterparse(request.FILES['file']):
				#import pdb; pdb.set_trace()
				if elem.tag == 'body':
					outlines = list(elem)

					for outline in outlines:
						if 'xmlUrl' not in outline.attrib:
							group = Group(user=request.user, name=outline.attrib['title']) 
							group.save()

							children = list(outline)
							for child in children:
								source = Source()
								source.text = child.attrib['text']
								source.title = child.attrib['title']
								source.feed_type = child.attrib['type'] 
								source.xml_url = child.attrib['xmlUrl']
								source.html_url = child.attrib['htmlUrl']
								source.save()

								user_source = UserSource(user=request.user, source=source, group=group)
								user_source.save()		
						elif 'xmlUrl' in outline.attrib:
							print outline.attrib
							source = Source()
							source.text = outline.attrib['text']
							source.title = outline.attrib['title']
							source.feed_type = outline.attrib['type'] 
							source.xml_url = outline.attrib['xmlUrl']
							source.html_url = outline.attrib['htmlUrl']
							source.save()	

							user_source = UserSource(user=request.user, source=source)
							user_source.save()		

			return HttpResponseRedirect( reverse('entries') )
    else:
        form = UploadOpmlFileForm()

    return render_to_response('feeds/upload_opml.html', {'form': form}, context_instance=RequestContext(request)) 
Exemplo n.º 5
0
    def enterRole(self, ctx):
        title = self.__strToken(ctx.QUOTE())

        inputstream = ctx.start.getInputStream()
        start = ctx.getChild(3).start.start
        stop = ctx.getChild(3).stop.stop
        text = inputstream.getText(start, stop)
        
        src = Source(title=title, text=text, 
                    owner=self.user.first_name + ' ' + self.user.last_name,
                    ) 
        src.save()
        self.context.append(src)
Exemplo n.º 6
0
    def enterRole(self, ctx):
        title = self.__strToken(ctx.QUOTE())

        inputstream = ctx.start.getInputStream()
        start = ctx.getChild(3).start.start
        stop = ctx.getChild(3).stop.stop
        text = inputstream.getText(start, stop)

        src = Source(
            title=title,
            text=text,
            owner=self.user.first_name + ' ' + self.user.last_name,
        )
        src.save()
        self.context.append(src)
Exemplo n.º 7
0
def source_update(request, pk, template_name='source/source_form.html'):

    next_page = request.GET.get('next', None)
    source = Source.objects.get(title=pk)
    if source == None:
        raise Http404("Source does not exist")

    if request.method == 'POST':
        form = SkipperForm(request.POST)
        if form.is_valid():

            try:
                with transaction.atomic():
                    # There is no update, sources must be deleted and remade.
                    # on_delete=CASCADE is emulated, but it works when my objects don't suck.
                    source.delete()

                    # Create a new one
                    source = Source()
                    source.title = pk
                    source.text = form.cleaned_data['text']
                    source.owner = request.user.first_name + ' ' + request.user.last_name
                    source.save()

                    # Now build it.
                    build(user=request.user, sourceobj=source)
            except IntegrityError as e:
                print "Transaction error:", e

            cache.clear()
            if form.cleaned_data['next'] != "":
                return redirect('jobs', form.cleaned_data['next'])
            else:
                return redirect('source_list')
        else:
            return render(request, template_name, {
                'title': pk,
                'form': form,
                'next': next_page
            })

    else:
        form = SkipperForm({'text': source.text, 'title': source.title})
        return render(request, template_name, {
            'title': pk,
            'form': form,
            'next': next_page
        })
Exemplo n.º 8
0
def clone_cohort(request, cohort_id):
    if debug: print >> sys.stderr,'Called '+sys._getframe().f_code.co_name
    redirect_url = 'cohort_details'
    parent_cohort = Cohort.objects.get(id=cohort_id)
    new_name = 'Copy of %s' % parent_cohort.name
    cohort = Cohort.objects.create(name=new_name)
    cohort.save()

    # If there are sample ids
    samples = Samples.objects.filter(cohort=parent_cohort).values_list('sample_id', 'study_id')
    sample_list = []
    for sample in samples:
        sample_list.append(Samples(cohort=cohort, sample_id=sample[0], study_id=sample[1]))
    Samples.objects.bulk_create(sample_list)

    # TODO Some cohorts won't have them at the moment. That isn't a big deal in this function
    # If there are patient ids
    patients = Patients.objects.filter(cohort=parent_cohort).values_list('patient_id', flat=True)
    patient_list = []
    for patient_code in patients:
        patient_list.append(Patients(cohort=cohort, patient_id=patient_code))
    Patients.objects.bulk_create(patient_list)

    # Clone the filters
    filters = Filters.objects.filter(resulting_cohort=parent_cohort).values_list('name', 'value')
    # ...but only if there are any (there may not be)
    if filters.__len__() > 0:
        filters_list = []
        for filter_pair in filters:
            filters_list.append(Filters(name=filter_pair[0], value=filter_pair[1], resulting_cohort=cohort))
        Filters.objects.bulk_create(filters_list)

    # Set source
    source = Source(parent=parent_cohort, cohort=cohort, type=Source.CLONE)
    source.save()

    # Set permissions
    perm = Cohort_Perms(cohort=cohort, user=request.user, perm=Cohort_Perms.OWNER)
    perm.save()

    # Store cohort to BigQuery
    project_id = settings.BQ_PROJECT_ID
    cohort_settings = settings.GET_BQ_COHORT_SETTINGS()
    bcs = BigQueryCohortSupport(project_id, cohort_settings.dataset_id, cohort_settings.table_id)
    bcs.add_cohort_with_sample_barcodes(cohort.id, samples)

    return redirect(reverse(redirect_url,args=[cohort.id]))
Exemplo n.º 9
0
def source_update(request, pk, template_name='source/source_form.html'):    

    next_page = request.GET.get('next', None)
    source = Source.objects.get(title=pk)
    if source == None :
        raise Http404("Source does not exist")

    if request.method=='POST':
        form = SkipperForm(request.POST)
        if form.is_valid():
        
            try: 
                with transaction.atomic() :
                    # There is no update, sources must be deleted and remade.
                    # on_delete=CASCADE is emulated, but it works when my objects don't suck. 
                    source.delete()

                    # Create a new one 
                    source = Source()
                    source.title = pk
                    source.text = form.cleaned_data['text']
                    source.owner = request.user.first_name + ' ' + request.user.last_name
                    source.save()
        
                    # Now build it.
                    build(user=request.user, sourceobj=source)
            except IntegrityError as e:
                print "Transaction error:", e
        
            cache.clear()
            if form.cleaned_data['next'] != "" : 
                return redirect('jobs', form.cleaned_data['next'])
            else:
                return redirect('source_list')
        else:
            return render(request, template_name, {'title': pk, 'form':form, 'next': next_page})

    else:
        form = SkipperForm({'text': source.text, 'title': source.title})
        return render(request, template_name, {'title': pk, 'form': form, 'next': next_page})
Exemplo n.º 10
0
def save_idea(form):
    # process data in form.cleaned_data
    title = form.cleaned_data['title']
    title_nospaces = str(title.replace(' ', '_').lower())
    status = form.cleaned_data['status']
    short_desc = form.cleaned_data['short_desc']
    long_desc = form.cleaned_data['long_desc']
    date_formed = form.cleaned_data['date_formed']
    links_strings = form.cleaned_data['links'].split(',')
    tags_strings = form.cleaned_data['tags'].split(',')
    sources_strings = form.cleaned_data['sources'].split(',')
    images_strings = form.cleaned_data['images'].split(',')
    # save new idea with cleaned form data
    new_idea = Idea(title=title,status=status,short_desc=short_desc,
		    long_desc=long_desc,date_formed=date_formed)
    new_idea.save()
    # add links, tags, sources, and images
    for link in links_strings:
	new_link = Link(url=link)
	new_link.save()
	new_idea.links.add(new_link)
    for tag in tags_strings:
	new_tag = Tag(tag=tag)
	new_tag.save()
	new_idea.tags.add(new_tag)
    for source in sources_strings:
	new_source = Source(source=source)
	new_source.save()
	new_idea.sources.add(new_source)
    for image in images_strings:
	new_image = Image(url=image)
	new_image.save()
	new_idea.images.add(new_image)
    # save after adding data
    new_idea.save()
    return title
Exemplo n.º 11
0
def install():
    print("installing templates...")
    for template_data in templates:
        print("\t{}".format(template_data['name']))
        t = Template(template_data)
        t.save()

    print("installing source texts...")
    for source_filename in source_filenames:
        source_path = path.join(path.dirname(__file__), 'static/txt', source_filename)
        print("\treading {}".format(source_path))
        text = open(source_path).read()
        s = Source({'name':source_filename,
                    'text':text,
                    'uploader': cfg.SYSTEM_USER})
        print("\tprocessing {}".format(source_path))
        s.process()
        print("\tsaving {}".format(source_path))
        s.save()

    print('adding system user')
    u = User({'name':cfg.SYSTEM_USER,
              'password': ''})
    u.save()
Exemplo n.º 12
0
    try:
        source_method = SourceMethod.objects.get(method_name=s_method)
    except SourceMethod.DoesNotExist:
        print 'bad method:', s_method
        sys.exit(1)
except SourceMethod.DoesNotExist:
    print 'bad method id:', s_method
    sys.exit(1)

try:
    ref = Ref.objects.get(refID=refID)
except Ref.DoesNotExist:
    print refID,'does not exist in Ref table!'
    sys.exit(1)
print ref.refID, ref.title

try:
    source_type = SourceType.objects.get(source_type=ref.ref_type)
except SourceType.DoesNotExist:
    print ref.ref_type,'does not exist in SourceType table!'
    sys.exit(1)

source = Source(refID=refID, source_type=source_type, authors=ref.authors,
                title=ref.title, title_html=ref.title_html, journal=ref.journal,
                volume=ref.volume, page_start=ref.page_start,
                page_end=ref.page_end, year=ref.year, institution=ref.institution,
                note=ref.note, note_html=ref.note_html, doi=ref.doi,
                cited_as_html=ref.cited_as_html, url=ref.url,
                method=source_method)
source.save()