2010-01-05 16:07:11 +00:00
|
|
|
from django.shortcuts import render_to_response, get_list_or_404, get_object_or_404
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.template import RequestContext
|
|
|
|
from django.db import IntegrityError
|
|
|
|
from django.core.cache import cache
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.http import HttpResponse, HttpRequest
|
|
|
|
from django.core import serializers
|
|
|
|
from django.utils.safestring import mark_safe
|
|
|
|
from django.views.decorators.cache import cache_page
|
|
|
|
from django.views.decorators.http import require_POST
|
|
|
|
from apps.rss_feeds.models import Feed, Story, Tag
|
2010-02-11 01:28:47 -05:00
|
|
|
from apps.reader.models import UserSubscription, UserStory
|
2010-03-23 20:03:40 -04:00
|
|
|
from apps.analyzer.models import ClassifierTitle, ClassifierAuthor, ClassifierFeed, ClassifierTag, get_classifiers_for_user
|
2010-01-05 16:07:11 +00:00
|
|
|
from utils import json
|
|
|
|
from utils.user_functions import get_user
|
|
|
|
import logging
|
|
|
|
import datetime
|
|
|
|
import random
|
|
|
|
|
|
|
|
def index(requst):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@require_POST
|
2010-01-21 13:12:29 -05:00
|
|
|
@json.json_view
|
2010-01-12 01:19:37 +00:00
|
|
|
def save_classifier_story(request):
|
2010-01-05 16:07:11 +00:00
|
|
|
post = request.POST
|
|
|
|
facets = post.getlist('facet')
|
|
|
|
code = 0
|
|
|
|
message = 'OK'
|
|
|
|
payload = {}
|
|
|
|
feed = Feed.objects.get(pk=post['feed_id'])
|
|
|
|
story = Story.objects.get(pk=post['story_id'])
|
2010-01-07 00:04:12 +00:00
|
|
|
score = int(post['score'])
|
2010-01-05 16:07:11 +00:00
|
|
|
|
|
|
|
if 'title' in post and 'title' in facets:
|
|
|
|
ClassifierTitle.objects.create(user=request.user,
|
2010-01-07 00:04:12 +00:00
|
|
|
score=score,
|
2010-01-05 16:07:11 +00:00
|
|
|
title=post['title'],
|
|
|
|
feed=feed,
|
|
|
|
original_story=story)
|
|
|
|
|
|
|
|
if 'author' in facets:
|
|
|
|
author = story.story_author
|
|
|
|
ClassifierAuthor.objects.create(user=request.user,
|
2010-01-07 00:04:12 +00:00
|
|
|
score=score,
|
2010-01-05 16:07:11 +00:00
|
|
|
author=author,
|
|
|
|
feed=feed,
|
|
|
|
original_story=story)
|
|
|
|
|
|
|
|
if 'publisher' in facets:
|
|
|
|
ClassifierFeed.objects.create(user=request.user,
|
2010-01-07 00:04:12 +00:00
|
|
|
score=score,
|
2010-01-05 16:07:11 +00:00
|
|
|
feed=feed,
|
|
|
|
original_story=story)
|
|
|
|
|
|
|
|
if 'tag' in post:
|
|
|
|
tags = post.getlist('tag')
|
|
|
|
for tag_name in tags:
|
|
|
|
tag = Tag.objects.get(name=tag_name, feed=feed)
|
|
|
|
ClassifierTag.objects.create(user=request.user,
|
2010-01-07 00:04:12 +00:00
|
|
|
score=score,
|
2010-01-05 16:07:11 +00:00
|
|
|
tag=tag,
|
|
|
|
feed=feed,
|
|
|
|
original_story=story)
|
|
|
|
|
2010-01-12 01:19:37 +00:00
|
|
|
response = dict(code=code, message=message, payload=payload)
|
2010-01-21 13:12:29 -05:00
|
|
|
return response
|
2010-01-12 01:19:37 +00:00
|
|
|
|
|
|
|
@require_POST
|
2010-01-21 13:12:29 -05:00
|
|
|
@json.json_view
|
2010-01-12 01:19:37 +00:00
|
|
|
def save_classifier_publisher(request):
|
|
|
|
post = request.POST
|
|
|
|
facets = post.getlist('facet')
|
|
|
|
code = 0
|
|
|
|
message = 'OK'
|
|
|
|
payload = {}
|
|
|
|
feed = Feed.objects.get(pk=post['feed_id'])
|
|
|
|
score = int(post['score'])
|
|
|
|
|
|
|
|
if 'author' in post:
|
|
|
|
authors = post.getlist('authors')
|
|
|
|
for author_name in authors:
|
|
|
|
author = StoryAuthor.objects.get(author_name=author_name, feed=feed)
|
|
|
|
ClassifierAuthor.objects.create(user=request.user,
|
|
|
|
score=score,
|
|
|
|
author=author,
|
|
|
|
feed=feed)
|
|
|
|
|
|
|
|
if 'publisher' in facets:
|
|
|
|
ClassifierFeed.objects.create(user=request.user,
|
|
|
|
score=score,
|
|
|
|
feed=feed)
|
|
|
|
|
|
|
|
if 'tag' in post:
|
|
|
|
tags = post.getlist('tag')
|
|
|
|
for tag_name in tags:
|
|
|
|
tag = Tag.objects.get(name=tag_name, feed=feed)
|
|
|
|
ClassifierTag.objects.create(user=request.user,
|
|
|
|
score=score,
|
|
|
|
tag=tag,
|
|
|
|
feed=feed)
|
|
|
|
|
2010-01-05 16:07:11 +00:00
|
|
|
response = dict(code=code, message=message, payload=payload)
|
2010-03-16 23:18:54 -04:00
|
|
|
return response
|
|
|
|
|
|
|
|
@json.json_view
|
|
|
|
def get_classifiers_feed(request):
|
|
|
|
feed = request.POST['feed_id']
|
|
|
|
user = get_user(request)
|
|
|
|
code = 0
|
|
|
|
|
2010-03-23 20:03:40 -04:00
|
|
|
payload = get_classifiers_for_user(user, feed)
|
2010-03-16 23:18:54 -04:00
|
|
|
|
|
|
|
response = dict(code=code, payload=payload)
|
|
|
|
|
2010-01-21 13:12:29 -05:00
|
|
|
return response
|