Exemplo n.º 1
0
def change(request):
    notice_settings = NoticeSetting.objects.myself(request.user)
    
    if request.method == "POST":
        form = NoticeSettingForm(request.POST, user=request.user)
        if form.is_valid():
            for notice_setting in notice_settings:
                notice_setting.flags = devices_set_true(notice_setting.flags, form.cleaned_data[notice_setting.notice_type.label])
                notice_setting.save()
            messages.success(request, u"成功修改通知")
            
            return redirect(reverse("notification.views.change"))
    else:
        data = {}
        for notice_setting in notice_settings:
            data[notice_setting.notice_type.label] = notice_setting.devices_tuple()
        form = NoticeSettingForm(data, user=request.user)
    
    current_nav = u"设置"
    breadcrumbs = [
        {"name":u"通知中心", "url":reverse("notification.views.home")},
        {"name":current_nav},
    ]
    return render_template("notification/change.html", form=form, request=request, breadcrumbs=breadcrumbs, 
                           current_nav=current_nav)
Exemplo n.º 2
0
def view(request, template_name='view.html'):
    """
    Shows a single message.``message_id`` argument is required.
    The user is only allowed to see the message, if he is either 
    the sender or the recipient. If the user is not allowed a 404
    is raised. 
    If the user is the recipient and the message is unread 
    ``read_at`` is set to the current datetime.
    """
    condition = None
    if 'condition' in request.GET:
        condition = request.GET['condition']
    if condition:
        message_list = Message.objects.messages_like(request.user, condition)
    else:
        message_list = Message.objects.messages_all(request.user)
    user_lastmsgs = {}
    for message in message_list:
        if message.sender not in user_lastmsgs and message.sender != request.user:
            user_lastmsgs[message.sender] = message
        if message.recipient not in user_lastmsgs and message.recipient != request.user:
            user_lastmsgs[message.recipient] = message
    msg_unreads = {}
    for user in user_lastmsgs:
        msg_unreads[user] = message_count_unread(user, request.user)
    msg_counts = {}
    for user in user_lastmsgs:
        msg_counts[user] = message_count_all(user, request.user)
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'私信'}]
    return render_template(template_name, request, users = user_lastmsgs, unreads = msg_unreads, msgcounts = msg_counts, breadcrumb=breadcrumb, condition=condition)
Exemplo n.º 3
0
def change(request):
    notice_settings = NoticeSetting.objects.myself(request.user)
    
    if request.method == "POST":
        form = NoticeSettingForm(request.POST, user=request.user)
        if form.is_valid():
            for notice_setting in notice_settings:
                notice_setting.flags = devices_set_true(notice_setting.flags, form.cleaned_data[notice_setting.notice_type.label])
                notice_setting.save()
            messages.success(request, u"成功修改通知")
            
            return redirect(reverse("notification.views.change"))
    else:
        data = {}
        for notice_setting in notice_settings:
            data[notice_setting.notice_type.label] = notice_setting.devices_tuple()
        form = NoticeSettingForm(data, user=request.user)
    
    current_nav = u"设置"
    breadcrumbs = [
        {"name":u"通知中心", "url":reverse("notification.views.home")},
        {"name":current_nav},
    ]
    return render_template("notification/change.html", form=form, request=request, breadcrumbs=breadcrumbs, 
                           current_nav=current_nav)
Exemplo n.º 4
0
def compose(request, recipient=None, form_class=ComposeForm,
        template_name='compose.html', success_url=None, recipient_filter=None):
    """
    Displays and handles the ``form_class`` form to compose new messages.
    Required Arguments: None
    Optional Arguments:
        ``recipient``: username of a `django.contrib.auth` User, who should
                       receive the message, optionally multiple usernames
                       could be separated by a '+'
        ``form_class``: the form-class to use
        ``template_name``: the template to use
        ``success_url``: where to redirect after successfull submission
    """
    if request.method == "POST":
        form = form_class(request.POST, recipient_filter=recipient_filter)
        if form.is_valid():
            form.save(sender=request.user)
            messages.info(request, u"Message successfully sent.")
            if success_url is None:
                success_url = reverse('messages_view')
            if request.GET.has_key('next'):
                success_url = request.GET['next']
            return HttpResponseRedirect(success_url)
    else:
        form = form_class()
        if recipient is not None:
            recipients = [u for u in User.objects.filter(**{'%s__in' % 'username': [r.strip() for r in recipient.split('+')]})]
            form.fields['recipient'].initial = recipients
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'私信','url':'/msg/view/'},{'name': u'写私信 '}]
    return render_template(template_name, request, form = form, breadcrumb=breadcrumb)
