Beispiel #1
0
def view_edit_question(request, question_id, question_slug, edit_question_template):
    userprofile = loggedin_userprofile(request)
    question = get_object_or_404(Question, id=int(question_id))
    if userprofile.is_my_question(question):
        asked_questions = list(userprofile.asked_questions)
        for question_info in asked_questions:
            if question_info['id'] == int(question_id):
                asked_questions.remove({'title':question.title,
                                        'id':int(question_id),
                                        'slug':question_slug})
        
        if request.method == 'GET':
            question_data = {'title':question.title,
                             'description':question.description,
                             'tags':",".join([tag['name'] for tag in question.tags.values('name')])}
            form = AskQuestionForm(question_data)
            return response(request, edit_question_template, {'form':form,
                                                              'question':question,
                                                              'previous_questions':asked_questions})
        form = AskQuestionForm(post_data(request))
        if form.is_valid():
            Question.objects.update_question(question,
                                             title=form.cleaned_data.get('title'),
                                             description=form.cleaned_data.get('description'),
                                             tags=form.cleaned_data.get('tags'))
            from quest.messages import QUESTION_UPDATED_SUCCESSFULLY
            messages.success(request, QUESTION_UPDATED_SUCCESSFULLY)
            return HttpResponseRedirect(redirect_to=url_reverse('quest.views.view_question', args=(question.id, question.slug)))
        return response(request, edit_question_template, {'form':form,
                                                          'question':question,
                                                          'previous_questions':asked_questions})
    raise Http404
Beispiel #2
0
def view_give_answer(request, question_id, give_answer_template,
                     question_template):
    question = get_object_or_404(Question, id=int(question_id))
    if request.method == 'POST':
        form = GiveAnswerForm(post_data(request))
        if form.is_valid():
            userprofile = loggedin_userprofile(request)
            new_answer = Answer.objects.create_answer(
                question=question,
                description=form.cleaned_data.get('description'),
                userprofile=userprofile)
            new_anwer_emailer(question, new_answer)
            from quest.messages import ANSWER_POSTING_SUCCESSFUL
            messages.success(request, ANSWER_POSTING_SUCCESSFUL)
            give_answer_form = GiveAnswerForm()
            return response(request, question_template, {
                'question': question,
                'give_answer_form': give_answer_form
            })
        return response(request, question_template, {
            'question': question,
            'give_answer_form': form
        })
    return HttpResponseRedirect(redirect_to=url_reverse(
        'quest.views.view_question', args=(question.id, question.slug)))
Beispiel #3
0
def view_contactgroup(request, group_type, group_id, contactgroup_template):
    userprofile = loggedin_userprofile(request)
    if group_type == 'college':
        group = get_object_or_404(College, id=int(group_id))
        to = "%s Students" % group.name
        redirect_url = url_reverse('users.views.view_college', args=(group_id, group.slug))
    elif group_type == 'company':
        group = get_object_or_404(Company, id=int(group_id))
        to = "%s Employees" % group.name
        redirect_url = url_reverse('users.views.view_company', args=(group_id, group.slug))
    else:
        raise Http404
    if request.method == 'POST':
        contactgroupform = ContactGroupForm(post_data(request))
        if contactgroupform.is_valid():
            mail_group(group_type=group_type,
                       group=group,
                       from_email=userprofile.user.email,
                       message=contactgroupform.cleaned_data.get('message'),
                       from_name=userprofile.name,
                       subject=contactgroupform.cleaned_data.get('subject'))
            from users.messages import CONTACTED_SUCCESSFULLY
            messages.success(request, CONTACTED_SUCCESSFULLY)
            return HttpResponseRedirect(redirect_to=redirect_url)
    contactgroupform = ContactGroupForm({'to':to})
    return response(request, contactgroup_template, {'contactgroupform':contactgroupform,
                                                     'group_type':group_type,
                                                     'group_id':group_id})
