Example #1
0
def VersionMember(request, pk):
    # dictionary for initial data with
    # field names as keys
    context ={}

    # fetch the object related to passed id
    obj = get_object_or_404(Member, pk = pk)

    # pass the object as instance in form
    form = MemberForm(request.POST or None, instance = obj)

    # save the data from the form and
    # redirect to detail_view
    if form.is_valid():
            obj.pk = int(round(time.time() * 1000))
            form.instance.creator = request.user
            form.save()
            return HttpResponseRedirect(reverse("members:all"))

    else:

            # add form dictionary to context
            context["form"] = form

            return render(request, "members/member_form.html", context)
Example #2
0
def edit(request, member_id):
    member = get_object_or_404(Member, pk=member_id)
    #if member.author != request.user and not request.user.is_staff:
    #    return HttpResponseForbidden()
    if request.method == 'POST':
        form = MemberForm(instance=member, data=request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(member.get_absolute_url())
    else:
        form = MemberForm(instance=member)
    return render(request, 'members/form.html',
        {'form': form, 'create': False, 'object': member})
def add_member(request):
    if request.method == 'POST':
        form = MemberForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('Member List', args = []))
    else:
        form = MemberForm()
    template_name = 'members/new_member.html'
    context = {
        'form':form
    }
    return render(request, template_name, context)
Example #4
0
def member_form_view(request):
    """
    Creates a new Member from form page
    """
    if request.method == 'POST':
        form = MemberForm(request.POST)
        if form.is_valid():
            form.save()
        #send mail to member
    form = MemberForm()
    context = {
        'form': form
    }
    return render(request, 'members/form.html', context=context)
Example #5
0
def add(request):
    """ Allows an admin to manually add members to the database """
    if request.method == 'POST':
        add_member_form = MemberForm(request.POST)
        if add_member_form.is_valid():
            add_member_form.save()
            return HttpResponseRedirect('/add')
        else:
            args = {'form': add_member_form, 'errors': add_member_form.errors}
            return render(request, 'members/add.html', args)
    else:
        add_member_form = MemberForm()
        print(add_member_form)
        return render(request, 'members/add.html', {'form': add_member_form})
def update_member_info(request, pk):
    member = get_object_or_404(Member, pk=pk)
    if request.method == 'POST':
        form = MemberForm(request.POST, request.FILES, instance = member)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('Member Detail', 
                kwargs = {'pk':pk}))
    else:
        form = MemberForm(instance = member)
    template_name = 'members/new_member.html'
    context = {
    'form':form
    }
    return render(request, template_name, context)
Example #7
0
def create(request):
    data = json.loads(request.body)
    form = MemberForm(data)
    if form.is_valid():
        member = form.save()
        return JsonResponse({'success': True, 'chat ID': member.user.id})
    return JsonResponse({'errors': form.errors}, status=400)
Example #8
0
def edit(request, member_id):
    member = get_object_or_404(Member, pk=member_id)
    #if member.author != request.user and not request.user.is_staff:
    #    return HttpResponseForbidden()
    if request.method == 'POST':
        form = MemberForm(instance=member, data=request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(member.get_absolute_url())
    else:
        form = MemberForm(instance=member)
    return render(request, 'members/form.html', {
        'form': form,
        'create': False,
        'object': member
    })
Example #9
0
def profile(request):
    page = {'title': _('Account Settings')}
    saved = False

    if request.POST:
        form = MemberForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            saved = True
    else:
        form = MemberForm(instance=request.user)

    return render(request, 'members/profile.html', {
        'saved': saved,
        'page': page,
        'form': form,
    })
Example #10
0
def edit_member(request):
    """ Allows an admin to manually add members to the database """
    if request.method == 'POST':
        pk = request.GET.get('pk')
        member_to_edit = get_object_or_404(Rider, id=pk)
        edit_member_form = MemberForm(request.POST or None, instance=member_to_edit)
        if edit_member_form.is_valid():
            edit_member_form.save()
            return HttpResponseRedirect('/search', {'success': True})
        else:
            args = {'form': edit_member_form, 'errors': edit_member_form.errors}
            return render(request, 'members/edit_member.html', args)
    else:
        pk = request.META['HTTP_PK']
        edit_form = get_object_or_404(Rider, id=pk)
        edit_form = MemberForm(instance=edit_form)
        args = {'form': edit_form, 'pk': pk}
        return render(request, 'members/edit_member.html', args)
Example #11
0
def create(request):
    logger.debug('create')
    if request.method == 'POST':
        form = MemberForm(data=request.POST)
        if form.is_valid():
            member = form.save()
            return HttpResponseRedirect(member.get_absolute_url())
    else:
        form = MemberForm()

    return render(request, 'members/form.html', {'form': form, 'create': True})
Example #12
0
def create(request):
    logger.debug('create')
    if request.method == 'POST':
        form = MemberForm(data = request.POST)
        if form.is_valid():
            member = form.save()
            return HttpResponseRedirect(member.get_absolute_url())
    else:
        form = MemberForm()

    return render(request, 'members/form.html', 
        { 'form' : form, 'create' : True })
Example #13
0
def member_update(request, member_id):
    member = Member.objects.get(id=member_id)
    # Here I check if the logged in user is the owner of the information.
    if member.user != request.user:
        #message='You do not have permission to change this information!'
        #return render(request,'members/no_access.html', {'message':message} )
        return HttpResponseRedirect(reverse('no_access'))

    if request.method == "POST":
        form = MemberForm(
            request.POST,
            instance=member)  # populates the form fields with POST data
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(
                reverse('member_profile', kwargs={'member_id': member_id}))
        else:
            return HttpResponseRedirect('/')

    form = MemberForm(instance=member)
    return render(request, 'members/member_update.html', {'form': form})
Example #14
0
def update_members(request, conference_id):
    conference = get_object_or_404(Conference, pk=conference_id)
    if request.method == 'POST':
        if request.POST.get('register_existitng_members'):
            # check if user wants to uncheck registrations
            # if len(request.POST.get('register_existing_members')) < conference.members.count():
            # add new registrations
            request_members = []
            for element in request.POST:
                if element.startswith('member_'):
                    member_pk = element.split('_')[1]
                    member = get_object_or_404(Member, pk=member_pk)
                    request_members.append(member)
                    if member not in conference.members.all():
                        conference.members.add(member)
            for member in conference.members.all():
                if member not in request_members:
                    conference.members.remove(member)
            return JsonResponse({'status': 'ok',
                                 'conference_id': conference.pk})
                    # pdb.set_trace()
        if request.POST.get('register_new_member_adding_to_conference'):
            print(request.POST)
            form = MemberForm(request.POST)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.user = request.user
                instance.save()
                conference.members.add(instance)
                return JsonResponse({'new_member_saved_and_registered_to_conference': 'True'})
            else:
                errors = form.errors
                # pdb.set_trace()
                return JsonResponse({'member_save_errors': True, 'errors': errors})

        return JsonResponse({'status': 'ok'})
Example #15
0
 def test_member_form_save_add_username(self):
     form = MemberForm(data=self.form_data)
     instance = form.save()
     username = instance.username
     instance.refresh_from_db()
     self.assertTrue(instance.username == username)
Example #16
0
def create_member(request):
    form = MemberForm(request.POST)
    if form.is_valid():
        member = form.save()
        return JsonResponse({'Result': 'Member created', 'id': member.id})
    return JsonResponse({'error': form.errors}, status=400)