def profile_view(request): profile = UserProfile.objects.get(username=request.user.username) if profile == None: profile = UserProfile(username=request.user.username) profile.level = 'normal' # TODO: Add something that figures out more automatically when things are # read-only. if request.method == 'POST': profile.name = request.POST.get('name', '') profile.affiliation = request.POST.get('affiliation', '') profile.acm_number = request.POST.get('acm_number', '') profile.email = request.POST.get('email', '') profile.save() UserPCConflict.objects.filter(user=profile).delete() pc_conflicts = [] for conf in request.POST.getlist('pc_conflicts[]'): new_pc_conflict = UserProfile.objects.get(username=conf) UserPCConflict.objects.create(user=profile, pc=new_pc_conflict) pc_conflicts.append(new_pc_conflict) else: pc_conflicts = [uppc.pc for uppc in UserPCConflict.objects.filter(user=profile).all()] pcs = UserProfile.objects.filter(level='pc').all() return ("profile.html", { "name": profile.name, "affiliation": profile.affiliation, "acm_number": profile.acm_number, "pc_conflicts": pc_conflicts, "email": profile.email, "pcs": [{'pc':pc, 'conflict':pc in pc_conflicts} for pc in pcs], "which_page": "profile", })
def users_view(request): user = UserProfile.objects.get(username=request.user.username) if user.level != 'chair': return ( "redirect", "/index") user_profiles = UserProfile.objects.all() if request.method == 'POST': for profile in user_profiles: query_param_name = 'level-' + profile.username level = request.POST.get(query_param_name, '') if level in ['normal', 'pc', 'chair']: profile.level = level profile.save() return ("users_view.html", { 'user_profiles': user_profiles, 'which_pages' : "users" })