Beispiel #4
0
def view_get_workinfo_settings(request, workinfo_settings_template):
    userprofile = loggedin_userprofile(request)
    (workplace, designation, years_of_exp) = userprofile.work_details
    form = WorkInfoSettingsForm({'workplace':workplace if workplace else '',
                                 'designation':designation,
                                 'years_of_exp':years_of_exp})
    return response(request, workinfo_settings_template, {'workinfo_form':form})
Beispiel #5
0
def view_webresume(request):
    userprofile = loggedin_userprofile(request)
    if userprofile.can_update_slug():
        from users.messages import NEED_TO_PICK_A_WEBRESUME_URL_MESSAGE
        messages.error(request, NEED_TO_PICK_A_WEBRESUME_URL_MESSAGE)
        return HttpResponseRedirect(url_reverse('users.views.view_account_settings'))
    return HttpResponseRedirect(redirect_to=url_reverse('users.views.view_userprofile', args=(userprofile.slug,)))
Beispiel #6
0
def view_edit_achievement(request, achievement_id, edit_achievement_template):
    userprofile = loggedin_userprofile(request)
    achievement = get_object_or_404(Achievement, id=int(achievement_id))
    if userprofile.is_my_achievement(achievement):
        achievements = list(userprofile.achievements)
        for achievment_info in achievements:
            if achievment_info['id'] == int(achievement_id):
                achievements.remove({'title':achievement.title,
                                        'id':int(achievement_id),
                                        'description':achievement.description})
                break
        if request.method == 'GET':
            form = AddAchievementForm({'title':achievement.title,
                                       'description':achievement.description})
            return response(request, edit_achievement_template, {'achievement':achievement,
                                                                 'form':form,
                                                                 'previous_achievements':achievements})
        form = AddAchievementForm(post_data(request))
        if form.is_valid():
            achievement.update(title=form.cleaned_data.get('title'),
                               description=form.cleaned_data.get('description'),)
            from users.messages import ACHIEVEMENT_UPDATED_SUCCESSFULLY
            messages.success(request, ACHIEVEMENT_UPDATED_SUCCESSFULLY)
            return HttpResponseRedirect(redirect_to=url_reverse('users.views.view_all_achievements'))
        return response(request, edit_achievement_template, {'achievement':achievement,
                                                             'form':form,
                                                             'previous_achievements':achievements})
    raise Http404
Beispiel #7
0
def view_save_personal_settings(request, personal_settings_template):
    if request.method == 'GET':
        return view_get_personal_settings(request, personal_settings_template)
    userprofile = loggedin_userprofile(request)
    form = PersonalSettingsForm(post_data(request))
    if form.is_valid():
        name = form.cleaned_data.get('name')
        new_password = form.cleaned_data.get('new_password')
        slug = form.cleaned_data.get('slug')
        if userprofile.can_update_slug():
            if slug:
                if UserProfile.objects.filter(slug=slug).count():
                    from users.messages import WEB_RESUME_URL_ALREADY_PICKED
                    form._errors['slug'] = WEB_RESUME_URL_ALREADY_PICKED
                else:
                    userprofile.update(name=name, slug=slug, password=new_password)
                    from users.messages import ACCOUNT_SETTINGS_SAVED
                    messages.success(request, ACCOUNT_SETTINGS_SAVED)
            else:
                from users.messages import INVALID_WEB_RESUME_URL
                messages.error(request, INVALID_WEB_RESUME_URL)
        else:
            userprofile.update(name=name, password=new_password)
            from users.messages import ACCOUNT_SETTINGS_SAVED
            messages.success(request, ACCOUNT_SETTINGS_SAVED)
    return response(request, personal_settings_template, {'personal_form':form})
