def _create_topic(self, title, summary_text): summary = Summary.objects.get_or_create(text=summary_text)[0] summary.save() topic = Topic(title = title, slug = core.utils.slugify(title), summary = summary, is_deleted = False) topic.save() return topic
def import_topics(filename): with open(filename, 'rt', encoding='utf-8') as csvfile: reader = csv.reader(csvfile, delimiter=',') topic_list = list(reader) for i in topic_list: t = Topic(name=i[0], descriptor=i[1]) t.save()
def save(self, request): data = self.cleaned_data topic = Topic( user=request.user, subject=data['subject'], subject_english=data['subject_english'], content=data['content'], content_english=data['content_english'], deadline=data['deadline'], event_close_date=data['event_close_date'], end_weight=data['end_weight'], ) topic.save() pay_topic_post(topic) for tag in data['tags']: topic.tags.add(tag) if data.get('yesno') is not None and data.get('score'): bet = Bet( user=request.user, topic=topic, score=data['score'], weight=get_current_weight(topic), yesno=data['yesno'], ) bet.save() pay_bet(bet) return topic
def index(request): user = None login(request) home = True if request.user.is_authenticated(): user = request.user topics_tree = mc.get('topics_tree') if not topics_tree: topics_tree = Topic.objects.topics_tree() mc.set('topics_tree', topics_tree, settings.MEMCACHED_TIMEOUT) tags = mc.get('tags') if not tags: tags = Tag.objects.all() mc.set('tags', tags, settings.MEMCACHED_TIMEOUT) contributions = mc.get('contributions') if not contributions: contributions = Topic.total_contributions() mc.set('contributions', contributions, 900) # 15 Minutes top_users = mc.get('top_users') if not top_users: top_users = User.get_top_users(24) mc.set('top_users', top_users, settings.MEMCACHED_TIMEOUT) top_liked = mc.get('top_liked') if not top_liked: top_liked = ArticleDetails.objects.get_top_liked(5) mc.set('top_liked', top_liked, settings.MEMCACHED_TIMEOUT) top_commented = mc.get('top_commented') if not top_commented: top_commented = ArticleDetails.objects.get_top_commented(5) mc.set('top_commented', top_commented, settings.MEMCACHED_TIMEOUT) template_context = { 'settings': settings, 'request': request, 'top_users': top_users, 'home': home, 'topics_tree': topics_tree, 'settings': settings, 'user': user, 'contributions': contributions, 'top_liked': top_liked, 'top_disliked': top_disliked, 'top_commented': top_commented, 'tags': tags } return render_to_response('index.html', template_context, RequestContext(request))
def cacheTopics(request, collection_id): if request.method == 'GET': evidence_count = Evidence.objects.filter(created_by=collection_id).count() Topic.objects.filter(collection_id=collection_id).delete() collection_name = Collection.objects.get(collection_id=int(collection_id)).collection_name topicList = TopicModeler.get_online_lda_topics(collection_name, evidence_count / 10) for i in range(len(topicList)): topic_id = topicList[i][0] evidence_count = Evidence.objects.filter(Q(evidencetopic__primary_topic=topic_id)&Q(created_by=collection_id)).count() t = Topic( collection_id=collection_id, index=topic_id, terms=json.dumps(topicList[i][1]), document_count=evidence_count ) t.save() return HttpResponse(json.dumps({}), status=status.HTTP_200_OK)
def newtopic_logic(form, userprofile): title = form.cleaned_data['title'] summary_text = form.cleaned_data['summary_text'] source_comment = form.cleaned_data['source_comment'] curators = [userprofile] summary = Summary.objects.get_or_create(text=summary_text)[0] # get_or_create returns (obj, is_new) summary.save() topic = Topic(title = title, slug = core.utils.slugify(title), summary = summary, is_deleted = False) topic.save() topic.curators = curators if source_comment: topic.comments = [source_comment] topic.save()
def index(request): user = None login(request) home = True if request.user.is_authenticated(): user = request.user topics_tree = mc.get('topics_tree') if not topics_tree: topics_tree = Topic.objects.topics_tree() mc.set('topics_tree', topics_tree, settings.MEMCACHED_TIMEOUT) tags = mc.get('tags') if not tags: tags = Tag.objects.all() mc.set('tags', tags, settings.MEMCACHED_TIMEOUT) contributions = mc.get('contributions') if not contributions: contributions = Topic.total_contributions() mc.set('contributions', contributions, 3600) # 15 Minutes top_users = mc.get('top_users') if not top_users: top_users = User.get_top_users(24) mc.set('top_users', top_users, settings.MEMCACHED_TIMEOUT) top_liked = mc.get('top_liked') if not top_liked: top_liked = ArticleDetails.objects.get_top_liked(5) mc.set('top_liked', top_liked, settings.MEMCACHED_TIMEOUT) top_commented = mc.get('top_commented') if not top_commented: top_commented = ArticleDetails.objects.get_top_commented(5) mc.set('top_commented', top_commented, settings.MEMCACHED_TIMEOUT) template_context = {'settings':settings, 'request':request, 'top_users':top_users, 'home':home,'topics_tree':topics_tree,'settings': settings,'user':user,'contributions':contributions,'top_liked':top_liked, 'top_disliked':top_disliked, 'top_commented':top_commented, 'tags':tags} return render_to_response('index.html', template_context ,RequestContext(request))
def post(self, request, *args, **kwargs): latitude = request.session['coordinates'][0] longitude = request.session['coordinates'][1] topic = Topic(latitude=latitude, longitude=longitude, user=request.user, name=request.POST.get("name", None)) topic.save(); return redirect("topic", topic.id)