def submit_image(request): if request.user.is_authenticated(): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() file = request.FILES['docfile'] work_dir = '/home/NANOMINE/Production/mdcs' os.chdir(work_dir) os.system('pwd') user_email_id = request.POST['email_id'] if not user_email_id: return HttpResponse( '<h3>Please provide an email address to receive Job ID!</h3>' ) #if no email id was provided, report error input_type = request.POST['Characterize_input_type'] if input_type == "1": if not str(file).endswith(".jpg"): if not str(file).endswith(".JPG"): if not str(file).endswith(".tif"): if not str(file).endswith(".png"): if not str(file).endswith(".PNG"): if not str(file).endswith(".TIF"): return HttpResponse( '<h3>Please upload a JPEG file</h3>' ) #report wrong file format elif input_type == "2": if not str(file).endswith(".zip"): return HttpResponse('<h3>Please upload ZIP file</h3>' ) #report wrong file format else: if not str(file).endswith(".mat"): return HttpResponse('<h3>Please upload .mat file</h3>' ) #report wrong file format user_name = None user_name = request.user.username num_recon = request.POST['num_recon'] correlation_choice = request.POST['correlation_choice'] # Run MATLAB when file is valid os.system( 'matlab -nodesktop -nodisplay -nosplash -r "cd /home/NANOMINE/Production/mdcs/Two_pt_MCR/mfiles;run_2ptMCR(\'"' + str(user_name) + '"\',"' + str(num_recon) + '","' + str(input_type) + '","' + str(correlation_choice) + '",\'"' + str(file) + '"\');exit"') #if user_email_id: mail_to_user = '******' + user_email_id + ' < /home/NANOMINE/Production/mdcs/Two_pt_MCR/email.html' os.system(mail_to_user) os.system( 'sendmail [email protected] < /home/NANOMINE/Production/mdcs/Two_pt_MCR/email.html' ) form = DocumentForm() documents = Document.objects.all() return render_to_response( 'Two_pt_MCR_submission_notify.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request)) else: form = DocumentForm() documents = Document.objects.all() return HttpResponse('<h3>Please upload an image!</h3>' ) # if no image was uploaded, report error else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render_to_response('Two_pt_MCR_submit_image.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request)) else: return redirect('/login')
def user_list(request): temp_name = "accounts/accounts-header.html" all_user = get_user_model().objects.all() return render_to_response('accounts/user_list.html', locals(), RequestContext(request))
def get(self, request, *args, **kwargs): return render_to_response('inicio/index.html', context_instance=RequestContext(request))
def index(request): # return HttpResponse("Hello, world! This is our first view.") return render_to_response("index.html", locals(), context_instance=RequestContext(request))
def portfolio(request): return render_to_response("portfolioMain.html", locals(), context_instance=RequestContext(request))
def thanks_view(request): """ success view for add_activity """ return render_to_response('thanks.html', context_instance=RequestContext(request))
def privacy(request): return render_to_response("privacy.html", locals(), context_instance=RequestContext(request))
def my_render(template, data, request): return render_to_response(template, data, context_instance=RequestContext(request))
def EditQuestion(request, question_slug='', **kwargs): #def inline_formset(request, form_class, template): template = 'edit_question.html' MultipleChoiceAnswerItemFormset = inlineformset_factory( MultipleChoiceQuestion, MultipleChoiceAnswerItem, form=MultipleChoiceAnswerItemModelForm, formset=MultipleChoiceAnswerItemModelFormset, extra=1, can_delete=True) theQuestion = MultipleChoiceQuestion.objects.get(slug=question_slug) # if POST the user submitted changes to the question. So validate and save to DB if request.method == 'POST': form = MultipleChoiceQuestionModelForm(request.POST, prefix="Question", instance=theQuestion) formset = MultipleChoiceAnswerItemFormset(request.POST, prefix="Answer", instance=theQuestion) is_question_form_valid = form.is_valid() is_answer_formset_valid = formset.is_valid() if is_question_form_valid and is_answer_formset_valid: try: form.save() formset.save() except (DatabaseError, IntegrityError) as e: return DefaultErrorPage( e, mesg= "Could not save your changes to the question due to a database error. Try again later." ) #redirect to the show the updated question return HttpResponseRedirect( reverse('ShowQuestionDetails', kwargs={'question_slug': question_slug})) else: #form is invalid, re-render form with errors return render_to_response(template, { 'form': form, 'formset': formset, 'question': theQuestion, 'add_or_edit': 'edit' }, context_instance=RequestContext(request)) #handle GET #render the form else: form = MultipleChoiceQuestionModelForm(prefix="Question", instance=theQuestion) formset = MultipleChoiceAnswerItemFormset(prefix="Answer", instance=theQuestion) return render_to_response(template, { 'form': form, 'formset': formset, 'question': theQuestion, 'add_or_edit': 'edit' }, context_instance=RequestContext(request))
user=a.username, passwd=a.password, port=int(a.port), cmd=None) for k, v in uf.items(): file_name = k rev = p.Localupload(file_name, s_path=v) re_li.append(rev) msg = u'上传目录: %s 共%d个 成功%d个' % (upload_dir, len(upload_files), count) return HttpResponse(msg) except Exception, e: error = "上传失败,请确认主机信息是否错误:%s" % (str(e)) return HttpResponse(error) #print re_li return render_to_response('upload.html', kwvars, RequestContext(request)) @login_required @Is_not_admin() def Filedownload(request): asset = Hostupload(request) if asset: kwvars = {'request': request, 'assets': asset} else: kwvars = {'request': request} if request.method == 'POST': from os import path file_path = request.POST.get('file_path') assets = request.POST.getlist('assets', '') if not file_path or not assets:
def Index_cu(request): kwvars = {'request': request} return render_to_response('index_cu.html', kwvars, RequestContext(request))
def movie_detail(request, movieId): payload = {'movie': Movie.objects.get(imdbId=movieId)} return render_to_response('movie/movieDetail.html', payload, context_instance=RequestContext(request))
def author(req): if req.method == 'POST': data = req.POST print data return render_to_response('books/author.html', locals(), context_instance=RequestContext(req))
def patientview(request): patients=[] query=[] if request.method=="POST": searchform=SearchForm(request.POST) query = searchform.data['query'] if query: qset = ( Q(patientname__icontains=query) | Q(patientid__icontains=query) ) patients = Patient.objects.filter(qset).distinct() else: patients = Patient.objects.order_by('patientname') #patients = Patient.objects.order_by('-patientname') searchform=SearchForm() return render_to_response("patient.html",{"patients":patients,"searchform":searchform,"query":query},context_instance=RequestContext(request))
def jsimg(req): return render_to_response('js_img.html', RequestContext(req))
def LoginPage(request): theUser = request.user return render_to_response('LoginPage.html', {'theUser': theUser}, context_instance=RequestContext(request))
def activities_list(request, username=''): """ list of user activities """ args = {'activities': Activities.objects.filter(activities_user=username)} return render_to_response('activities.html', args, context_instance=RequestContext(request))
def AddQuestion(request, **kwargs): template = 'edit_question.html' theUser = request.user #inline formset is a good tool to use to get answers that have a foreign key to a question MultipleChoiceAnswerItemFormset = inlineformset_factory( MultipleChoiceQuestion, MultipleChoiceAnswerItem, form=MultipleChoiceAnswerItemModelForm, formset=MultipleChoiceAnswerItemModelFormset, extra=2, can_delete=True) #POST means user has submitted the form with new question and answer options if request.method == 'POST': #prefix helps distinguish forms from each other form = MultipleChoiceQuestionModelForm(request.POST, prefix='Question') formset = MultipleChoiceAnswerItemFormset(request.POST, prefix='Answer') if form.is_valid() and formset.is_valid(): try: #create new question but don't commit to DB yet as we have to #create the survey object first as the question has a foreign key to the survey object new_question = form.save(commit=False) #create new survey, for now each question has a survey object. no more than 1 question per survey for now new_survey = MultipleChoiceSurvey( create_date=datetime.datetime.now(), author=theUser) new_survey.save() the_new_id = new_survey.id new_question.linked_survey = MultipleChoiceSurvey.objects.get( id=the_new_id) new_question.save() new_question_in_db = MultipleChoiceQuestion.objects.get( id=new_question.id) new_answers = formset.save(commit=False) for a in new_answers: a.linked_question = new_question_in_db a.save() #To-do: need to actually do a rollback of all changes here upon getting an unlikely DB error #should use Django's atomic.transaction probably except (DatabaseError, IntegrityError) as e: return DefaultErrorPage( e, "Your question could not be saved due to some problem with the database. Please try again later." ) #redirect to ShowQuestionDetails when done adding a question return HttpResponseRedirect( reverse('ShowQuestionDetails', kwargs={'question_slug': new_question_in_db.slug})) else: #if form is not valid, i.e. the new question has a problem, just rerender the form with errors return render_to_response(template, { 'form': form, 'formset': formset, 'add_or_edit': 'add' }, context_instance=RequestContext(request)) # if method is GET show a blank form else: form = MultipleChoiceQuestionModelForm(prefix='Question') formset = MultipleChoiceAnswerItemFormset(prefix='Answer') return render_to_response(template, { 'form': form, 'formset': formset, 'add_or_edit': 'add' }, context_instance=RequestContext(request))
def index(request): """Index page""" return render_to_response('main.html', context_instance=RequestContext(request))
def admin(req): return HttpResponseRedirect('/admin/', RequestContext(req))
def blog(request): return render_to_response("blog.html", locals(), context_instance=RequestContext(request))
def collection(req): return render_to_response('my_collection.html', context_instance=RequestContext(req))
def about(request): return render_to_response("about.html", locals(), context_instance=RequestContext(request))
def warcraft(req): return render_to_response('warcraft.html', context_instance=RequestContext(req))
def PostView(request,ID): thisuser = GetUser(request) try: bpo = BlogPost.objects.get(id=ID) except BlogPost.DoesNotExist: kwvars = { "request":request, "ctlist":BlogCategoty.objects.all().order_by('order'), } return render_to_response('home/post.err.html',kwvars,RequestContext(request)) if not bpo.rendered: kwvars = { "request":request, "ctlist":BlogCategoty.objects.all().order_by('order'), } return render_to_response('home/post.err.html',kwvars,RequestContext(request)) if bpo.hidden: if not bpo.author == thisuser: if not PermCheck(request.auth,'pichublog','Admin'): kwvars = { "request":request, "ctlist":BlogCategoty.objects.all().order_by('order'), } return render_to_response('home/post.err.html',kwvars,RequestContext(request)) if bpo.private: if bpo.passwdlck: if request.method == "POST": if not request.POST.get('ppppppppaaaaaassssssssssssswwwwwooorrrrrdddd') == bpo.passwd: messages.error(request,u"<b>密码错误!</b>") return HttpResponseRedirect(reverse('pichublog_postpwdf',args=(bpo.id,))) else: return HttpResponseRedirect(reverse('pichublog_postpwdf',args=(bpo.id,))) else: pmh = False for hgp in thisuser.group: if hgp in bpo.readgrp: if not thisuser in bpo.readuex: pmh = True break if not pmh: if thisuser in bpo.readuin: pmh = True if not pmh: kwvars = { "request":request, "ctlist":BlogCategoty.objects.all().order_by('order'), } return render_to_response('home/post.err.html',kwvars,RequestContext(request)) if bpo.freecomment: pmhc = True else: pmhc = False for hgp in thisuser.group: if hgp in bpo.commentgrp: if not thisuser in bpo.commentuex: pmhc = True break if not pmhc: if thisuser in bpo.commentuin: pmhc = True kwvars = { "request":request, "bpo":bpo, "bkmode":False, "OutsiteCaptchaURL":OutsiteCaptchaURL(request), "ctlist":BlogCategoty.objects.all().order_by('order'), "crws":boolFastConfGet('CommentsReviewSwitch',default=True), "allowcmt":pmhc, } return render_to_response('home/post.view.html',kwvars,RequestContext(request))
def music(req): return render_to_response('music_rain.html', context_instance=RequestContext(req))
def user_del(request, ids): if ids: get_user_model().objects.filter(id=ids).delete() return HttpResponseRedirect(reverse('user_list'), RequestContext(request))
def index(req): print('in index') blogs = [] # 登录 if req.is_ajax(): username = req.POST.get("username", None) password = req.POST.get("password", None) if login_validate(req, username, password): response = render_to_response('index_new.html', RequestContext(req)) response.set_cookie('username', username, 3600) return response elif req.method == 'POST': content = req.POST.get("content", None) if content: _blogs = Blog.objects.all().order_by("-post_time") for blog in _blogs: if content.lower() in blog.title.lower(): blogs.append(blog) request_log.info('SEARCH - BLOG - {0}'.format(blogs)) master_13 = RedisDriver().master_13 master_15 = RedisDriver().master_15 online_ips = master_15.dbsize() day = time.strftime('%Y-%m-%d', time.localtime(time.time())) yesterday = str(datetime.date.today() - datetime.timedelta(days=1)) d = 'Day:{0}'.format(day) yesd = 'Day:{0}'.format(yesterday) access_day_ip = master_13.hget(d, 'IP') access_day_pv = master_13.hget(d, 'PV') access_yesterday_ip = master_13.hget(yesd, 'IP') access_yesterday_pv = master_13.hget(yesd, 'PV') if not blogs: blogs = Blog.objects.all().order_by("-post_time") num = None page_num_list = [] try: num = len(blogs) paginator = Paginator(blogs, 10) try: page = int(req.GET.get('page', 1)) blogs = paginator.page(page) for i in range(blogs.paginator.num_pages): page_num_list.append(i + 1) except (EmptyPage, InvalidPage, PageNotAnInteger): blogs = paginator.page(1) except Exception as e: error_log.error(e) return render_to_response( 'index_new.html', { 'blogs': blogs, 'page_num_list': page_num_list, 'online_ips': online_ips, 'access_day_ip': access_day_ip, 'access_day_pv': access_day_pv, 'access_yesterday_ip': access_yesterday_ip, 'access_yesterday_pv': access_yesterday_pv, }, RequestContext(req))
def home(request): return render_to_response("signup.html", locals(), context_instance=RequestContext(request))
def Characterize(request): if request.user.is_authenticated(): if request.method == "POST": form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() user_email_id = request.POST['email_id'] if not user_email_id: # if no email provided, report error return HttpResponse( '<h3>Please provide an email address to receive Job ID!</h3>' ) work_dir = '/home/NANOMINE/Production/mdcs' os.chdir(work_dir) os.system('pwd') file = request.FILES['docfile'] #get name of incoming file print type(str(file)) input_type = request.POST['Characterize_input_type'] if input_type == "1": if not str(file).endswith(".jpg"): if not str(file).endswith(".JPG"): if not str(file).endswith(".tif"): if not str(file).endswith(".png"): if not str(file).endswith(".PNG"): if not str(file).endswith(".TIF"): return HttpResponse( '<h3>Please upload a file in supported format (.jpg, .tif, .png)</h3>' ) #report wrong file format elif input_type == "2": if not str(file).endswith(".zip"): return HttpResponse('<h3>Please upload ZIP file</h3>' ) #report wrong file format else: if not str(file).endswith(".mat"): return HttpResponse('<h3>Please upload .mat file</h3>' ) #report wrong file format correlation_choice = request.POST['correlation_choice'] user_name = None user_name = request.user.get_username() print(user_name) # Run MATLAB when file is valid os.system( 'matlab -nodesktop -nodisplay -nosplash -r "cd /home/NANOMINE/Production/mdcs/Two_pt_MCR/mfiles;Characterize(\'"' + user_name + '"\',"' + str(input_type) + '","' + str(correlation_choice) + '",\'"' + str(file) + '"\');exit"') mail_to_user = '******' + user_email_id + ' < /home/NANOMINE/Production/mdcs/Two_pt_MCR/email.html' os.system(mail_to_user) os.system( 'sendmail [email protected] < /home/NANOMINE/Production/mdcs/Two_pt_MCR/email.html' ) form = DocumentForm() documents = Document.objects.all() return render_to_response( "MCR_Characterize_Check_Result.html", { 'documents': documents, 'form': form }, context_instance=RequestContext(request)) else: return HttpResponse('<h3>Please upload an image!</h3>' ) # if no image was uploaded, report error else: form = DocumentForm() documents = Document.objects.all() return render_to_response('Two_pt_MCR_Characterize.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request)) else: return ('/login')