Beispiel #8
0
def view_close_answering(request, question_template, close_answer_template):#This would be an ajax post call
    question_id = post_data(request).get('question_id')
    question = get_object_or_404(Question, id=int(question_id))
    userprofile = loggedin_userprofile(request)
    if userprofile.id == question.owner.id:
        question.close_answering()
        return response(request, close_answer_template, {'give_answer_form':None})
    raise Http404
Beispiel #9
0
def view_get_acad_settings(request, acad_settings_template):
    userprofile = loggedin_userprofile(request)
    (branch, college, start_year, end_year, aggregate) = userprofile.acad_details
    acad_form = AcadSettingsForm({'branch':branch,
                                  'college':college.name,
                                  'start_year':start_year,
                                  'end_year':end_year,
                                  'aggregate':aggregate})
    return response(request, acad_settings_template, {'acad_form':acad_form})
Beispiel #10
0
def view_accept_answer(request, question_id, answers_template):
    question = get_object_or_404(Question, id=int(question_id))
    userprofile = loggedin_userprofile(request)
    if userprofile.id == question.owner.id:
        answer_id = post_data(request).get('answer_id')
        answer = get_object_or_404(Answer, id=int(answer_id))
        answer.accept(userprofile)
        return response(request, answers_template, {'question':question, 'all_answers':question.answers})
    raise Http404
Beispiel #11
0
def view_close_answering(
        request, question_template,
        close_answer_template):  #This would be an ajax post call
    question_id = post_data(request).get('question_id')
    question = get_object_or_404(Question, id=int(question_id))
    userprofile = loggedin_userprofile(request)
    if userprofile.id == question.owner.id:
        question.close_answering()
        return response(request, close_answer_template,
                        {'give_answer_form': None})
    raise Http404
Beispiel #12
0
def view_notepad(request, notepad_template):
    userprofile = loggedin_userprofile(request)
    all_notes = userprofile.all_notes
    if request.method == 'GET':
        return response(request, notepad_template, {'form':SaveNoteForm(),
                                                    'all_notes':all_notes})
    form = SaveNoteForm(post_data(request))
    userprofile = loggedin_userprofile(request)
    if not form.is_valid():
        return response(request, notepad_template, {'form':form,
                                                    'all_notes':all_notes})
    Note.objects.create_note(userprofile=userprofile,
                             name=form.cleaned_data.get('name'),
                             short_description=form.cleaned_data.get('short_description'),
                             note=form.cleaned_data.get('content'),
                             public=form.cleaned_data.get('public'))
    from users.messages import SAVED_NOTEPAD_SUCCESSFULLY_MESSAGE
    messages.success(request, SAVED_NOTEPAD_SUCCESSFULLY_MESSAGE)
    return response(request, notepad_template, {'form':SaveNoteForm(),
                                                'all_notes':all_notes})
Beispiel #13
0
def view_accept_answer(request, question_id, answers_template):
    question = get_object_or_404(Question, id=int(question_id))
    userprofile = loggedin_userprofile(request)
    if userprofile.id == question.owner.id:
        answer_id = post_data(request).get('answer_id')
        answer = get_object_or_404(Answer, id=int(answer_id))
        answer.accept(userprofile)
        return response(request, answers_template, {
            'question': question,
            'all_answers': question.answers
        })
    raise Http404
