예제 #1
0
파일: views.py 프로젝트: SzymonKreta/myrepo
def buy(request,thread_id):
    if request.method == 'POST':
        aform=AnnouncementForm(request.POST,request.FILES)
        print "here i'am"
        print "here i'am"  
        thread=Thread.objects.filter(id=thread_id)
        print thread_id		
        #return HttpResponseRedirect('/mysite/mainsite/')
        announcement=aform.save(commit=False)
        announcement.user=request.user
        announcement.is_active=True
        announcement.thread=thread[0]
        #announcement.photo=''
        announcement.save()
        print "here i'am"
        
        announcements=Announcement.objects.filter(thread__id=thread_id)
        return render_to_response('mainsite.html',{"announcement":announcements,"aform":aform,"thread":thread},context_instance=RequestContext(request))
    else:
        aform=AnnouncementForm()
        print "thread_id"
        print thread_id
        thread=Thread.objects.filter(id=thread_id)
        print thread[0].name
        announcements=Announcement.objects.filter(thread__id=thread_id)
    return render_to_response('mainsite.html',{"announcement":announcements,"aform":aform,"thread":thread[0]},context_instance=RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: SzymonKreta/myrepo
def addAnnouncement(request):
	if request.method=="POST":
		form=AnnouncementForm(request.POST,request.FILES)
		recaptcha=RecaptchaForm(request.POST)
		if form.is_valid() and recaptcha.is_valid():
			announcement=form.save()
			return HttpResponseRedirect("/thanks/")
	else:
		form=AnnouncementForm()
		recaptcha=RecaptchaForm(request.POST)
	return render_to_response("addAnnouncement.html",{'form':form,"recaptcha":recaptcha,},context_instance=RequestContext(request))
예제 #3
0
파일: views.py 프로젝트: maggie98choy/MOOC
def addAnnouncement(request):
    config = ConfigParser.ConfigParser()
    config.read('moo.ini')
				
    host = config.get("bottle","host")
    port = config.get("bottle","port")
	
    template = 'welcome.html'
    params = {'':''}
	
    if request.method == 'POST':
	form = AnnouncementForm(request.POST)		
		
	if form.is_valid():
	    	
	    addupdatestatus = request.POST['addupdatestatus']
	    courseid = request.POST['courseid']
	    title = request.POST['title']
	    description= request.POST['description']
	    postDate = request.POST['postDate']
	    #attachment = request.POST['attachment']	
	    status = request.POST['status']	
	
	    #new course -courseid = 0
	    #update course - courseid !=0
	    
	    if addupdatestatus =='0':
		url='http://'+host+':'+port+'/announcement'
		method = 'POST'
	    else:
		args = {'id':courseid}
		encoded_args = urllib.urlencode(args)
		url='http://'+host+':'+port+'/announcement/update/id?' + encoded_args
		method = 'PUT'			

	    args = {'courseid':courseid,'title':title,'description':description,'postDate':postDate,'status':status}

	    encoded_args = urllib.urlencode(args)
	    request = urllib2.Request(url,encoded_args)
	    request.get_method = lambda: method
			   
			
	    try: 
		response = urllib2.urlopen(request)	
		r=response.read()
		template = 'welcome.html'
		result=json.loads(r)
		cid = result['id']
		
		params = {'result':'Announcement is added/updated succesfully! Announcement id:'+cid}
					
	    except urllib2.HTTPError, e:
		template = 'announcement/announcement.html'
		params = {'result':'Server error, try later'}
		
	else:
	    print 'Invalid form entered. Populate data on form.'
	    courseid = request.POST['courseid']
	    title = request.POST['title']
	    description = request.POST['description']
	    postDate = request.POST['postDate']
	    status = request.POST['status']
	    
	    params = {'courseid':courseid,'title':title,'description':description,'postDate':postDate,'status':status}
	    template = 'announcement/announcement.html'