Exemplo n.º 5
0
def prepare_reset_password(request):
    statu = None
    msg = None
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'忘记密码'}]

    if request.method == "POST":
        form = PrepareResetPasswordForm(request.POST)
        if form.is_valid():
            statu = "ok"
            msg = u"我们已经按你所提交的电子邮箱地址发送了密码设置说明.你应该很快就能收到这封邮件."
            django_user = DjangoUser.objects.filter(
                email=form.cleaned_data["email"])[0]
            token = default_token_generator.make_token(django_user)
            urllink = reverse("account.views.reset_password",
                              args=(
                                  django_user.id,
                                  token,
                              ))

            email_data = {"urllink": urllink, "user": django_user}
            email_data["domain"] = DOMAIN
            email_data["protocol"] = PROTOCOL
            email_data["connectus"] = CONNECT_US
            send_html_template_email(u"密码重置", "auth_email.html", email_data,
                                     [django_user.email], [])
    else:
        form = PrepareResetPasswordForm()

    return render_template("prepare_reset_password.html",
                           request,
                           form=form,
                           breadcrumb=breadcrumb,
                           statu=statu,
                           msg=msg)
Exemplo n.º 6
0
def home(request):
    if request.POST:
        form = VerificationCodeForm(request.POST)
        if form.is_valid():
            return HttpResponseRedirect(request.path + '?ok')
    else:
        form = VerificationCodeForm()
    return render_template('home.html', request, form=form)
Exemplo n.º 7
0
def home(request):
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'个人中心'}]
    filename = os.path.join(USER_ICONS_PATH, "%s.jpg" % request.user.username)
    icon = None
    if os.path.isfile(filename):
        icon = "%s/%s.jpg" % (USER_ICON_DIR, request.user.username)
    return render_template("auth_userhome.html",
                           request,
                           use=request.user,
                           breadcrumb=breadcrumb,
                           icon=icon)
Exemplo n.º 8
0
def home(request, page_no=1):
    notices = Notice.objects.filter(user=request.user)
    notices_page = get_page(notices, page_no, config.PAGE_SIZE)
    prefix = reverse("notification.views.home")
    
    current_nav = u"通知中心"
    breadcrumbs = [
        {"name": current_nav},
    ]
    return render_template("notification/home.html", request=request, prefix=prefix, \
                           notices_page=notices_page, breadcrumbs=breadcrumbs,
                           current_nav=current_nav)
Exemplo n.º 9
0
def change_password(request):
    redirect_url = reverse("account.views.home")

    if request.method == "POST":
        form = ChangePasswordForm(user=request.user, data=request.POST)
        if form.is_valid():
            form.save(commit=True)
            return redirect(redirect_url)
    else:
        form = ChangePasswordForm(user=request.user)

    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'修改密码'}]
    return render_template("change_password.html", request, form=form, breadcrumb=breadcrumb)
Exemplo n.º 10
0
def change_password(request):
    redirect_url = reverse("account.views.home")

    if request.method == "POST":
        form = ChangePasswordForm(user=request.user, data=request.POST)
        if form.is_valid():
            form.save(commit=True)
            return redirect(redirect_url)
    else:
        form = ChangePasswordForm(user=request.user)

    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'修改密码'}]
    return render_template("change_password.html", request, form=form, breadcrumb=breadcrumb)
Exemplo n.º 11
0
def view_detail(request, username, template_name='view_detail.html'):
    """
    Shows a single message.``message_id`` argument is required.
    The user is only allowed to see the message, if he is either 
    the sender or the recipient. If the user is not allowed a 404
    is raised. 
    If the user is the recipient and the message is unread 
    ``read_at`` is set to the current datetime.
    """
    session_user = User.objects.get(username=username)
    message_list = Message.objects.messages_between(request.user, session_user)
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'私信','url':'/msg/view/'},{'name': u'与 ' + session_user.username + u'的会话'}]
    #Message.objects.filter(recipient=request.user, sender=recipients[0], read_at__isnull=True).update(read_at=datetime.datetime.now())
    return render_template(template_name, request, message_list = message_list, session_user= session_user, breadcrumb=breadcrumb)
