Exemplo n.º 1
0
    def setUp(self):
        user1 = User(username='******')
        user2 = User(username='******')
        user1.set_password('123')
        user2.set_password('123')
        user1.save()
        user2.save()
        dep = Department(id=532, num_id=36, code="CS", name="전산학전공")
        dep.save()
        user_profile1 = UserProfile(user=user1,
                                    student_id='20120010',
                                    department=dep,
                                    nickname='kido1',
                                    language="ko")
        user_profile2 = UserProfile(user=user2,
                                    student_id='20120011',
                                    department=dep,
                                    nickname='kido2',
                                    language="ko")
        user_profile1.save()
        user_profile2.save()
        dep = Department(id=110, num_id=20, code="PH", name="물리학과")
        dep.save()
        dep = Department(id=151, num_id=25, code="MAS", name="수리과학과")
        dep.save()

        self.client.login(username='******', password='******')
        user = User.objects.get(username='******')
        profile = UserProfile.objects.get(user=user)
Exemplo n.º 2
0
Arquivo: tests.py Projeto: hodduc/otl
    def setUp(self):
        user1 = User(username='******')
        user2 = User(username='******')
        user1.set_password('123')
        user2.set_password('123')
        user1.save()
        user2.save()
        dep = Department(id=532, num_id=36, code="CS", name="전산학전공")
        dep.save()
        user_profile1 = UserProfile(user=user1, student_id='20120010', department=dep, nickname='kido1', language="ko")
        user_profile2 = UserProfile(user=user2, student_id='20120011', department=dep, nickname='kido2', language="ko")
        user_profile1.save()
        user_profile2.save()
        dep = Department(id=110, num_id=20, code="PH", name="물리학과")
        dep.save()
        dep = Department(id=151, num_id=25, code="MAS", name="수리과학과")
        dep.save()

        self.client.login(username='******', password='******')
        user = User.objects.get(username='******')
        profile = UserProfile.objects.get(user=user)
Exemplo n.º 3
0
from otl.apps.dictionary.models import Course, Comment

#writer =  User.objects.get(username='******')

lecture = Lecture.objects.filter(code='36.330')[0]
course = Course.objects.get(old_code='CS330')
dep = Department.objects.get(id=532)

users = User.objects.all()
profiles = UserProfile.objects.all()
comments = Comment.objects.all()
profiles.delete()
users.delete()
comments.delete()

for n in range(1,100):
    writer_name = "kid%d"%n
    writer = User(username=writer_name)
    writer.set_password("1234")
    writer.save()
    sid=20120010
    writer_profile = UserProfile(user=writer, student_id=str(sid+n), department=dep, nickname=writer_name, language="ko")
    writer_profile.save()
    writer_profile.take_lecture_list.add(lecture)
    writer_profile.save()
    comment_text = "코멘트%d by %s"%(n,writer_name)
    comment = Comment(course=course, lecture=lecture, writer=writer, comment=comment_text, load=1, score=1, gain=1)
    comment.save()


