コード例 #1
0
ファイル: general.py プロジェクト: Yellowen/daarmaan
def login_view(request):
    username = request.POST['username']
    password = request.POST['password']
    remember = request.POST.get("remember_me", False)
    next_url = request.POST.get("next", None)
    form = PreRegistrationForm()

    user = authenticate(username=username,
                        password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            setup_session(request)

            if next_url:
                return HttpResponseRedirect("/")

            return redirect(reverse(
                "dashboard-index",
                args=[]))
        else:
            return rr("index.html", {"regform": form,
                                     "msgclass": "error",
                                     "next": next_url,
                                     "msg": _("Your account is disabled.")},
                          context_instance=RequestContext(request))

    else:
        return rr("index.html", {"regform": form,
                                 "msgclass": "error",
                                 "next": next_url,
                                 "msg": _("Username or Password is invalid.")},
                  context_instance=RequestContext(request))
コード例 #2
0
ファイル: update.py プロジェクト: pinkdawn/xmwq.net
def change_avatar(req):
    msg = ''
    if req.method == 'GET':
        avatar_form = new_avatar_form()
        try:
            avatar_form.instance = req.user.get_profile()
        except:
            pass
    elif req.method == 'POST':
        avatar_form = new_avatar_form(req.POST)
        if avatar.objects.filter(user=req.user):
            _a = avatar.objects.filter(user=req.user)[0]
        else :
            _a = avatar()
            _a.user = req.user
        if req.FILES.has_key('avatar'):
            _img = req.FILES['avatar']
                
            if _img.size < 50*1024:                
                _a.avatar = upload_and_replace('avatar',_img,str(_a.user.id))
            else:
                msg = "图片大小要小于50kb!"
                return rr('user/change_avatar.htm',
                    {'avatar_form':avatar_form,'msg':msg, },
                    context_instance = RequestContext(req))
            
        _a.desc = req.POST['desc']
        _a.save()
        return rd('/')
    return rr('user/change_avatar.htm',
            {'avatar_form':avatar_form,'msg':msg, },
            context_instance = RequestContext(req)) 
コード例 #3
0
ファイル: views.py プロジェクト: Yellowen/ultra_blog
def edit_category(request, id):
    """
    Edit a post.
    """
    site = get_site(request)

    try:
        instance = Category.objects.get(site=site, id=id)
    except Category.DoesNotExist:
        raise Http404()

    form = CategoryForm(site, request.POST, instance=instance)
    if form.is_valid():
        from django.db import IntegrityError
        try:
            m = form.save()
        except IntegrityError:
            return rr("ublog/dashboard/form.html",
                      {"url": reverse("edit-category", args=[id]),
                       "title": _("Edit Category"),
                       "form": form,
                       "msg": _("A category with this title already exists."),
                       "msgclass": "error"},
                      context_instance=RequestContext(request))

        return HttpResponseRedirect(reverse("categories", args=[]))
    else:
        form = CategoryForm(site, instance=instance)
        return rr("ublog/dashboard/form.html",
                  {"url": reverse("edit-category", args=[id]),
                   "title": _("Edit Category"),
                   "form": form},
                  context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: Yellowen/vanda
def post_register(request):
    """
    Complete the registeration by asking user to fill extra information.
    """

    user = None
    if "user" in request.session:
        user = request.session["user"]
    else:
        return HttpResponseForbidden()

    if request.method == "POST":
        form = PostRegistrationForm(request.POST)
        if form.is_valid():
            try:
                form.save(user)
            except form.PasswordError, e:
                form.errors["password1"] = unicode(e)
                form.errors["password2"] = unicode(e)
                return rr("post_registeration.html",
                          {"form": form},
                          context_instance=RequestContext(request))

            user = authenticate(username=user.username,
                                password=form.cleaned_data["password1"])
            login(request, user)
            return HttpResponseRedirect(reverse("auth.views.profile",
                                                args=[]))
        else:
            return rr("post_registeration.html",
                          {"form": form},
                          context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: Yellowen/Sharamaan
def login_view(request):

    if request.method == "POST":
        form = LoginForm(request.POST)
        next_ = request.POST.get("next", "/")

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            user = authenticate(username=username, password=password)

            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect(next_)
                else:
                    return rr("registration/login.html",
                              {"msg": _("Your account is not active.")},
                              context_instance=RequestContext(request))
            else:
                return rr("registration/login.html",
                          {"msg": _("username or password is incorrect.")},
                          context_instance=RequestContext(request))

    else:
        next_ = request.GET.get("next", "/")
        if request.user.is_authenticated():
            return HttpResponseRedirect(next_)

        return rr("registration/login.html", {"next": next_},
                  context_instance=RequestContext(request))
コード例 #6
0
ファイル: new.py プロジェクト: pinkdawn/xmwq.net
def new(req): #new user
    msg = ''
    if req.method == 'GET':
        avatar_form = new_avatar_form()
        userAddForm = UserCreationForm()        
    elif req.method == 'POST':
        userAddForm = UserCreationForm(req.POST)
        avatar_form = new_avatar_form(req.POST)
        if userAddForm.is_valid():
            _a = avatar()
            _a.desc = req.POST['desc']            
            
            if req.FILES.has_key('avatar'): # 如果有上传图像
                _img = req.FILES['avatar']
                if _img.size < 50*1024: # 图片大小合适
                    userAddForm.save()                    
                    _a.avatar = upload_and_replace('avatar',_img,str(userAddForm.instance.id))
                else: # 图片过大
                    msg = "图片大小要小于50kb!"
                    return rr('user/new.htm',
                        {'userAddForm':userAddForm, 'avatar_form':avatar_form,'msg':msg, },
                        context_instance = RequestContext(req))
            else: #没有上传图像,保存新建用户的请求,保存avatar。
                userAddForm.save()
            
            _a.user = userAddForm.instance
            _a.save()
            return rd('/')
    return rr('user/new.htm',
            {'userAddForm':userAddForm, 'avatar_form':avatar_form,'msg':msg, },
            context_instance = RequestContext(req))
        
コード例 #7
0
ファイル: views.py プロジェクト: Yellowen/ultra_blog
def add_category(request):
    """
    Add view.
    """
    site = get_site(request)

    if request.method == "POST":
        form = CategoryForm(site, request.POST)
        if form.is_valid():
            from django.db import IntegrityError
            try:
                m = form.save()
            except IntegrityError:
                return rr("ublog/dashboard/form.html",
                          {"url": reverse("add-category", args=[]),
                           "title": _("Add Category"),
                           "form": form,
                           "msg": _("A category with this title already exists."),
                           "msgclass": "error"},
                          context_instance=RequestContext(request))

            return HttpResponseRedirect(reverse("categories", args=[]))
    else:
        form = CategoryForm(site)
        return rr("ublog/dashboard/form.html",
                  {"url": reverse("add-category", args=[]),
                   "title": _("Add Category"),
                   "form": form},
                  context_instance=RequestContext(request))
コード例 #8
0
ファイル: views.py プロジェクト: Yellowen/vanda
def pre_register(request):
    """
    First step of registeration process. In this step we process
    just username and email address and send a verification mail.
    """
    if request.method == "POST":
        form = PreRegistrationForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data

            # collect queries in a single transaction
            with transaction.commit_on_success():
                email = User.objects.filter(email=data["email"])
                user = User.objects.filter(username=data["username"])

            if email or user:
                # returning suitable error if email or user already registered
                if email:
                    form.errors["email"] = (
                        _("This Email already registered."), )
                if user:
                    form.errors["usernmae"] = (
                        _("This Username already registered."), )
                return rr("pre_registeration.html",
                      {"form": form},
                      context_instance=RequestContext(request))

            else:
                # Create a user and send the verification mail
                user = User(username=data["username"], email=data["email"],
                                    is_active=False)
                user.save()

                # create verification code and save it in DB
                verification_code = Verification(user=user)
                code = verification_code.create_verification_code()

                vmail = VerificationMail(user, code, request.META["HTTP_HOST"])
                vmail.send()
                return rr("verification_sent.html")

        else:
            return rr("pre_registeration.html",
                      {"form": form},
                      context_instance=RequestContext(request))
    else:
        form = PreRegistrationForm()
        return rr("pre_registeration.html",
                  {"form": form},
                  context_instance=RequestContext(request))
コード例 #9
0
ファイル: views.py プロジェクト: Yellowen/vanda
def verificate_email(request, code):
    """
    Get the verification code and verify the user mail.
    """
    # Look for given verification code
    try:
        verification = Verification.objects.get(code=code)

    except Verification.DoesNotExist:
        # always riase a 404 status code for invalid code
        raise Http404()

    # if verification code sent ins last 48 hours
    if verification.is_valid():
        # Activating user
        user = verification.user
        user.is_active = True
        user.save()

        request.session["user"] = user
        verification.delete()

        form = PostRegistrationForm()
        return rr("post_registeration.html",
                  {"form": form},
                  context_instance=RequestContext(request))
    else:
        # If code expired.
        verification.delete()
        raise Http404()
コード例 #10
0
ファイル: views.py プロジェクト: gitter-badger/TehPUG
def ajax(request):
    """
    load news with ajax
    """
    lang = translation.get_language()
    news = News.objects.filter(lang=lang).order_by('-date')

    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    try:
        count = int(request.GET.get('count', '10'))
    except ValueError:
        count = 10

    if not 1 < count < 20:
        count = 10

    p = Paginator(news, count)

    try:
        return rr('ajax.html',
                  {'news_list': p.page(page)},
                  context_instance=RequestContext(request))
    except (EmptyPage, InvalidPage):
        return HttpResponse('')
コード例 #11
0
ファイル: views.py プロジェクト: Yellowen/Sharamaan
def erb(request, path):
    """
    Serv the erb templates for backbone
    """
    template = "erb/%s" % path.replace("..", "")
    return rr(template, {},
              context_instance=RequestContext(request))
コード例 #12
0
ファイル: blog.py プロジェクト: Yellowen/ultra_blog
def view_post(request, slug):
    """
    View a single post.
    """

    domain = request.get_host()
    try:
        site = Site.objects.get(domain=domain)
    except Site.DoesNotExist:
        raise Http404()

    post = get_object_or_404(Post, slug=slug)

    from django.contrib.comments.models import Comment


    comments = Comment.objects.filter(site=site,
                                      content_type__name='Post',
                                      content_type__app_label="ultra_blog",
                                      object_pk=post.pk,
                                      is_public=True)

    return rr("ublog/view_post.html",
              {"post": post,
               "comments_list": comments},
              context_instance=RequestContext(request))
コード例 #13
0
ファイル: blog.py プロジェクト: Yellowen/ultra_blog
def view_category(request, category):
    """
    Render the lastest blog entries in specific category.
    """
    ppp = Setting.get_setting("post_per_page")
    try:
        cat = Category.objects.get(slug=category)
    except Category.DoesNotExist:
        raise Http404()

    post_list = cat.ultra_blog_posts.all()
    paginator = Paginator(post_list, ppp)

    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    try:
        posts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        postss = paginator.page(paginator.num_pages)

    return rr('ublog/index.html',
              {"posts": posts,
               "category_name": category,
               "types": post_types.get_types_complex(),
               "rssfeed": "/blog/feed/category/%s/" % category},
              context_instance=RequestContext(request))
コード例 #14
0
ファイル: blog.py プロジェクト: Yellowen/ultra_blog
def view_tag(request, tag):
    """
    Render the lastest blog entries with specifc tag.
    """
    from tagging.models import Tag, TaggedItem

    ppp = Setting.get_setting("post_per_page")
    try:
        tagobj = Tag.objects.get(name=tag)
    except Tag.DoesNotExist:
        raise Http404()

    post_list = TaggedItem.objects.get_by_model(Post, tagobj)
    paginator = Paginator(post_list, ppp)

    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    try:
        posts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        postss = paginator.page(paginator.num_pages)

    return rr('ublog/index.html',
              {"posts": posts,
               "types": post_types.get_types_complex(),
               "rssfeed": "/blog/feed/"},
              context_instance=RequestContext(request))
コード例 #15
0
def books_index(request):
    """
    Main index of registered books.
    """
    books = Book.objects.all().order_by("weight")
    book_per_page = 4
    try:
        book_per_page = settings.BOOK_IN_PAGE
    except AttributeError:
        pass
    paginator = Paginator(books, book_per_page)

    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    try:
        books_list = paginator.page(page)
    except (EmptyPage, InvalidPage):
        # if provided page value in GET was out of range
        books_list = paginator.page(paginator.num_pages)

    return rr("books.html", {"books": books_list},
              context_instance=RequestContext(request))
コード例 #16
0
ファイル: views.py プロジェクト: Yellowen/Sharamaan
def index(request):
    """
    Temprorary index page.
    """
    return rr("index.html",
              {},
              context_instance=RequestContext(request))
コード例 #17
0
ファイル: buttons.py プロジェクト: Yellowen/daarmaan
 def widgets_list(self, request):
     widgets = list(self.dashboard.widgets)
     #widgets = [i.name for i in widgets]
     return rr("dashboard/widgets/add_widgets.html",
               {"widgets": widgets,
                "self": self},
               context_instance=RequestContext(request))
コード例 #18
0
ファイル: profile.py プロジェクト: Yellowen/daarmaan
    def edit(self, request):
        """
        Edit view for basic user profile.
        """
        from daarmaan.server.forms import EditBasicProfile

        if not request.user.is_authenticated():
            return HttpResponseRedirect('/?next=%s' % reverse(self.edit,
                                                              args=[]))
        user = request.user
        profile = self._get_user_profile(user)

        if request.method == "POST":
            form = EditBasicProfile(user, instance=profile, data=request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse("profile-home",
                                                    args=[]))
        else:
            form = EditBasicProfile(user, instance=profile)

        return rr(self.edit_profile_template,
                  {"form": form,
                   "user": user},
                  context_instance=RequestContext(request))
コード例 #19
0
ファイル: user_homepage.py プロジェクト: ShervinAra/MyBlog
def user_homepage(request,user):
    contexts = context.user_post(request.user)
    return  rr('home.html',
               {'now':now,
                'contexts':contexts,
                'user':user},
                context_instance=RequestContext(request))
コード例 #20
0
ファイル: views.py プロジェクト: Yellowen/ultra_blog
def posts(request):
    """
    Posts index.
    """
    return rr("ublog/dashboard/grid.html",
              {"url": reverse("ultra_blog.dashboard.views.posts_json",
                              args=[])},
              context_instance=RequestContext(request))
コード例 #21
0
ファイル: base.py プロジェクト: Yellowen/vanda
 def render(self, request):
     """
     Render the final template.
     """
     context = self._prepare_context()
     context.update(self.extra_context)
     return rr(self.template, context,
               context_instance=RequestContext(request))
コード例 #22
0
ファイル: buttons.py プロジェクト: Yellowen/daarmaan
 def config_form(self, request):
     if request.method == "POST":
         pass
     else:
         form = self.form()
         return rr(form.template,
                 {"form": form,
                  "self": self},
                 context_instance=RequestContext(request))
コード例 #23
0
ファイル: views.py プロジェクト: marcinch18/karajlug
def index(request):
    """
    show the whole index
    """
    request.session['django_language']
    faqs = FAQ.objects.all()
    return rr("faq.html",
              {"faq": faqs, },
              context_instance=RequestContext(request))
コード例 #24
0
def index(request):
    """
    show the whole index
    """
    faqs = FAQ.objects.all()
    return rr("faq.html", {
        "faq": faqs,
    },
              context_instance=RequestContext(request))
コード例 #25
0
ファイル: views.py プロジェクト: Yellowen/vanda
def ajax_js(request):
    """
    Return a suitable javascript code for given url.
    """
    url = request.GET.get("validator", None)
    if url:
        return rr("validator.js", {"url": url})
    else:
        raise Http404()
コード例 #26
0
ファイル: views.py プロジェクト: thetoppython/TehPUG
def projects_index(request):
    """
    project index page
    """
    projects = Project.objects.all().order_by("weight")
    # god damn b3hnam's server
    projects = [(i + 1, j) for i, j in enumerate(projects)]
    # ---
    return rr("projects.html", {"projects": projects},
              context_instance=RequestContext(request))
コード例 #27
0
def book_view(request, slug):
    """
    View of each Book
    """
    try:
        book = Book.objects.get(slug=slug)
    except Book.DoesNotExist:
        raise Http404()
    return rr("book_view.html", {"book": book},
              context_instance=RequestContext(request))
コード例 #28
0
ファイル: views.py プロジェクト: Karajlug/karajlug
def members_index(request):
    """
    Main index of members.
    """
    members = Member.objects.all().order_by("weight")
    # god damn b3hnam's server
    members = [(i + 1, j) for i, j in enumerate(members)]
    # ---
    return rr("members.html", {"members": members},
              context_instance=RequestContext(request))
コード例 #29
0
def members_index(request):
    """
    Main index of members.
    """
    members = Member.objects.all().order_by("weight")
    # god damn b3hnam's server
    members = [(i + 1, j) for i, j in enumerate(members)]
    # ---
    return rr("members.html", {"members": members},
              context_instance=RequestContext(request))
コード例 #30
0
def index(request):
    """
    show the whole index
    """
    request.session['django_language']
    faqs = FAQ.objects.all()
    return rr("faq.html", {
        "faq": faqs,
    },
              context_instance=RequestContext(request))
コード例 #31
0
ファイル: views.py プロジェクト: Karajlug/karajlug
def projects_index(request):
    """
    project index page
    """
    projects = Project.objects.all().order_by("weight")
    # god damn b3hnam's server
    projects = [(i + 1, j) for i, j in enumerate(projects)]
    # ---
    return rr("projects.html",
              {"projects": projects},
              context_instance=RequestContext(request))
コード例 #32
0
ファイル: views.py プロジェクト: thetoppython/TehPUG
def index(request):
    """
    index view of tehpug.ir
    """
    lang = translation.get_language()
    try:
        page = FirstPage.objects.filter(lang=lang).latest("date")
    except FirstPage.DoesNotExist:
        page = None

    return rr("index.html", {"page": page},
              context_instance=RequestContext(request))
コード例 #33
0
ファイル: views.py プロジェクト: pinkdawn/xmwq.net
def home(req):
#    _as = article.objects.order_by('-time')[:6]
    _cats = category.objects.all()
    _cats_dict = []
    for _cat in _cats:
        _threads = [x._t for x in category_thread.objects.order_by('-_t__time').filter(_c = _cat)[:6]]
        _cats_dict.append([_cat, _threads])
    
    return rr('home.html',
            {#'articles':_as, 
             'categories':_cats_dict,},
            context_instance = RequestContext(req))
コード例 #34
0
ファイル: views.py プロジェクト: Yellowen/ultra_blog
    def on_invalid_form(form):
            rendered_form = rs("ublog/dashboard/forms.html",
                               {"action":
                                reverse("ultra_blog.dashboard.views.new_post",
                                        args=[]),
                                "form": form},
                               context_instance=RequestContext(request))

            return rr("ublog/dashboard/page.html",
                      {"content": rendered_form,
                       "title": _("New Post")},
                      context_instance=RequestContext(request))
コード例 #35
0
ファイル: views.py プロジェクト: gitter-badger/TehPUG
def index(request):
    """
    index view of tehpug.ir
    """
    lang = translation.get_language()
    try:
        page = FirstPage.objects.filter(lang=lang).latest("date")
    except FirstPage.DoesNotExist:
        page = None

    return rr("index.html", {"page": page},
              context_instance=RequestContext(request))
コード例 #36
0
def index(request):
    """
    index view of karajlug.org
    """
    news = News.objects.all().order_by("-date")[:settings.NEWS_LIMIT]
    try:
        page = FirstPage.objects.latest("date")
    except FirstPage.DoesNotExist:
        page = None
    return rr("index.html", {
        "news_list": news,
        "page": page,
    },
              context_instance=RequestContext(request))
コード例 #37
0
def show_page(request, slug):
    """
    show the page with the given slug
    """
    try:
        page = Page.objects.get(slug=slug, publish=True)

    except Page.DoesNotExist:
        raise Http404()

    return rr("page.html", {
        "page": page,
        "title": "%s | %s" % (_("Karajlug"), page.title)
    },
              context_instance=RequestContext(request))
コード例 #38
0
ファイル: views.py プロジェクト: gitGNU/gnu_karajlug
def news_entry(request, id_=None):
    """
    Show a single news entry.
    """
    if not id_:
        raise Http404()

    try:
        news_ent = News.objects.get(id=id_)

    except News.DoesNotExist:
        raise Http404()

    return rr('news_view.html', {'news': news_ent},
              context_instance=RequestContext(request))
コード例 #39
0
def member_view(request, id):
    """
    View each member details.
    """
    from models import MemberDetail

    try:
        member = Member.objects.get(id=id)
    except Member.DoesNotExist:
        raise Http404()

    # TODO: lang code here
    details = MemberDetail.objects.filter(member=member).order_by("weight")
    return rr("member_view.html", {
        "member": member,
        "details": details
    },
              context_instance=RequestContext(request))
コード例 #40
0
ファイル: views.py プロジェクト: gitGNU/gnu_karajlug
def index(request):
    """
    show all the news with pagination.
    """
    news = News.objects.all().order_by('-date')
    p = Paginator(news, settings.NEWS_LIMIT)

    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    try:
        news_page = p.page(page)
    except (EmptyPage, InvalidPage):
        news_page = p.page(p.num_pages)

    return rr('news_list.html', {'news': news_page},
              context_instance=RequestContext(request))
コード例 #41
0
ファイル: views.py プロジェクト: thetoppython/TehPUG
def project_view(request, slug):
    """
    Project view
    """
    try:
        project = Project.objects.get(slug=slug)
    except Project.DoesNotExist:
        raise Http404()

    if project.vcs:
        vcsdict = dict(Project.VCS)
        project.vcs = vcsdict[project.vcs]

    repos = Repository.objects.filter(project=project).order_by("weight")
    return rr("project_view.html", {
        "project": project,
        "repositories": repos
    },
              context_instance=RequestContext(request))
コード例 #42
0
def index(request):
    return rr('donate.html', {}, context_instance=RequestContext(request))
コード例 #43
0
ファイル: views.py プロジェクト: thetoppython/TehPUG
def contact(request):
    return rr("contact.html", context_instance=RequestContext(request))