Exemplo n.º 12
0
def reset_password(request, userid, token):
    msg = ""
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'重置密码'}]

    try:
        django_user = DjangoUser.objects.get(id=userid)
        if not default_token_generator.check_token(django_user, token):
            msg = u"参数错误!"
            form = ResetPasswordForm(user=django_user)
            return render_template("reset_password.html", request, breadcrumb=breadcrumb, msg=msg, form=form)
    except ObjectDoesNotExist:
        msg = u"该用户不存在!"
        form = ResetPasswordForm(user=None)
        return render_template("reset_password.html", request, breadcrumb=breadcrumb, msg=msg, form=form)

    if request.method == "POST":
        form = ResetPasswordForm(user=django_user, data=request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse("account.views.login"))
    else:
        form = ResetPasswordForm(user=django_user)

    return render_template("reset_password.html", request, breadcrumb=breadcrumb, msg=msg, form=form)
Exemplo n.º 13
0
def reset_password(request, userid, token):
    msg = ""
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'重置密码'}]

    try:
        django_user = DjangoUser.objects.get(id=userid)
        if not default_token_generator.check_token(django_user, token):
            msg = u"参数错误!"
            form = ResetPasswordForm(user=django_user)
            return render_template("reset_password.html", request, breadcrumb=breadcrumb, msg=msg, form=form)
    except ObjectDoesNotExist:
        msg = u"该用户不存在!"
        form = ResetPasswordForm(user=None)
        return render_template("reset_password.html", request, breadcrumb=breadcrumb, msg=msg, form=form)

    if request.method == "POST":
        form = ResetPasswordForm(user=django_user, data=request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse("account.views.login"))
    else:
        form = ResetPasswordForm(user=django_user)

    return render_template("reset_password.html", request, breadcrumb=breadcrumb, msg=msg, form=form)
Exemplo n.º 14
0
def change_user_icon(request):
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'修改头像'}]
    redirect_url = reverse("account.views.change_user_icon")
    redirect_url = "%s?%s" % (redirect_url, time.time())
    status = ""

    if request.method == "POST":
        form = ChangeUserIconForm(request.POST, request.FILES)
        if form.is_valid():
            if handle_uploaded_file(request.FILES["upload_file"], request.user.username):
                return redirect(redirect_url)
            else:
                status = "upload_failed"
    else:
        form = ChangeUserIconForm()

    return render_template("change_user_icon.html", request, breadcrumb=breadcrumb, form=form, status=status)
Exemplo n.º 15
0
def login(request):
    next_url = request.GET.get("next", None)
    if next_url:
        redirect_url = next_url
    else:
        redirect_url = reverse("account.views.home")

    if request.user.is_authenticated():
        return redirect(redirect_url)

    if request.method == "POST":
        form = LoginForm(data=request.POST)
        if form.is_valid():
            djangologin(request, form.get_user())
            return redirect(redirect_url)
    else:
        form = LoginForm()

    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'登录'}]
    return render_template("login.html", request, form=form, breadcrumb=breadcrumb)
Exemplo n.º 16
0
def login(request):
    next_url = request.GET.get("next", None)
    if next_url:
        redirect_url = next_url
    else:
        redirect_url = reverse("account.views.home")

    if request.user.is_authenticated():
        return redirect(redirect_url)

    if request.method == "POST":
        form = LoginForm(data=request.POST)
        if form.is_valid():
            djangologin(request, form.get_user())
            return redirect(redirect_url)
    else:
        form = LoginForm()

    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'登录'}]
    return render_template("login.html", request, form=form, breadcrumb=breadcrumb)
Exemplo n.º 17
0
def home(request, page_no=1):
    notices = Notice.objects.filter(user=request.user) 
    prefix = reverse("notification.views.home")
    current_nav = u"通知中心"
    breadcrumbs = [
        {"name": current_nav},
    ]
    NoticeList.objects.all().delete()
    for notice in notices:
        add_datetime_timestamp = time.mktime(notice.add_datetime.timetuple())
        add_datetime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(add_datetime_timestamp))
        if notice.is_read == 1:
            NoticeList.push(add_datetime=add_datetime, content=notice.content) 
        else:
            info_url=reverse("notification.views.go",args=[notice.id])
            content="<a href=\"%s\" target=\"_blank\" >%s</a>" % (info_url, notice.content)
            NoticeList.push(add_datetime=add_datetime, content=content)
    show_notices = NoticeTable()
    return render_template("notification/home.html", request=request, prefix=prefix, \
                           show_notices=show_notices, breadcrumbs=breadcrumbs,
                           current_nav=current_nav)