Exemplo n.º 4
0
Arquivo: views.py Projeto: hodduc/otl
def login(request):

    num_users = cache_with_default('stat.num_users',
                                   lambda: User.objects.count() - 1, 60)
    num_lectures = cache_with_default('stat.num_lectures',
                                      lambda: Lecture.objects.count(), 600)
    num_favorites = cache_with_default('stat.num_favorites',
                                       lambda: CourseLink.objects.count(), 60)
    num_schedules = cache_with_default(
        'stat.num_schedules', lambda: Schedule.objects.filter(one_of=None).
        count() + RepeatedSchedule.objects.count(), 30)
    num_groups = cache_with_default('stat.num_groups',
                                    lambda: GroupBoard.objects.count(), 60)
    num_comments = cache_with_default('stat.num_comments',
                                      lambda: Comment.objects.count(), 60)

    next_url = request.GET.get('next', '/')
    if request.method == 'POST':

        if not request.POST.has_key('agree'):
            # Do login process
            f = LoginForm(request.POST)
            if not f.is_valid():
                return render_to_response(
                    'login.html', {
                        'form_login': f,
                        'title': ugettext(u'로그인'),
                        'error': True,
                        'msg': ugettext(u'아이디/비밀번호를 모두 적어야 합니다.'),
                        'next': next_url,
                        'num_users': num_users,
                        'num_lectures': num_lectures,
                        'num_favorites': num_favorites,
                        'num_schedules': num_schedules,
                        'num_groups': num_groups,
                        'num_comments': num_comments,
                    },
                    context_instance=RequestContext(request))

            try:
                user = auth.authenticate(username=request.POST['username'],
                                         password=request.POST['password'])
            except UnicodeEncodeError:
                return HttpResponseBadRequest('Bad Request')

            if user is None:  # Login Failed
                return render_to_response(
                    'login.html', {
                        'form_login': f,
                        'title': ugettext(u'로그인'),
                        'error': True,
                        'msg': ugettext(u'로그인에 실패하였습니다.'),
                        'next': next_url,
                        'num_users': num_users,
                        'num_lectures': num_lectures,
                        'num_favorites': num_favorites,
                        'num_schedules': num_schedules,
                        'num_groups': num_groups,
                        'num_comments': num_comments,
                    },
                    context_instance=RequestContext(request))
            else:  # Login OK
                try:
                    temp = user.first_login
                except AttributeError:
                    user.first_login = False
                if user.first_login:
                    # First Login
                    return render_to_response(
                        'login_agreement.html', {
                            'username': user.username,
                            'title': ugettext(u'로그인'),
                            'kuser_info': user.kuser_info,
                            'form_profile': ProfileForm(),
                            'next': next_url,
                        },
                        context_instance=RequestContext(request))
                else:
                    # Already existing user
                    if not user.is_superuser:
                        profile = UserProfile.objects.get(user=user)
                    # Create user's default system calendars if not exists
                    color = 1
                    for key, value in SYSTEM_CALENDAR_NAMES.iteritems():
                        try:
                            Calendar.objects.get(owner=user, system_id=key)
                        except Calendar.DoesNotExist:
                            c = Calendar()
                            c.owner = user
                            c.system_id = key
                            c.title = value
                            c.color = color
                            c.save()
                        color += 1
                    auth.login(request, user)
                    # If persistent login options is set, let the session expire after 2-weeks.
                    if request.POST.has_key('persistent_login'):
                        request.session.set_expiry(14 * 24 * 3600)
                    request.session[
                        'django_language'] = user.userprofile.language[:2]
                    return HttpResponseRedirect(next_url)
        else:
            # Show privacy agreement form after confirming this is a valid user in KAIST.
            if request.POST['agree'] == 'yes':
                user = User.objects.get(username=request.POST['username'])
                user.backend = 'otl.apps.accounts.backends.KAISTSSOBackend'

                # Create user's profile
                try:
                    profile = UserProfile.objects.get(user__exact=user)
                except UserProfile.DoesNotExist:
                    profile = UserProfile()
                profile.user = user
                profile.language = request.POST['language']
                try:
                    profile.department = Department.objects.get(
                        id__exact=int(request.POST['department_no']))
                except:
                    profile.department = Department.objects.get(
                        id__exact=0)  # 찾을 수 없는 학과 사람은 일단 무학과로 등록
                profile.student_id = request.POST['student_id']
                profile.nickname = user.username
                profile.save()
                profile.favorite_departments.add(
                    Department.objects.get(id=2044))  # 인문사회과학부는 기본으로 추가

                # Create user's default system calendars
                color = 1
                for key, value in SYSTEM_CALENDAR_NAMES.iteritems():
                    try:
                        Calendar.objects.get(owner=user, system_id=key)
                    except Calendar.DoesNotExist:
                        c = Calendar()
                        c.owner = user
                        c.system_id = key
                        c.title = value
                        c.color = color
                        c.save()
                    color += 1

                # Registration finished!
                auth.login(request, user)
                return HttpResponseRedirect(next_url)
            else:
                return HttpResponseNotAllowed(
                    ugettext(u'개인정보 활용에 동의하셔야 서비스를 이용하실 수 있습니다. 죄송합니다.'))

    else:
        # Show login form for GET requests
        return render_to_response('login.html', {
            'title': ugettext(u'로그인'),
            'form_login': LoginForm(),
            'next': next_url,
            'num_users': num_users,
            'num_lectures': num_lectures,
            'num_favorites': num_favorites,
            'num_schedules': num_schedules,
            'num_groups': num_groups,
            'num_comments': num_comments,
        },
                                  context_instance=RequestContext(request))
Exemplo n.º 5
0
users = User.objects.all()
profiles = UserProfile.objects.all()
comments = Comment.objects.all()
profiles.delete()
users.delete()
comments.delete()

for n in range(1, 100):
    writer_name = "kid%d" % n
    writer = User(username=writer_name)
    writer.set_password("1234")
    writer.save()
    sid = 20120010
    writer_profile = UserProfile(user=writer,
                                 student_id=str(sid + n),
                                 department=dep,
                                 nickname=writer_name,
                                 language="ko")
    writer_profile.save()
    writer_profile.take_lecture_list.add(lecture)
    writer_profile.save()
    comment_text = "코멘트%d by %s" % (n, writer_name)
    comment = Comment(course=course,
                      lecture=lecture,
                      writer=writer,
                      comment=comment_text,
                      load=1,
                      score=1,
                      gain=1)
    comment.save()
