Example #1
0
def get_user_details(user):
   user_details_list = UserDetail.objects.filter(user = user.id)
   if len(user_details_list) == 0:
      user_details = UserDetail()
      user_details.user = user
      user_details.smartphone = True
      user_details.no_messages = False
      user_details.save()
      return user_details
   else:
      return user_details_list[0]
Example #2
0
def save_memberships_from_form(user, form):
   delete_memberships_for_user(user)
   for project in form.cleaned_data['surveys']:
      membership = Membership(user = user, project = project)
      membership.save()
   user_details_list = UserDetail.objects.filter(user = user.id)
   if (len(user_details_list) > 0):
      user_details = user_details_list[0]
   else:
      user_details = UserDetail()
   user_details.phone_number = form.cleaned_data['phone_number']
   user_details.smartphone = form.cleaned_data['smartphone']
   user_details.no_messages = form.cleaned_data['no_messages']
   user_details.save()
   return