Beispiel #14
0
def view_edit_question(request, question_id, question_slug,
                       edit_question_template):
    userprofile = loggedin_userprofile(request)
    question = get_object_or_404(Question, id=int(question_id))
    if userprofile.is_my_question(question):
        asked_questions = list(userprofile.asked_questions)
        for question_info in asked_questions:
            if question_info['id'] == int(question_id):
                asked_questions.remove({
                    'title': question.title,
                    'id': int(question_id),
                    'slug': question_slug
                })

        if request.method == 'GET':
            question_data = {
                'title':
                question.title,
                'description':
                question.description,
                'tags':
                ",".join([tag['name'] for tag in question.tags.values('name')])
            }
            form = AskQuestionForm(question_data)
            return response(
                request, edit_question_template, {
                    'form': form,
                    'question': question,
                    'previous_questions': asked_questions
                })
        form = AskQuestionForm(post_data(request))
        if form.is_valid():
            Question.objects.update_question(
                question,
                title=form.cleaned_data.get('title'),
                description=form.cleaned_data.get('description'),
                tags=form.cleaned_data.get('tags'))
            from quest.messages import QUESTION_UPDATED_SUCCESSFULLY
            messages.success(request, QUESTION_UPDATED_SUCCESSFULLY)
            return HttpResponseRedirect(redirect_to=url_reverse(
                'quest.views.view_question', args=(question.id,
                                                   question.slug)))
        return response(
            request, edit_question_template, {
                'form': form,
                'question': question,
                'previous_questions': asked_questions
            })
    raise Http404
Beispiel #15
0
def view_give_answer(request, question_id, give_answer_template, question_template):
    question = get_object_or_404(Question, id=int(question_id))
    if request.method == 'POST':
        form = GiveAnswerForm(post_data(request))
        if form.is_valid():
            userprofile = loggedin_userprofile(request)
            new_answer = Answer.objects.create_answer(question=question,
                                                      description=form.cleaned_data.get('description'),
                                                      userprofile=userprofile)
            new_anwer_emailer(question, new_answer)
            from quest.messages import ANSWER_POSTING_SUCCESSFUL
            messages.success(request, ANSWER_POSTING_SUCCESSFUL)
            give_answer_form = GiveAnswerForm()
            return response(request, question_template, {'question':question, 'give_answer_form':give_answer_form})
        return response(request, question_template, {'question':question, 'give_answer_form':form})
    return HttpResponseRedirect(redirect_to=url_reverse('quest.views.view_question', args=(question.id, question.slug)))
Beispiel #16
0
def view_add_achievement(request, add_achievement_template):
    userprofile = loggedin_userprofile(request)
    achievements = userprofile.achievements
    if request.method == 'GET':
        form = AddAchievementForm()
        return response(request, add_achievement_template, {'form':form,
                                                            'achievements':achievements})
    form = AddAchievementForm(post_data(request))
    if form.is_valid():
        Achievement.objects.create_achievement(userprofile,
                                               title=form.cleaned_data.get('title'),
                                               description=form.cleaned_data.get('description'))
        from users.messages import ACHIEVEMENT_ADDED_SUCCESSFULLY
        messages.success(request, ACHIEVEMENT_ADDED_SUCCESSFULLY)
        return HttpResponseRedirect(url_reverse('users.views.view_all_achievements'))
    return response(request, add_achievement_template, {'form':form,
                                                        'achievements':achievements})
Beispiel #17
0
def view_ask_question(request, ask_question_template):
    userprofile = loggedin_userprofile(request)
    asked_questions = userprofile.asked_questions
    if request.method == 'GET':
        form = AskQuestionForm()
        return response(request, ask_question_template, {'form':form,
                                                         'asked_questions':asked_questions})
    form = AskQuestionForm(post_data(request))
    if form.is_valid():
        question = Question.objects.create_question(title=form.cleaned_data.get('title'),
                                                    description=form.cleaned_data.get('description'),
                                                    userprofile=userprofile,
                                                    tags=form.cleaned_data.get('tags'))
        messages.success(request, QUESTION_POSTING_SUCCESSFUL)
        return HttpResponseRedirect(redirect_to=url_reverse('quest.views.view_question', args=(question.id, question.slug)))
    return response(request, ask_question_template, {'form':form,
                                                     'asked_questions':asked_questions})
