コード例 #1
0
ファイル: views.py プロジェクト: rsj217/dmblog
def privatemsgdetail(request, username, did):

    pm = get_object_or_404(PrivateMessage, id=did)

    varibles = RequestContext(request, {
        'pm': pm,
        'pcount': function.get_privatemsg_count(request, request.user),
    })
    return render_to_response('privatemsgdetail.html', varibles)
コード例 #2
0
ファイル: views.py プロジェクト: rsj217/dmblog
def favoritelist(request, username):

    if username == request.user.username:
        favoritelist = request.user.favorite_set.all().order_by('-addtime')
    else:
        raise Http404(u'非法操作')
    varibles = RequestContext(request, {
        'page_title': u'收藏',
        'favoritelist': favoritelist,
        'pcount': function.get_privatemsg_count(request, request.user),
    })
    return render_to_response('favoritelist.html', varibles)
コード例 #3
0
ファイル: views.py プロジェクト: rsj217/dmblog
def userslist(request):

    users = User.objects.exclude(is_staff=True).exclude(
        username=request.user.username)

    paginator_info = paginatorer.paginator_parse(
        request, users, ITEMS_PRE_PAGE)

    varibles = RequestContext(request, {
        'page_title': 'userslist',
        'users': paginator_info['curremt_obj'],
        'paginator': paginator_info,
        'pcount': function.get_privatemsg_count(request, request.user),
    })
    return render_to_response('userslist.html', varibles)
コード例 #4
0
ファイル: views.py プロジェクト: rsj217/dmblog
def fans(request, username):

    taruser = get_object_or_404(User, username=username)
    fanslist = [f.fans for f in taruser.fan_set.all()]

    paginator_info = paginatorer.paginator_parse(
        request, fanslist, ITEMS_PRE_PAGE)

    varibles = RequestContext(request, {
        'page_title': 'fanslist',
        'fanslist': paginator_info['curremt_obj'],
        'paginator': paginator_info,
        'taruser': taruser,
        'pcount': function.get_privatemsg_count(request, request.user),
    })
    return render_to_response('fans.html', varibles)
コード例 #5
0
ファイル: views.py プロジェクト: rsj217/dmblog
def home(request):

    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            message = form.cleaned_data['message']
            t = Tweet.objects.create(message=message, user=request.user)
            messages.info(request, u'发送成功!')
            return HttpResponseRedirect(reverse('mblog_home'))
        else:
            messages.info(request, u'发送失败!')
    else:
        form = PostForm()
        rtform = RTForm()

    followerslist = [f.followers for f in request.user.follower_set.all()]
    followerslist = list(followerslist)
    followerslist.append(request.user)

    tweets = Tweet.objects.filter(user__in=followerslist).order_by('-addtime')

    paginator_info = paginatorer.paginator_parse(
        request, tweets, ITEMS_PRE_PAGE)

    taruser = request.user

    tartweet = Tweet.objects.filter(user=taruser).order_by('addtime')

    varibles = RequestContext(request, {
        'form': form,
        'tweets': paginator_info['curremt_obj'],
        'paginator': paginator_info,
        'taruser': taruser,
        'rtform': rtform,
        'pcount': function.get_privatemsg_count(request, request.user),
    })

    return render_to_response('home.html', varibles)
コード例 #6
0
ファイル: views.py プロジェクト: rsj217/dmblog
def user_index(request, username):

    taruser = get_object_or_404(User, username=username)

    tweets = Tweet.objects.filter(user=taruser).order_by('-addtime')

    paginator_info = paginatorer.paginator_parse(
        request, tweets, ITEMS_PRE_PAGE)

    avatar_url = '/%savatar/150/%s' % (
        MEDIA_ROOT, taruser.profile.avatar)
    avatar_50_url = '/%savatar/50/%s' % (
        MEDIA_ROOT, taruser.profile.avatar)

    varibles = RequestContext(request, {
        'tweets': paginator_info['curremt_obj'],
        'avatar_url': avatar_url,
        'avatar_50_url': avatar_50_url,
        'paginator': paginator_info,
        'taruser': taruser,
        'pcount': function.get_privatemsg_count(request, request.user),
    })

    return render_to_response('user_index.html', varibles)
コード例 #7
0
ファイル: views.py プロジェクト: rsj217/dmblog
def setting(request):

    if request.method == "POST":
        form = SettingForm(request.POST, request.FILES)
        if form.is_valid():
            # 头像修改
            if 'avatar' in request.FILES:
                avatar = request.FILES['avatar']

                state = uploader.upload_avatar(avatar)
                if state['success']:
                    print request.user.profile.id

                    Profile.objects.filter(user__id=request.user.id).update(
                        user=request.user,
                        avatar=state['message']
                    )

                    remessage = u'上传成功'
                    avatar_url = '/%s/avatar/150/%s' % (
                        MEDIA_ROOT, request.user.profile.avatar)
                else:
                    remessage = state['message']
                messages.info(request, remessage)
            else:
                try:
                    p = Profile.objects.get(user=request.user)
                    avatar_url = '/%savatar/150/%s' % (MEDIA_ROOT, p.avatar)
                    messages.info(request, u'头像保存成功')
                except Exception as e:
                    raise e
                if p.avatar is None:
                    messages.info(request, u'请选择上传的图片!')
                    return HttpResponseRedirect('.')
            # 用户名 个人主页 关于修改
            nickname = form.cleaned_data['nickname']
            homepage = form.cleaned_data['homepage']
            about = form.cleaned_data['about']

            Profile.objects.filter(user__id=request.user.id).update(
                user=request.user,
                nickname=nickname,
                homepage=homepage,
                about=about)

            # 密码修改
            password = form.cleaned_data['password']
            try:
                u = User.objects.get(username=request.user)
                u.set_password(password)
                u.save()
                messages.info(request, u'保存成功')
                return HttpResponseRedirect('.')
            except Exception as e:
                raise e

        else:
            messages.info(request, u'没有上传图片或者上传的图片不合法!')
            return HttpResponseRedirect('.')
    else:
        form = SettingForm()
        try:
            p = Profile.objects.get(user=request.user)
            if p.avatar == '':
                avatar_url = '/%savatar/default/default.png' % MEDIA_ROOT
            else:
                avatar_url = '/%savatar/150/%s' % (MEDIA_ROOT, p.avatar)
        except Exception as e:
            raise e

    varibles = RequestContext(request, {
        'page_title': u'个人设置',
        'form': form,
        'avatar_url': avatar_url,
        'pcount': function.get_privatemsg_count(request, request.user),
    })
    return render_to_response('settings.html', varibles)