コード例 #1
0
ファイル: views.py プロジェクト: juliangay/ticker-tape
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)) 
コード例 #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})
コード例 #3
0
ファイル: source.py プロジェクト: mike-matera/SignupSheetPy
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})
コード例 #4
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
        })
コード例 #5
0
ファイル: source.py プロジェクト: mike-matera/SignupSheetPy
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})