Exemplo n.º 18
0
def change_user_icon(request):
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'修改头像'}]
    redirect_url = reverse("account.views.home")

    if request.method == "POST":
        form = ChangeUserIconForm(request.POST, request.FILES)
        if form.is_valid():
            if handle_uploaded_file(request.FILES["upload_file"],
                                    request.user.username):
                return redirect(redirect_url)
            else:
                form._errors = {
                    "__all__": [u"文件上传失败!"]
                }  # __all__ will set error-msg into non_field_error
    else:
        form = ChangeUserIconForm()

    return render_template("change_user_icon.html",
                           request,
                           breadcrumb=breadcrumb,
                           form=form)
Exemplo n.º 19
0
def prepare_reset_password(request):
    statu = None
    msg = None
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'忘记密码'}]

    if request.method == "POST":
        form = PrepareResetPasswordForm(request.POST)
        if form.is_valid():
            statu = "ok"
            msg = u"我们已经按你所提交的电子邮箱地址发送了密码设置说明.你应该很快就能收到这封邮件."
            django_user = DjangoUser.objects.filter(email=form.cleaned_data["email"])[0]
            token = default_token_generator.make_token(django_user)
            urllink = reverse("account.views.reset_password", args=(django_user.id, token, ))

            email_data = {"urllink": urllink, "user": django_user}
            email_data["domain"] = DOMAIN
            email_data["protocol"] = PROTOCOL
            email_data["connectus"] = CONNECT_US
            send_html_template_email(u"密码重置", "auth_email.html", email_data, [django_user.email], [])
    else:
        form = PrepareResetPasswordForm()

    return render_template("prepare_reset_password.html", request,
                           form=form, breadcrumb=breadcrumb, statu=statu, msg=msg)
Exemplo n.º 20
0
 def test_render_template(self):
     response = render_template('email.html', None, username='******')
     self.assertEquals(
         response.content,
         '<html>\r\n<body>\r\nhello <strong>render_test</strong>\r\nyour account activated.\r\n</body>\r\n</html>'
     )
Exemplo n.º 21
0
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password1"]
            try:
                django_user = form.save()
                if REGISTER_AUTO_LOGIN:
                    django_user = authenticate(username=username, password=password)
                    djangologin(request, django_user)
                return redirect(redirect_url)
            except Exception, e:
                logging.error("failed to register: %s" % e)
                DjangoUser.objects.filter(username=username).delete()
    else:
        form = RegisterForm()

    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'注册'}]
    return render_template("register.html", request, form=form, breadcrumb=breadcrumb)


def login(request):
    next_url = request.GET.get("next", None)
    if next_url:
        redirect_url = next_url
    else:
        redirect_url = reverse("account.views.home")

    if request.user.is_authenticated():
        return redirect(redirect_url)

    if request.method == "POST":
        form = LoginForm(data=request.POST)
        if form.is_valid():
Exemplo n.º 22
0
 def test_render_template(self):
     response = render_template('email.html', None, username = '******')
     self.assertEquals(response.content, '<html>\n<body>\nhello <strong>render_test</strong>\nyour account activated.\n</body>\n</html>')
Exemplo n.º 23
0
def home(request):
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'个人中心'}]
    return render_template("auth_userhome.html", request, use=request.user, breadcrumb=breadcrumb)
Exemplo n.º 24
0
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password1"]
            try:
                django_user = form.save()
                if REGISTER_AUTO_LOGIN:
                    django_user = authenticate(username=username, password=password)
                    djangologin(request, django_user)
                return redirect(redirect_url)
            except Exception, e:
                logging.error("failed to register: %s" % e)
                DjangoUser.objects.filter(username=username).delete()
    else:
        form = RegisterForm()

    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'注册'}]
    return render_template("register.html", request, form=form, breadcrumb=breadcrumb)


def login(request):
    next_url = request.GET.get("next", None)
    if next_url:
        redirect_url = next_url
    else:
        redirect_url = reverse("account.views.home")

    if request.user.is_authenticated():
        return redirect(redirect_url)

    if request.method == "POST":
        form = LoginForm(data=request.POST)
        if form.is_valid():
Exemplo n.º 25
0
def home(request):
    breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'个人中心'}]
    return render_template("auth_userhome.html", request, use=request.user, breadcrumb=breadcrumb)