Beispiel #18
0
def view_invite(request, invite_template):
    if request.method == 'GET':
        return response(request, invite_template, {'form':InvitationForm()})
    userprofile = loggedin_userprofile(request)
    form = InvitationForm(post_data(request))
    if form.is_valid():
        try:
            invitation_emailer(from_email=userprofile.user.email,
                               to_emails=form.cleaned_data.get('to_emails'),
                               from_name=userprofile.name)
            from users.messages import CONTACTED_SUCCESSFULLY
            messages.success(request, CONTACTED_SUCCESSFULLY)
            return HttpResponseRedirect(redirect_to='/')
        except Exception:
            from users.messages import CONTACTING_FAILED
            messages.error(request, CONTACTING_FAILED)
    return response(request, invite_template, {'form':form})
Beispiel #19
0
def view_save_acad_settings(request, acad_settings_template):
    if request.method == 'GET':
        return view_get_acad_settings(request, acad_settings_template)
    userprofile = loggedin_userprofile(request)
    acad_form = AcadSettingsForm(post_data(request))
    if acad_form.is_valid():
        branch = acad_form.cleaned_data.get('branch')
        college = acad_form.cleaned_data.get('college')
        start_year = acad_form.cleaned_data.get('start_year')
        end_year = acad_form.cleaned_data.get('end_year')
        aggregate = acad_form.cleaned_data.get('aggregate')
        userprofile.join_college(college_name=college,
                                 branch=branch,
                                 start_year=start_year,
                                 end_year=end_year,
                                 aggregate=aggregate)
        from users.messages import ACCOUNT_SETTINGS_SAVED
        messages.success(request, ACCOUNT_SETTINGS_SAVED)
    return response(request, acad_settings_template, {'acad_form':acad_form})
Beispiel #20
0
def view_account_settings(request, settings_template):
    userprofile = loggedin_userprofile(request)
    personal_form = PersonalSettingsForm({'name':userprofile.name,
                                          'slug':userprofile.slug})
    (branch, college, start_year, end_year, aggregate) = userprofile.acad_details
    acad_form = AcadSettingsForm({'branch':branch,
                                  'college':college.name if college else '',
                                  'start_year':start_year if start_year else DEFAULT_COLLEGE_START_YEAR,
                                  'end_year':end_year if start_year else DEFAULT_COLLEGE_END_YEAR,
                                  'aggregate':aggregate if aggregate else ''})
    if userprofile.is_student:
        return response(request, settings_template, {'personal_form':personal_form,
                                                     'acad_form':acad_form})
    else:
        (workplace, designation, years_of_exp) = userprofile.work_details
        workinfo_form = WorkInfoSettingsForm({'workplace':workplace.name if workplace else '',
                                              'designation':designation,
                                              'years_of_exp':years_of_exp})
        return response(request, settings_template, {'personal_form':personal_form,
                                                     'acad_form':acad_form,
                                                     'workinfo_form':workinfo_form})
Beispiel #21
0
def view_contactuser(request, user_id, contactuser_template):
    userprofile = loggedin_userprofile(request)
    to_userprofile = get_object_or_404(UserProfile, id=int(user_id))
    if request.method == 'GET':
        return response(request, contactuser_template, {'contactuserform':ContactUserForm({'to':to_userprofile.name,
                                                                                           'message':'Hello,'}),
                                                        'to_userprofile':to_userprofile})
    form = ContactUserForm(post_data(request))
    if form.is_valid():
        try:
            default_emailer(from_email=userprofile.user.email,
                            to_emails=[form.cleaned_data.get('to')],
                            subject=form.cleaned_data.get('subject'),
                            message=form.cleaned_data.get('message'))
            from users.messages import CONTACTED_SUCCESSFULLY
            messages.success(request, CONTACTED_SUCCESSFULLY)
            return HttpResponseRedirect(redirect_to=url_reverse('users.views.view_userprofile', args=(to_userprofile.slug,)))
        except Exception:
            from users.messages import CONTACTING_FAILED
            messages.error(request, CONTACTING_FAILED)
    return response(request, contactuser_template, {'contactuserform':form, 'to_userprofile':to_userprofile})
