Esempio n. 1
0
def view_delusermilestone(session, request, collection):
    """ Handle user login """

    referer = request.META.get('HTTP_REFERER', None)
    if referer is None:
        redirect_to = 'ddtss_index'
    try:
        redirect_to = urlsplit(referer, 'http', False)[2]
    except IndexError:
        redirect_to = 'ddtss_index'

    user = get_user(request, session)

    if not user.logged_in:
        return show_message_screen(request, 'Only for login user',
                                   'ddtss_login')

    collectionmilestone = session.query(CollectionMilestone) \
            .filter(CollectionMilestone.collection==collection) \
            .filter(CollectionMilestone.name==user.username) \
            .filter(CollectionMilestone.nametype==CollectionMilestone.NAME_TYPE_USER) \
            .one()

    if collectionmilestone:
        session.delete(collectionmilestone)
        session.commit()

        return redirect(redirect_to)

    return HttpResponseForbidden('<h1>Forbidden</h1>')
Esempio n. 2
0
def view_addusermilestone(session, request, collectiontype, collection):
    """ Handle user login """

    referer = request.META.get('HTTP_REFERER', None)
    if referer is None:
        redirect_to = 'ddtss_index'
    try:
        redirect_to = urlsplit(referer, 'http', False)[2]
    except IndexError:
        redirect_to = 'ddtss_index'

    user = get_user(request, session)

    if not user.logged_in:
        return show_message_screen(request, 'Only for login user',
                                   'ddtss_login')

    collectionmilestone = CollectionMilestone(
        name=user.username,
        nametype=CollectionMilestone.NAME_TYPE_USER,
        collection=collectiontype + ':' + collection)
    session.add(collectionmilestone)
    try:
        session.commit()
    except:
        messages.error(request, "Error")

    return redirect(redirect_to)
Esempio n. 3
0
def view_delusermilestone(session, request, collection):
    """ Handle user login """

    referer = request.META.get('HTTP_REFERER', None)
    if referer is None:
        redirect_to='ddtss_index'
    try:
        redirect_to = urlsplit(referer, 'http', False)[2]
    except IndexError:
        redirect_to='ddtss_index'

    user = get_user(request, session)

    if not user.logged_in:
        return show_message_screen(request, 'Only for login user', 'ddtss_login')

    collectionmilestone = session.query(CollectionMilestone) \
            .filter(CollectionMilestone.collection==collection) \
            .filter(CollectionMilestone.name==user.username) \
            .filter(CollectionMilestone.nametype==CollectionMilestone.NAME_TYPE_USER) \
            .one()

    if collectionmilestone:
        session.delete(collectionmilestone)
        session.commit()

        return redirect(redirect_to)

    return HttpResponseForbidden('<h1>Forbidden</h1>')
Esempio n. 4
0
def view_addusermilestone(session, request, collectiontype, collection):
    """ Handle user login """

    referer = request.META.get('HTTP_REFERER', None)
    if referer is None:
        redirect_to='ddtss_index'
    try:
        redirect_to = urlsplit(referer, 'http', False)[2]
    except IndexError:
        redirect_to='ddtss_index'

    user = get_user(request, session)

    if not user.logged_in:
        return show_message_screen(request, 'Only for login user', 'ddtss_login')

    collectionmilestone = CollectionMilestone(name=user.username,
        nametype=CollectionMilestone.NAME_TYPE_USER,
        collection=collectiontype+':'+collection)
    session.add(collectionmilestone)
    try:
        session.commit()
    except:
        messages.error(request, "Error")

    return redirect(redirect_to)
Esempio n. 5
0
def view_preference(session, request):
    """ Handle user login """

    user = get_user(request, session)

    if not user.logged_in:
        return show_message_screen(request, 'Only for login user',
                                   'ddtss_login')

    if request.method == "POST":
        if request.POST.get('cancel'):
            return redirect('ddtss_index')

        form = UserPreference(session, data=request.POST)
        if form.is_valid():
            user.milestone = form.cleaned_data['milestone']
            user.realname = form.cleaned_data['realname']

            if (form.cleaned_data['password1']):
                user.md5password = hashlib.md5(
                    user.key + form.cleaned_data['password1']).hexdigest()

            session.commit()
            messages.success(request, "Preferenc changed")
            return redirect('ddtss_index')
    else:
        form_fields = dict(
            milestone=user.milestone,
            realname=user.realname,
        )
        form = UserPreference(session, form_fields)

    collectionmilestones = session.query(CollectionMilestone).\
            filter(CollectionMilestone.nametype==CollectionMilestone.NAME_TYPE_USER). \
            filter(CollectionMilestone.name==user.username).all()

    context = {
        'user': user,
        'form': form,
        'collectionmilestones': collectionmilestones,
    }
    return render_to_response("ddtss/user_preference.html",
                              context,
                              context_instance=RequestContext(request))
Esempio n. 6
0
def view_preference(session, request):
    """ Handle user login """

    user = get_user(request, session)

    if not user.logged_in:
        return show_message_screen(request, 'Only for login user', 'ddtss_login')

    if request.method == "POST":
        if request.POST.get('cancel'):
            return redirect('ddtss_index')

        form = UserPreference(session,data=request.POST)
        if form.is_valid():
            user.milestone=form.cleaned_data['milestone']
            user.realname=form.cleaned_data['realname']

            if (form.cleaned_data['password1']):
                user.md5password = hashlib.md5(user.key + form.cleaned_data['password1']).hexdigest()

            session.commit()
            messages.success(request, "Preferenc changed")
            return redirect('ddtss_index')
    else:
        form_fields = dict(milestone=user.milestone,
                realname=user.realname,
                )
        form = UserPreference(session,form_fields)

    collectionmilestones = session.query(CollectionMilestone).\
            filter(CollectionMilestone.nametype==CollectionMilestone.NAME_TYPE_USER). \
            filter(CollectionMilestone.name==user.username).all()

    context = {
        'user': user,
        'form': form,
        'collectionmilestones': collectionmilestones,
    }
    return render_to_response("ddtss/user_preference.html", context,
                              context_instance=RequestContext(request))