Beispiel #1
0
def add_volunteer(request, eknight_id):
    form = Add_volunteer(initial={'eknights': eknight_id})
    if request.method == 'POST':
        form = Add_volunteer(request.POST, request.user)
        if form.is_valid():
            done = form.save()
            # if request.POST['other']:
            #     expert = Expertise(name=request.POST['other'])
            #     expert.full_clean()
            #     expert.save()
            #     other_expertise = Expertise.objects.get(name=expert)
            #     done.expertise.add(other_expertise.id)
            # user = Volunteer.objects.get(email=done.email)
            e_id = EKnight.objects.get(id=eknight_id)
            arrival = Arrival(user=done, eknight=e_id)
            arrival.save()
            return HttpResponseRedirect('/')
    return render(request, 'volunteers/add_volunteer.html', {'form': form})
Beispiel #2
0
def data_insert(request):
    q = Coordinator_question(question='lectures wanted')
    q.save()
    with open('data', 'rb') as f:
        s = f.read()
        data_dic = ast.literal_eval(s)
        attr_map = {'fname': 'first_name', 'lname': 'last_name', 'phonenum': 'phone',
                    'work_study_place': 'work_study_place', 'emailad': 'email',
                    'vol_message': 'volunteer_messages'}
        # assert False, data_dic
        for user_name, user_data in data_dic.iteritems():
            v = Volunteer()
            for key, val in user_data.iteritems():
                if key != 'name' and val:
                    if key == 'eknight':
                        for date_str, eknight_name in val.iteritems():
                            pass
                    elif key == 20:
                        continue
                    elif key == 'previous_contacts':
                        pass
                    elif key == 'role':
                        expertise = Expertise.objects.filter(name=val)
                        val = expertise
                    elif key == 'city':
                        comm = Community.objects.filter(name=val)
                        val = comm
                    elif key == 'regdates':
                        pass
                        # for a in val:
                        # 	if user_data['eknight']:
                        # 		ek = EKnight.objects.get(name=user_data['eknight'])
                        # 	else:
                        # 		ek = EKnight.objects.get(name='other')
                        # 	arrival = Arrival(user=v, user_arrived=a, eknight=ek, coordinator_message="")
                        # 	arrival.save()
                    attr = attr_map[key] if key in attr_map else key
                    setattr(v, attr, val)
            vol = v.save()
            for a in user_data['regdates']:
                pass
                # if user_data['eknight']:
                # 	ek = EKnight.objects.get(name=user_data['eknight'])
                # else:
                ek = EKnight.objects.get(name='ללא חשמביר')
                arrival = Arrival(user=v, user_arrived=a, eknight=ek, coordinator_message="")
                arrival.save()
            add = ""
            if user_data['address']:
                add = Volunteer_address(user=v, address=user_data['address'])
            else:
                add = Volunteer_address(user=v, address="no address")
            add.save()
            ans = ""
            if user_data['wanted_lectures']:
                ans = Coordinator_question_answer(question=q, answer=user_data['wanted_lectures'], user=v)
            else:
                ans = Coordinator_question_answer(question=q, answer="no data", user=v)
            ans.save()


# dic = {}
#    attribute_map = {}
#    for user_name, user_data in dic:
#        v = Volunteer()
#        for key, val in user_data:
#            attr = attribute_map[key] if key in attribute_map else key
#            setattr(v, attr, val)
#        v.save()
# 		volunteer = Volunteer(first_name=row[0], last_name=row[1], email=row[3], phone=row[8],
# 		home_address=row[9], work_place=row[10], github=row[17], facebook=[18], linkedin=row[19], tweeter=row[20], birth_date=row[21])
# 		volunteer.save()
    return HttpResponseRedirect('/')
Beispiel #3
0
def data_insert(request):
    q = Coordinator_question(question="lectures wanted")
    q.save()
    with open("data", "rb") as f:
        s = f.read()
        data_dic = ast.literal_eval(s)
        attr_map = {
            "fname": "first_name",
            "lname": "last_name",
            "phonenum": "phone",
            "work_study_place": "work_study_place",
            "emailad": "email",
            "vol_message": "volunteer_messages",
        }
        # 		assert False, data_dic
        for user_name, user_data in data_dic.iteritems():
            v = Volunteer()
            for key, val in user_data.iteritems():
                if key != "name" and val:
                    if key == "eknight":
                        for date_str, eknight_name in val.iteritems():
                            pass
                    elif key == 20:
                        continue
                    elif key == "previous_contacts":
                        pass
                    elif key == "role":
                        expertise = Expertise.objects.filter(name=val)
                        val = expertise
                    elif key == "city":
                        comm = Community.objects.filter(name=val)
                        val = comm
                    elif key == "regdates":
                        pass
                    # 						for a in val:
                    # 							if user_data['eknight']:
                    # 								ek = EKnight.objects.get(name=user_data['eknight'])
                    # 							else:
                    # 								ek = EKnight.objects.get(name='other')
                    # 							arrival = Arrival(user=v, user_arrived=a, eknight=ek, coordinator_message="")
                    # 							arrival.save()
                    attr = attr_map[key] if key in attr_map else key
                    setattr(v, attr, val)
            vol = v.save()
            for a in user_data["regdates"]:
                pass
                # 				if user_data['eknight']:
                # 					ek = EKnight.objects.get(name=user_data['eknight'])
                # 				else:
                ek = EKnight.objects.get(name="ללא חשמביר")
                arrival = Arrival(user=v, user_arrived=a, eknight=ek, coordinator_message="")
                arrival.save()
            add = ""
            if user_data["address"]:
                add = Volunteer_address(user=v, address=user_data["address"])
            else:
                add = Volunteer_address(user=v, address="no address")
            add.save()
            ans = ""
            if user_data["wanted_lectures"]:
                ans = Coordinator_question_answer(question=q, answer=user_data["wanted_lectures"], user=v)
            else:
                ans = Coordinator_question_answer(question=q, answer="no data", user=v)
            ans.save()

    # dic = {}
    #    attribute_map = {}
    #    for user_name, user_data in dic:
    #        v = Volunteer()
    #        for key, val in user_data:
    #            attr = attribute_map[key] if key in attribute_map else key
    #            setattr(v, attr, val)
    #        v.save()
    # 		volunteer = Volunteer(first_name=row[0], last_name=row[1], email=row[3], phone=row[8],
    # 		home_address=row[9], work_place=row[10], github=row[17], facebook=[18], linkedin=row[19], tweeter=row[20], birth_date=row[21])
    # 		volunteer.save()
    return HttpResponseRedirect("/")