Beispiel #22
0
def view_save_workinfo_settings(request, workinfo_settings_template):
    if request.method == 'GET':
        return view_get_workinfo_settings(request, workinfo_settings_template)
    userprofile = loggedin_userprofile(request)
    form = WorkInfoSettingsForm(post_data(request))
    if form.is_valid():
        workplace = form.cleaned_data.get('workplace')
        designation = form.cleaned_data.get('designation')
        years_of_exp = form.cleaned_data.get('years_of_exp')
        #TODO:Currently a Professor getting a corporate job is not handled
        if userprofile.is_student:
            workplace_type = 'Company'
            userprofile.make_employee()
        elif userprofile.is_employee:
            workplace_type = 'Company'
        else:
            workplace_type = 'College'
            userprofile.make_professor()
        userprofile.join_workplace(workplace, workplace_type, designation, years_of_exp)
        from users.messages import ACCOUNT_SETTINGS_SAVED
        messages.success(request, ACCOUNT_SETTINGS_SAVED)
    return response(request, workinfo_settings_template, {'workinfo_form':form})
Beispiel #23
0
def view_ask_question(request, ask_question_template):
    userprofile = loggedin_userprofile(request)
    asked_questions = userprofile.asked_questions
    if request.method == 'GET':
        form = AskQuestionForm()
        return response(request, ask_question_template, {
            'form': form,
            'asked_questions': asked_questions
        })
    form = AskQuestionForm(post_data(request))
    if form.is_valid():
        question = Question.objects.create_question(
            title=form.cleaned_data.get('title'),
            description=form.cleaned_data.get('description'),
            userprofile=userprofile,
            tags=form.cleaned_data.get('tags'))
        messages.success(request, QUESTION_POSTING_SUCCESSFUL)
        return HttpResponseRedirect(redirect_to=url_reverse(
            'quest.views.view_question', args=(question.id, question.slug)))
    return response(request, ask_question_template, {
        'form': form,
        'asked_questions': asked_questions
    })
Beispiel #24
0
def view_edit_note(request, note_id, notepad_template):
    userprofile = loggedin_userprofile(request)
    note = get_object_or_404(Note, id=int(note_id))
    if userprofile.is_my_note(note):
        all_notes = userprofile.all_notes
        if request.method == 'GET':
            form = SaveNoteForm({'name':note.name,
                                 'short_description':note.short_description,
                                 'content':note.note,
                                 'public':note.public})
            return response(request, notepad_template, {'form':form,
                                                        'note':note,
                                                        'all_notes':all_notes})
        form = SaveNoteForm(post_data(request))
        if form.is_valid():
            note.update(name=form.cleaned_data.get('name'),
                        short_description=form.cleaned_data.get('short_description'),
                        note=form.cleaned_data.get('content'),
                        public=form.cleaned_data.get('public'))
            from users.messages import SAVED_NOTEPAD_SUCCESSFULLY_MESSAGE
            messages.success(request, SAVED_NOTEPAD_SUCCESSFULLY_MESSAGE)
        return response(request, notepad_template, {'form':SaveNoteForm(),
                                                    'all_notes':all_notes})
    raise Http404
Beispiel #25
0
def view_note(request, note_id):
    userprofile = loggedin_userprofile(request)
    note = get_object_or_404(Note, id=int(note_id))
    if userprofile.is_my_note(note):
        return HttpResponse(content=note.note, mimetype='text/plain')
    raise Http404
Beispiel #26
0
def view_get_personal_settings(request, personal_settings_template):
    userprofile = loggedin_userprofile(request)
    form = PersonalSettingsForm({'name':userprofile.name,
                                 'slug':userprofile.slug,
                                 'new_password':''})
    return response(request, personal_settings_template, {'personal_form':form})
Beispiel #27
0
def view_all_achievements(request, achievements_template):
    userprofile = loggedin_userprofile(request)
    achievements = userprofile.achievements
    return response(request, achievements_template, {'achievements':achievements})