Beispiel #1
0
def edit_project(request, encrypted_id):
    if ie_test(request):
        return fuck_ie(request)
    
    now = datetime.now()
    post_id = unencrypt(encrypted_id)
    post = Posting.objects.get(id=post_id)

    try:
        if not ((request.session['user'] == post.contact_email) \
            and (request.session['passkey'] == post.passkey)):
            pass
    # user needs to put in email and passkey
    except:
        return HttpResponseRedirect('/listings/%sL/#openModal' % (encrypted_id))
    
    if request.method == 'POST': # If the form has been submitted...
        form = PostingForm(data=request.POST, instance=post)
        if form.is_valid(): # All validation rules pass
            edit_post = form.save()
            edit_post.date_modified = now
            edit_post.save()
            return HttpResponseRedirect('/edit_success/') # Redirect after POST
    else:
        form = PostingForm(instance=post) # A form bound to the POST data
        
    return render(request, 'agora/base_edit_project.html', {
        'form' : form,
        'listing' : post,
        'pagetitle' : 'edit post',
    })
Beispiel #2
0
def post_project(request):
    if ie_test(request):
        return fuck_ie(request)
    
    now = datetime.now()
    if request.method == 'POST': # If the form has been submitted...
        form = PostingForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ... here is where we save()
            post = form.save()
            post.passkey = post.gen_passkey()
            post.date_modified = now
            post.save()
            # For email stuffs
            first_name = post.name.split()[0]
            subject = "projectMed: %s, save this email!" % (first_name)
            message = "Thank you for using projectMed, %s!\n\n\nWe\'ve added your listing:\n\"%s\"\n\nBelow is the permanent link to your project listing:\nhttp://www.projectMed.org/listings/%s/\n\nIf you need to edit/delete your project listing, you'll need this passkey:\n%s\n\n\nGood luck finding a great student collaborator,\nprojectMed Team" % (first_name,post.title,post.gen_url(),post.passkey)
            from_email = 'projectMed <*****@*****.**>'
            to_email = form.cleaned_data['contact_email']
            send_mail(subject, message, from_email, [to_email], fail_silently=True)
            return HttpResponseRedirect('/submit_success/') # Redirect after POST
    else:
        form = PostingForm() # An unbound form

    return render(request, 'agora/base_post_project.html', {
        'form': form,
        'pagetitle' : 'submit',
    })
Beispiel #3
0
def edit_project(request, encrypted_id):
    if ie_test(request):
        return fuck_ie(request)

    now = datetime.now()
    post_id = unencrypt(encrypted_id)
    post = Posting.objects.get(id=post_id)

    try:
        if not ((request.session['user'] == post.contact_email) \
            and (request.session['passkey'] == post.passkey)):
            pass
    # user needs to put in email and passkey
    except:
        return HttpResponseRedirect('/listings/%sL/#openModal' %
                                    (encrypted_id))

    if request.method == 'POST':  # If the form has been submitted...
        form = PostingForm(data=request.POST, instance=post)
        if form.is_valid():  # All validation rules pass
            edit_post = form.save()
            edit_post.date_modified = now
            edit_post.save()
            return HttpResponseRedirect(
                '/edit_success/')  # Redirect after POST
    else:
        form = PostingForm(instance=post)  # A form bound to the POST data

    return render(request, 'agora/base_edit_project.html', {
        'form': form,
        'listing': post,
        'pagetitle': 'edit post',
    })
Beispiel #4
0
def post_project(request):
    if ie_test(request):
        return fuck_ie(request)

    now = datetime.now()
    if request.method == 'POST':  # If the form has been submitted...
        form = PostingForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            # ... here is where we save()
            post = form.save()
            post.passkey = post.gen_passkey()
            post.date_modified = now
            post.save()
            # For email stuffs
            first_name = post.name.split()[0]
            subject = "projectMed: %s, save this email!" % (first_name)
            message = "Thank you for using projectMed, %s!\n\n\nWe\'ve added your listing:\n\"%s\"\n\nBelow is the permanent link to your project listing:\nhttp://www.projectMed.org/listings/%s/\n\nIf you need to edit/delete your project listing, you'll need this passkey:\n%s\n\n\nGood luck finding a great student collaborator,\nprojectMed Team" % (
                first_name, post.title, post.gen_url(), post.passkey)
            from_email = 'projectMed <*****@*****.**>'
            to_email = form.cleaned_data['contact_email']
            send_mail(subject,
                      message,
                      from_email, [to_email],
                      fail_silently=True)
            return HttpResponseRedirect(
                '/submit_success/')  # Redirect after POST
    else:
        form = PostingForm()  # An unbound form

    return render(request, 'agora/base_post_project.html', {
        'form': form,
        'pagetitle': 'submit',
    })