Exemplo n.º 6
0
Arquivo: views.py Projeto: hodduc/otl
def login(request):

    num_users = cache_with_default('stat.num_users', lambda: User.objects.count() - 1, 60)
    num_lectures = cache_with_default('stat.num_lectures', lambda: Lecture.objects.count(), 600)
    num_favorites = cache_with_default('stat.num_favorites', lambda: CourseLink.objects.count(), 60)
    num_schedules = cache_with_default('stat.num_schedules', lambda: Schedule.objects.filter(one_of=None).count() + RepeatedSchedule.objects.count(), 30)
    num_groups = cache_with_default('stat.num_groups', lambda: GroupBoard.objects.count(), 60)
    num_comments = cache_with_default('stat.num_comments', lambda: Comment.objects.count(), 60)

    next_url = request.GET.get('next', '/')
    if request.method == 'POST':

        if not request.POST.has_key('agree'):
            # Do login process
            f = LoginForm(request.POST)
            if not f.is_valid():
                return render_to_response('login.html', {
                    'form_login': f,
                    'title': ugettext(u'로그인'),
                    'error': True,
                    'msg': ugettext(u'아이디/비밀번호를 모두 적어야 합니다.'),
                    'next': next_url,
                    'num_users': num_users,
                    'num_lectures': num_lectures,
                    'num_favorites': num_favorites,
                    'num_schedules': num_schedules,
                    'num_groups': num_groups,
                    'num_comments': num_comments,
                }, context_instance=RequestContext(request))

            try:
                user = auth.authenticate(username=request.POST['username'], password=request.POST['password'])
            except UnicodeEncodeError:
                return HttpResponseBadRequest('Bad Request')

            if user is None: # Login Failed
                return render_to_response('login.html', {
                    'form_login': f,
                    'title': ugettext(u'로그인'),
                    'error': True,
                    'msg': ugettext(u'로그인에 실패하였습니다.'),
                    'next': next_url,
                    'num_users': num_users,
                    'num_lectures': num_lectures,
                    'num_favorites': num_favorites,
                    'num_schedules': num_schedules,
                    'num_groups': num_groups,
                    'num_comments': num_comments,
                }, context_instance=RequestContext(request))
            else: # Login OK
                try:
                    temp = user.first_login
                except AttributeError:
                    user.first_login = False
                if user.first_login:
                    # First Login
                    return render_to_response('login_agreement.html', {
                        'username': user.username,
                        'title': ugettext(u'로그인'),
                        'kuser_info': user.kuser_info,
                        'form_profile': ProfileForm(),
                        'next': next_url,
                    }, context_instance=RequestContext(request))
                else:
                    # Already existing user
                    if not user.is_superuser:
                        profile = UserProfile.objects.get(user=user)
                    # Create user's default system calendars if not exists
                    color = 1
                    for key, value in SYSTEM_CALENDAR_NAMES.iteritems():
                        try:
                            Calendar.objects.get(owner=user, system_id=key)
                        except Calendar.DoesNotExist:
                            c = Calendar()
                            c.owner = user
                            c.system_id = key
                            c.title = value
                            c.color = color
                            c.save()
                        color += 1
                    auth.login(request, user)
                    # If persistent login options is set, let the session expire after 2-weeks.
                    if request.POST.has_key('persistent_login'):
                        request.session.set_expiry(14*24*3600)
                    request.session['django_language'] = user.userprofile.language[:2]
                    return HttpResponseRedirect(next_url)
        else:
            # Show privacy agreement form after confirming this is a valid user in KAIST.
            if request.POST['agree'] == 'yes':
                user = User.objects.get(username = request.POST['username'])
                user.backend = 'otl.apps.accounts.backends.KAISTSSOBackend'

                # Create user's profile
                try:
                    profile = UserProfile.objects.get(user__exact = user)
                except UserProfile.DoesNotExist:
                    profile = UserProfile()
                profile.user = user
                profile.language = request.POST['language']
                try:
                    profile.department = Department.objects.get(id__exact=int(request.POST['department_no']))
                except:
                    profile.department = Department.objects.get(id__exact=0) # 찾을 수 없는 학과 사람은 일단 무학과로 등록
                profile.student_id = request.POST['student_id']
                profile.nickname = user.username
                profile.save()
                profile.favorite_departments.add(Department.objects.get(id=2044)) # 인문사회과학부는 기본으로 추가

                # Create user's default system calendars
                color = 1
                for key, value in SYSTEM_CALENDAR_NAMES.iteritems():
                    try:
                        Calendar.objects.get(owner=user, system_id=key)
                    except Calendar.DoesNotExist:
                        c = Calendar()
                        c.owner = user
                        c.system_id = key
                        c.title = value
                        c.color = color
                        c.save()
                    color += 1

                # Registration finished!
                auth.login(request, user)
                return HttpResponseRedirect(next_url)
            else:
                return HttpResponseNotAllowed(ugettext(u'개인정보 활용에 동의하셔야 서비스를 이용하실 수 있습니다. 죄송합니다.'))

    else:
        # Show login form for GET requests
        return render_to_response('login.html', {
            'title': ugettext(u'로그인'),
            'form_login': LoginForm(),
            'next': next_url,
            'num_users': num_users,
            'num_lectures': num_lectures,
            'num_favorites': num_favorites,
            'num_schedules': num_schedules,
            'num_groups': num_groups,
            'num_comments': num_comments,
        }, context_instance=RequestContext(request))