Ejemplo n.º 1
0
def add_feature(request):
    if not request.user.is_staff:
        return HttpResponseForbidden()

    code = -1    
    form = FeatureForm(request.POST)
    
    if form.is_valid():
        form.save()
        code = 1
        return HttpResponseRedirect(reverse('index'))
    
    return dict(code=code)
Ejemplo n.º 2
0
def add_feature(request):
    if not request.user.is_staff:
        return HttpResponseForbidden()

    code = -1    
    form = FeatureForm(request.POST)
    
    if form.is_valid():
        form.save()
        code = 1
        return HttpResponseRedirect(reverse('index'))
    
    return dict(code=code)
Ejemplo n.º 3
0
def render_features_module(context):
    user         = get_user(context['user'])
    features     = Feature.objects.all()[:3]
    feature_form = FeatureForm() if user.is_staff else None

    return {
        'user': user,
        'features': features,
        'feature_form': feature_form,
    }
Ejemplo n.º 4
0
def index(request):
    if request.method == "POST":
        if request.POST['submit'] == 'login':
            login_form = LoginForm(request.POST, prefix='login')
            signup_form = SignupForm(prefix='signup')
        else:
            login_form = LoginForm(prefix='login')
            signup_form = SignupForm(request.POST, prefix='signup')
    else:
        login_form = LoginForm(prefix='login')
        signup_form = SignupForm(prefix='signup')

    user = get_user(request)
    authed = request.user.is_authenticated()
    features = Feature.objects.all()[:3]
    feature_form = FeatureForm() if request.user.is_staff else None
    feed_count = UserSubscription.objects.filter(
        user=request.user).count() if authed else 0
    active_count = UserSubscription.objects.filter(
        user=request.user, active=True).count() if authed else 0
    train_count = UserSubscription.objects.filter(
        user=request.user,
        active=True,
        is_trained=False,
        feed__stories_last_month__gte=1).count() if authed else 0
    recommended_feeds = RecommendedFeed.objects.filter(
        is_public=True,
        approved_date__lte=datetime.datetime.now()).select_related('feed')[:2]
    unmoderated_feeds = RecommendedFeed.objects.filter(
        is_public=False, declined_date__isnull=True).select_related('feed')[:2]
    statistics = MStatistics.all()
    feedbacks = MFeedback.all()
    start_import_from_google_reader = request.session.get(
        'import_from_google_reader', False)
    if start_import_from_google_reader:
        del request.session['import_from_google_reader']

    return render_to_response(
        'reader/feeds.xhtml', {
            'user_profile': hasattr(user, 'profile') and user.profile,
            'login_form': login_form,
            'signup_form': signup_form,
            'feature_form': feature_form,
            'features': features,
            'feed_count': feed_count,
            'active_count': active_count,
            'train_count': active_count - train_count,
            'account_images': range(1, 4),
            'recommended_feeds': recommended_feeds,
            'unmoderated_feeds': unmoderated_feeds,
            'statistics': statistics,
            'feedbacks': feedbacks,
            'start_import_from_google_reader': start_import_from_google_reader,
        },
        context_instance=RequestContext(request))
Ejemplo n.º 5
0
def index(request):
    if request.method == "POST":
        if request.POST['submit'] == 'login':
            login_form = LoginForm(request.POST, prefix='login')
            signup_form = SignupForm(prefix='signup')
        else:
            login_form = LoginForm(prefix='login')
            signup_form = SignupForm(request.POST, prefix='signup')
    else:
        login_form = LoginForm(prefix='login')
        signup_form = SignupForm(prefix='signup')

    user = get_user(request)
    features = Feature.objects.all()[:3]
    feature_form = None
    if request.user.is_staff:
        feature_form = FeatureForm()

    feed_count = 0
    active_count = 0
    train_count = 0
    if request.user.is_authenticated():
        feed_count = UserSubscription.objects.filter(user=request.user).count()
        active_count = UserSubscription.objects.filter(user=request.user,
                                                       active=True).count()
        train_count = UserSubscription.objects.filter(
            user=request.user,
            active=True,
            is_trained=False,
            feed__stories_last_month__gte=1).count()

    now = datetime.datetime.now()
    recommended_feeds = RecommendedFeed.objects.filter(
        is_public=True, approved_date__lte=now).select_related('feed')[:2]
    # recommended_feed_feedback = RecommendedFeedUserFeedback.objects.filter(recommendation=recommended_feed)

    statistics = MStatistics.all()
    howitworks_page = 0  # random.randint(0, 5)
    return render_to_response(
        'reader/feeds.xhtml',
        {
            'user_profile':
            user.profile,
            'login_form':
            login_form,
            'signup_form':
            signup_form,
            'feature_form':
            feature_form,
            'features':
            features,
            'start_import_from_google_reader':
            request.session.get('import_from_google_reader', False),
            'howitworks_page':
            howitworks_page,
            'feed_count':
            feed_count,
            'active_count':
            active_count,
            'train_count':
            active_count - train_count,
            'account_images':
            range(1, 4),
            'recommended_feeds':
            recommended_feeds,
            'statistics':
            statistics,
            # 'recommended_feed_feedback': recommended_feed_feedback,
        },
        context_instance=RequestContext(request))