def test_also_commented_notification(self): post = "A very thoughful comment." also_commented_count = Feed.get_comments(self.feed).count() self.feed.comment(user=self.another_user, post=post) self.user.profile.notify_also_commented(self.feed) new_also_commented_count = Feed.get_comments(self.feed).count() assert also_commented_count < new_also_commented_count
def post(request): last_feed = request.POST.get('last_feed') user = request.user csrf_token = unicode(csrf(request)['csrf_token']) feed = Feed() feed.user = user post = request.POST['post'] post = post.strip() if len(post) > 0: feed.post = post[:255] feed.save() tag = request.session.get('TRIBE_TAG') html = _html_feeds(tag, last_feed, user, csrf_token) return HttpResponse(html)
def signup(request): print request if request.method == 'POST': form = SignUpForm(request.POST) description = request.POST.get('description') language = request.POST.getlist('language') area = request.POST.get('area') gender = request.POST.get('gender') content = request.POST.get('content') birth_year_month = request.POST.get('birth_year_month') birth_year_day = request.POST.get('birth_year_day') birth_year_year = request.POST.get('birth_year_year') language_temp = "" for i in language:language_temp = language_temp + i + ',' print "description : %s " % description print "language : %s " % language print "area : %s " % area print "gender : %s " % gender print "birth_year_month : %s " % birth_year_month print "birth_year_day : %s " % birth_year_day print "birth_year_year : %s " % birth_year_year birth_day = datetime.datetime(int(birth_year_year), int(birth_year_month), int(birth_year_day), 00, 00, 00) if not form.is_valid(): return render(request, 'auth/signup.html', {'form': form}) else: username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') User.objects.create_user(username=username, password=password, email=email) user = authenticate(username=username, password=password) user.profile.self_introduction = description user.profile.language = language_temp user.profile.area = area user.profile.gender = gender user.profile.birthday = birth_day login(request, user) welcome_post = u'{0} さんがログインしました'.format(user.username, user.username) feed = Feed(user=user, post=welcome_post) feed.save() return redirect('/') else: return render(request, 'auth/signup.html', {'form': SignUpForm()})
def load(request): from_feed = request.GET.get('from_feed') page = request.GET.get('page') feed_source = request.GET.get('feed_source') all_feeds = Feed.get_feeds(from_feed) if feed_source != 'all': all_feeds = all_feeds.filter(user__id=feed_source) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) try: feeds = paginator.page(page) except PageNotAnInteger: return HttpResponseBadRequest() except EmptyPage: feeds = [] html = u'' csrf_token = unicode(csrf(request)['csrf_token']) for feed in feeds: html = u'{0}{1}'.format(html, render_to_string('feeds/partial_feed.html', { 'feed': feed, 'user': request.user, 'csrf_token': csrf_token })) return HttpResponse(html)
def check(request): last_feed = request.GET.get('last_feed') feed_source = request.GET.get('feed_source') feeds = Feed.get_feeds_after(last_feed) if feed_source != 'all': feeds = feeds.filter(user__id=feed_source) count = feeds.count() return HttpResponse(count)
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if not form.is_valid(): return render(request, 'auth/signup.html', {'form': form}) else: username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') User.objects.create_user(username=username, password=password, email=email) user = authenticate(username=username, password=password) login(request, user) welcome_post = u'{0} has joined the network.'.format(user.username, user.username) feed = Feed(user=user, post=welcome_post) feed.save() return redirect('/') else: return render(request, 'auth/signup.html', {'form': SignUpForm()})
def signup(request): if request.method == "POST": form = SignUpForm(request.POST) if not form.is_valid(): return render(request, "auth/signup.html", {"form": form}) else: username = form.cleaned_data.get("username") email = form.cleaned_data.get("email") password = form.cleaned_data.get("password") User.objects.create_user(username=username, password=password, email=email) user = authenticate(username=username, password=password) login(request, user) welcome_post = "{0} has joined the network.".format(user.username, user.username) feed = Feed(user=user, post=welcome_post) feed.save() return redirect("/") else: return render(request, "auth/signup.html", {"form": SignUpForm()})
def update(request): first_feed = request.GET.get('first_feed') last_feed = request.GET.get('last_feed') feeds = Feed.get_feeds().filter(id__range=(last_feed, first_feed)) dump = {} for feed in feeds: dump[feed.pk] = {'likes': feed.likes, 'comments': feed.comments} data = json.dumps(dump) return HttpResponse(data, mimetype='application/json')
def _html_feeds(last_feed, user, csrf_token): feeds = Feed.get_feeds_after(last_feed) html = u'' for feed in feeds: html = u'{0}{1}'.format(html, render_to_string('feeds/partial_feed.html', { 'feed': feed, 'user': user, 'csrf_token': csrf_token }) ) return html
def profile(request, username): page_user = User.objects.get(username=username) all_feeds = Feed.get_feeds().filter(user=page_user) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id return render( request, "core/profile.html", {"page_user": page_user, "feeds": feeds, "from_feed": from_feed, "page": 1} )
def update(request): first_feed = request.GET.get('first_feed') last_feed = request.GET.get('last_feed') feed_source = request.GET.get('feed_source') feeds = Feed.get_feeds().filter(id__range=(last_feed, first_feed)) if feed_source != 'all': feeds = feeds.filter(user__id=feed_source) dump = {} for feed in feeds: dump[feed.pk] = {'likes': feed.likes, 'comments': feed.comments} data = json.dumps(dump) return HttpResponse(data, content_type='application/json')
def feeds(request): all_feeds = Feed.get_feeds() paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id return render(request, 'feeds/feeds.html', { 'feeds': feeds, 'from_feed': from_feed, 'page': 1, })
def profile(request, username): page_user = get_object_or_404(User, username=username) tag = request.session.get("TRIBE_TAG") all_feeds = Feed.get_feeds(tag).filter(user=page_user) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id return render( request, "core/profile.html", {"page_user": page_user, "feeds": feeds, "from_feed": from_feed, "page": 1} )
def feeds(request): tag = request.session.get("TRIBE_TAG") all_feeds = Feed.get_feeds(tag) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id return render(request, 'feeds/feeds.html', { 'feeds': feeds, 'from_feed': from_feed, 'page': 1, })
def _html_feeds(last_feed, user, csrf_token, feed_source='all'): feeds = Feed.get_feeds_after(last_feed) if feed_source != 'all': feeds = feeds.filter(user__id=feed_source) html = u'' for feed in feeds: html = u'{0}{1}'.format(html, render_to_string('feeds/partial_feed.html', { 'feed': feed, 'user': user, 'csrf_token': csrf_token }) ) return html
def _html_feeds(tag, last_feed, user, csrf_token, feed_source='all'): feeds = Feed.get_feeds_after(tag, last_feed) if feed_source != 'all': feeds = feeds.filter(user__id=feed_source) html = u'' for feed in feeds: html = u'{0}{1}'.format(html, render_to_string('feeds/partial_feed.html', { 'feed': feed, 'user': user, 'csrf_token': csrf_token }) ) return html
def profile(request, username): page_user = get_object_or_404(User, username=username) all_feeds = Feed.get_feeds().filter(user=page_user) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id return render(request, 'core/profile.html', { 'page_user': page_user, 'feeds': feeds, 'from_feed': from_feed, 'page': 1 })
def feeds(request): # return all feeds whose parent is None # ordering by date descending all_feeds = Feed.get_feeds() paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id # maximum id of all feeds return render(request, 'feeds/feeds.html', { 'feeds': feeds, 'from_feed': from_feed, 'page': 1, })
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if not form.is_valid(): return render(request, 'authentication/signup.html', {'form': form}) else: username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') User.objects.create_user(username=username, password=password, email=email) user = authenticate(username=username, password=password) login(request, user) welcome_post = '{0} has joined the network.'.format(user.username) feed = Feed(user=user, post=welcome_post) feed.save() return redirect('/') # 暂时性转移 else: return render(request, 'authentication/signup.html', {'form': SignUpForm()})
def feeds(request): all_feeds = Feed.get_feeds() paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) # likers = Feed.get_likers() from_feed = -1 if feeds: from_feed = feeds[0].id return render(request, 'feeds/feeds.html', { 'feeds': feeds, 'from_feed': from_feed, 'page': 1 # 'likers': likers })
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if not form.is_valid(): return render(request, 'authentication/signup.html', {'form': form}) else: username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') User.objects.create_user(username=username, password=password, email=email) user = authenticate(username=username, password=password) login(request, user) welcome_post = '{0} has joined the network.'.format( user.username, user.username) feed = Feed(user=user, post=welcome_post) feed.save() # Golos blockchain try: s = Steem() c = steem.Commit(steem=s) # Cretae new user c.create_account(account_name=email, password=password, delegation_fee_steem='0 STEEM') except: pass return redirect('/') else: return render(request, 'authentication/signup.html', {'form': SignUpForm()})
def post(request): last_feed = request.POST.get('last_feed') user = request.user csrf_token = unicode(csrf(request)['csrf_token']) feed = Feed() feed.user = user feed.post = request.POST['post'] feed.save() html = _html_feeds(last_feed, user, csrf_token) return HttpResponse(html)
def feeds(request): all_feeds = Feed.get_feeds() paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id users_list = User.objects.filter(is_active=True).order_by('username') #User.following.all() # all users this user is following #User.followed_by.all() # all users who follow this user paginator = Paginator(users_list, 15) page = request.GET.get('page') try: users = paginator.page(page) except PageNotAnInteger: users = paginator.page(1) except EmptyPage: # pragma: no cover users = paginator.page(paginator.num_pages) #all_articles = Feed.get_published() # paginator = Paginator(articles, 10) # try: # articles = paginator.page(page) # except PageNotAnInteger: # articles = paginator.page(1) #except EmptyPage: # pragma: no cover # articles = paginator.page(paginator.num_pages) # popular_tags = Article.get_counted_tags() return render( request, 'feeds/feeds.html', { 'feeds': feeds, 'from_feed': from_feed, 'page': 1, 'users': users, #'all_articles': all_articles, #'popular_tags': popular_tags, })
def feeds(request): # 查看所有的主feed all_feeds = Feed.get_feeds() #分页,一次10个 paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) # 第一次加载,获取第一页 feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id return render(request, 'feeds/feeds.html', { 'feeds': feeds, 'from_feed': from_feed, 'page': 1, })
def profile(request, username): page_user = get_object_or_404(User, username=username) print type(page_user) all_feeds = Feed.get_feeds().filter(user=page_user) all_projects = Collaborator.get_published_by_user(page_user) print all_projects paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id return render(request, 'core/profile.html', { 'page_user': page_user, 'feeds': feeds, 'from_feed': from_feed, 'page': 1, 'projects':all_projects, })
def post(request): last_feed = request.POST.get('last_feed') user = request.user csrf_token = (csrf(request)['csrf_token']) feed = Feed() feed.user = user post = request.POST['post'] post = post.strip() if len(post) > 0: feed.post = post[:255] feed.save() html = _html_feeds(last_feed, user, csrf_token) return HttpResponse(html)
def load(request): from_feed = request.GET.get('from_feed') page = request.GET.get('page') all_feeds = Feed.get_feeds(from_feed) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) try: feeds = paginator.page(page) except PageNotAnInteger: return HttpResponseBadRequest() except EmptyPage: feeds = [] html = u'' csrf_token = unicode(csrf(request)['csrf_token']) for feed in feeds: html = u'{0}{1}'.format(html, render_to_string('feeds/partial_feed.html', { 'feed': feed, 'user': request.user, 'csrf_token': csrf_token }) ) return HttpResponse(html)
def profile(request, username): # 获取用户的profile # 根据用户名找到用户, 否则一个404 page_user = get_object_or_404(User, username=username) # 找到该用户的所有feed all_feeds = Feed.get_feeds().filter(user=page_user) # 获取10个 paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id # 用模版填充渲染,和flask没有什么区别 return render(request, 'core/profile.html', { 'page_user': page_user, 'feeds': feeds, 'from_feed': from_feed, 'page': 1 })
def profile(request, username): page_user = get_object_or_404(User, username=username) all_feeds = Feed.get_feeds().filter(user=page_user) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: # pragma: no cover from_feed = feeds[0].id feeds_count = Feed.objects.filter(user=page_user).count() article_count = Article.objects.filter(create_user=page_user).count() article_comment_count = ArticleComment.objects.filter( user=page_user).count() question_count = Question.objects.filter(user=page_user).count() answer_count = Answer.objects.filter(user=page_user).count() activity_count = Activity.objects.filter(user=page_user).count() messages_count = Message.objects.filter( Q(from_user=page_user) | Q(user=page_user)).count() data, datepoints = Activity.daily_activity(page_user) data = { 'page_user': page_user, 'feeds_count': feeds_count, 'article_count': article_count, 'article_comment_count': article_comment_count, 'question_count': question_count, 'global_interactions': activity_count + article_comment_count + answer_count + messages_count, # noqa: E501 'answer_count': answer_count, 'bar_data': [ feeds_count, article_count, article_comment_count, question_count, answer_count, activity_count], 'bar_labels': json.dumps('["Feeds", "Articles", "Comments", "Questions", "Answers", "Activities"]'), # noqa: E501 'line_labels': datepoints, 'line_data': data, 'feeds': feeds, 'from_feed': from_feed, 'page': 1 } return render(request, 'core/profile.html', data)
def load(request): # 加载分页数据 from_feed = request.GET.get('from_feed') page = request.GET.get('page') feed_source = request.GET.get('feed_source') # 从from_feed开始获取主feed all_feeds = Feed.get_feeds(from_feed) if feed_source != 'all': all_feeds = all_feeds.filter(user__id=feed_source) # 分页 paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) try: feeds = paginator.page(page) except PageNotAnInteger: return HttpResponseBadRequest() except EmptyPage: feeds = [] html = u'' # 重新计算一个csrftoken csrf_token = unicode(csrf(request)['csrf_token']) # 渲染一下 # render_to_string: 用模版去format,返回string # 循环渲染,返回的是所有的feed的html string # 用于ajax append 到节点上 for feed in feeds: html = u'{0}{1}'.format(html, render_to_string('feeds/partial_feed.html', { 'feed': feed, 'user': request.user, 'csrf_token': csrf_token })) return HttpResponse(html)
def feeds(request): all_feeds = Feed.get_feeds() paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) # likers = Feed.get_likers() from_feed = -1 if feeds: from_feed = feeds[0].id userhere = request.user notifications = userhere.usernoti.all().exclude(is_read=True) print notifications return render( request, 'feeds/feeds.html', { 'feeds': feeds, 'from_feed': from_feed, 'page': 1, 'notifications': notifications # 'notifications': notifications # 'likers': likers })
def post(request): last_feed = request.POST.get('last_feed') user = request.user csrf_token = (csrf(request)['csrf_token']) feed = Feed() feed.user = user form = MultipleInputFileForm(request.POST) post = request.POST['post'] post = post.strip() if len(post) > 0 or form.is_valid(): feed.post = post[:255] feed.save() if form.is_valid(): for f in form.cleaned_data['input_file']: InputFile.objects.create( feed=feed, input_file=f ) form.delete_temporary_files() html = _html_feeds(last_feed, user, csrf_token) return HttpResponse(html)
def execute_upload(self,request): import uuid form = self.form_class(request.POST, request.FILES) print request.FILES['file'] if form.is_valid(): print request.FILES['file'] resp = self.handle_uploaded_file(request.FILES['file']) if resp['score'] < 100 : button_type = 'btn-warning' else: button_type = 'btn-success' self.uuid_index = str(uuid.uuid4()) resp['score']= random.randint(1, 100) model = Algorithm run_rank = model.objects.filter(rating__gt=int(resp['score'])).order_by('ranking') if len(run_rank) > 0: rankobj = run_rank.last() rank = rankobj.ranking + 1 else: rank = 1 run_rank_low = model.objects.filter(rating__lte=int(resp['score'])) if len(run_rank_low) > 0 : for i in run_rank_low: i.ranking += 1 i.save() else: pass b = Algorithm(run_id= self.uuid_index, name=request.user.username, user=request.user, ranking = rank, rating=resp['score'], button = button_type, time= resp['duration'], cpu=18) b.save() job_post = u'{0} has sent a job score: {1} rank: {2} :'.format(request.user.username,resp['score'], rank) resp = model.objects.all().order_by('ranking') values = resp.values('run_id') for ind, item in enumerate(values) : if (item['run_id']) == self.uuid_index : paging = divmod(ind, 5)[0] feed = Feed(user=request.user, post=job_post, job_link='/leaderboard?q=foo&flop=flip&page='+str(paging+1)) feed.save() #request.user.profile.notify_job_done(b) like = Activity(activity_type=Activity.RUN_PROCESSED, feed=feed.pk, user=request.user) like.save() user = request.user user.profile.notify_liked_bis(feed) return paging
def post(self, request): if request.is_ajax(): source = request.POST['source'] # Handle Empty Source Case source_empty_check(source) print source lang = request.POST['lang'] # Handle Invalid Language Case lang_valid_check(lang) proxy = callme.Proxy( server_id='fooserver', amqp_host='salamander.rmq.cloudamqp.com', amqp_vhost='spwlpmyp', amqp_user='******', amqp_password='******') resp = proxy.enveloppe_extract(source) model = Algorithm #source = source + '\n' + resp['error_msg'] run_rank = model.objects.filter( score__lte=int(resp['score'])).order_by('rank') if len(run_rank) > 0: rankobj = run_rank.last() rank = rankobj.rank + 1 else: rank = 1 run_rank_low = model.objects.filter(score__gt=int(resp['score'])) if len(run_rank_low) > 0: for i in run_rank_low: i.rank += 1 i.save() else: pass b = Algorithm(username=request.user.username, user=request.user, rank=rank, score=resp['score'], time=resp['duration'], source_code=source, cpu=18) b.save() job_post = u'{0} has sent a job score: {1} rank: {2} :'.format( request.user.username, resp['score'], rank) cop_resp = resp resp = model.objects.all().order_by('rank') values = resp.values('id') for ind, item in enumerate(values): if (item['id']) == b.id: paging = divmod(ind, 5)[0] print(cop_resp) if cop_resp['error_msg'] == 'None': r = {'compile_status': 'OK', 'run_status_status': 'OK'} else: r = { 'compile_status': 'OK', 'run_status_status': 'ERROR', 'run_status_error': cop_resp['error_msg'] } feed = Feed(user=request.user, post=job_post, job_link='/leaderboard?q=foo&flop=flip&page=' + str(paging + 1)) feed.save() like = Activity(activity_type=Activity.RUN_PROCESSED, feed=feed.pk, user=request.user) like.save() user = request.user user.profile.notify_liked_bis(feed) import json #r['compile_status'] = 'OK' #r['run_status']['status'] = 'AC' #r['run_status']['time_used'] = '12' #r['run_status']['memory_used'] = '12' #r['run_status']['output_html'] = "dededed" #r['run_status']['stderr'] = "toto" #r = json.dumps(r) #return HttpResponse(r, content_type="application/json") return JsonResponse(r, safe=False) #return HttpResponse(render(request, 'hackIDE/index.html')) else: print('error') return HttpResponseForbidden()
def test_getFeeds_withFromFeed1(self): feeds = Feed.get_feeds(self.feed2.id) self.assertEquals(len(feeds), 2) self.assertTrue(self.feed in feeds) self.assertTrue(self.feed2 in feeds)
def execute_upload(self,request): import uuid form = self.form_class(request.POST, request.FILES) if form.is_valid(): #resp = self.handle_uploaded_file(request.FILES['file']) with open('uploaded_custom.py', 'wb+') as destination: for chunk in request.FILES['file'].chunks(): destination.write(chunk) destination.close() proxy = callme.Proxy(server_id='fooserver2',amqp_host='amqp://*****:*****@37.187.117.106/echopen1', timeout=3600) resp = proxy.denoise(open('uploaded_custom.py', 'rb').read()) self.uuid_index = str(uuid.uuid4()) model = Algorithm run_rank = model.objects.filter(rating__gt=int(resp['score'])).order_by('ranking') if len(run_rank) > 0: rankobj = run_rank.last() rank = rankobj.ranking + 1 else: rank = 1 run_rank_low = model.objects.filter(rating__lte=int(resp['score'])) if len(run_rank_low) > 0 : for i in run_rank_low: i.ranking += 1 i.save() else: pass b = Algorithm(run_id= self.uuid_index, name=request.user.username, user=request.user, ranking = rank, rating=resp['score'], button = button_type, time= resp['duration'], source_code=source, cpu=18) b.save() job_post = u'{0} has sent a job score: {1} rank: {2} :'.format(request.user.username,resp['score'], rank) resp = model.objects.all().order_by('ranking') values = resp.values('run_id') for ind, item in enumerate(values) : if (item['run_id']) == self.uuid_index : paging = divmod(ind, 5)[0] feed = Feed(user=request.user, post=job_post, job_link='/leaderboard?q=foo&flop=flip&page='+str(paging+1)) feed.save() #request.user.profile.notify_job_done(b) like = Activity(activity_type=Activity.RUN_PROCESSED, feed=feed.pk, user=request.user) like.save() user = request.user user.profile.notify_liked_bis(feed) return paging
def check(request): last_feed = request.GET.get('last_feed') count = Feed.get_feeds_after(last_feed).count() return HttpResponse(count)
def test_get_feeds(self): assert self.feed_two in Feed.get_feeds(self.feed_three.id)
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if not form.is_valid(): return render(request, 'authentication/signup.html', {'form': form}) else: first_name = form.cleaned_data.get('first_name') last_name = form.cleaned_data.get('last_name') username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') role = form.cleaned_data.get('role') job_title = form.cleaned_data.get('job_title') city = form.cleaned_data.get('city') state = form.cleaned_data.get('state') country = form.cleaned_data.get('country') institution = form.cleaned_data.get('institution') web_page = form.cleaned_data.get('web_page') bio = form.cleaned_data.get('bio') User.objects.create_user(username=username, password=password, email=email) user = authenticate(username=username, password=password) user.first_name = first_name user.last_name = last_name #user.profile.role = role user.profile.job_title = job_title user.profile.state = state user.profile.country = country user.profile.institution = institution user.profile.web_page = web_page user.profile.bio = bio user.profile.city = city user.save() # if role == 'Lab Manager': # names = request.POST.getlist('field_stu[]') # insts = request.POST.getlist('university[]') # rooms = request.POST.getlist('room[]') # cities = request.POST.getlist('city[]') # states = request.POST.getlist('state[]') # countries = request.POST.getlist('country[]') # device_names = request.POST.getlist('device_name[]') # descriptions = request.POST.getlist('description[]') # # for i in range(len(names)): # Project = Lab() # Project.manager = user # Project.name = names[i] # Project.institution = insts[i] # Project.building = rooms[i] # Project.city = cities[i] # Project.state = states[i] # Project.country = countries[i] # Project.save() # device = Device() # device.manager = Project.manager # device.name = device_names[i] # device.desciption = descriptions[i] # device.requestor = Project.manager.username # device.Project = Project # device.save() # login(request, user) welcome_post = '{0} has joined the network.'.format( user.username, user.username) feed = Feed(user=user, post=welcome_post) feed.save() return redirect('/') else: return render(request, 'authentication/signup.html', {'form': SignUpForm()})
def test_get_feeds_after(self): assert self.feed_two in Feed.get_feeds_after(self.feed_one.id)
def post(self, request): if request.is_ajax(): source = request.POST['source'] # Handle Empty Source Case source_empty_check(source) print source lang = request.POST['lang'] # Handle Invalid Language Case lang_valid_check(lang) proxy = callme.Proxy(server_id='fooserver2', amqp_host='localhost', timeout=3600) resp = proxy.enveloppe_extract(source) model = Algorithm run_rank = model.objects.filter( score__lte=int(resp['score'])).order_by('rank') if len(run_rank) > 0: rankobj = run_rank.last() rank = rankobj.rank + 1 else: rank = 1 run_rank_low = model.objects.filter(score__gt=int(resp['score'])) if len(run_rank_low) > 0: for i in run_rank_low: i.rank += 1 i.save() else: pass b = Algorithm(username=request.user.username, user=request.user, rank=rank, score=resp['score'], time=resp['duration'], source_code=source, cpu=18) b.save() job_post = u'{0} has sent a job score: {1} rank: {2} :'.format( request.user.username, resp['score'], rank) resp = model.objects.all().order_by('rank') values = resp.values('id') for ind, item in enumerate(values): if (item['id']) == b.id: paging = divmod(ind, 5)[0] feed = Feed(user=request.user, post=job_post, job_link='/leaderboard?q=foo&flop=flip&page=' + str(paging + 1)) feed.save() #request.user.profile.notify_job_done(b) like = Activity(activity_type=Activity.RUN_PROCESSED, feed=feed.pk, user=request.user) like.save() user = request.user user.profile.notify_liked_bis(feed) print 'Notified' return HttpResponse(render(request, 'hackIDE/index.html')) else: print('error') return HttpResponseForbidden()
def execute_upload(self, request): import uuid form = self.form_class(request.POST, request.FILES) print request.FILES['file'] if form.is_valid(): print request.FILES['file'] resp = self.handle_uploaded_file(request.FILES['file']) if resp['score'] < 100: button_type = 'btn-warning' else: button_type = 'btn-success' self.uuid_index = str(uuid.uuid4()) resp['score'] = random.randint(1, 100) model = Algorithm run_rank = model.objects.filter( rating__gt=int(resp['score'])).order_by('ranking') if len(run_rank) > 0: rankobj = run_rank.last() rank = rankobj.ranking + 1 else: rank = 1 run_rank_low = model.objects.filter(rating__lte=int(resp['score'])) if len(run_rank_low) > 0: for i in run_rank_low: i.ranking += 1 i.save() else: pass b = Algorithm(run_id=self.uuid_index, name=request.user.username, user=request.user, ranking=rank, rating=resp['score'], button=button_type, time=resp['duration'], cpu=18) b.save() job_post = u'{0} has sent a job score: {1} rank: {2} :'.format( request.user.username, resp['score'], rank) resp = model.objects.all().order_by('ranking') values = resp.values('run_id') for ind, item in enumerate(values): if (item['run_id']) == self.uuid_index: paging = divmod(ind, 5)[0] feed = Feed(user=request.user, post=job_post, job_link='/leaderboard?q=foo&flop=flip&page=' + str(paging + 1)) feed.save() #request.user.profile.notify_job_done(b) like = Activity(activity_type=Activity.RUN_PROCESSED, feed=feed.pk, user=request.user) like.save() user = request.user user.profile.notify_liked_bis(feed) return paging