def demo_add(request):
    context = RequestContext(request)
    context_dict = {}
    t = get_team(request.user)
    add_isteam_to_context_dict(context_dict, t)

    added = False
    t = get_team(request.user)
    if t:
        if request.method == 'POST':
            demo_form = DemoForm(data=request.POST)
            if demo_form.is_valid():
                demo = demo_form.save(commit=False)
                demo.team = t
                if 'screenshot' in request.FILES:
                    demo.logo = request.FILES['screenshot']

                demo.save()
                added = True
                return HttpResponseRedirect('/showcase/team/' + str(t.id) +
                                            '/')
            else:
                print demo_form.errors
        else:
            demo_form = DemoForm()

        # Render the template depending on the context.
        context_dict['demo_form'] = demo_form
        context_dict['added'] = added
        return render_to_response('showcase/demo_add.html', context_dict,
                                  context)
    else:
        return HttpResponse('You need to be a team to add a demo.')
def contact(demo):
  form = ContactForm()
  form2 = DemoForm()

  demo = False if demo == '0' else True

  if request.method == 'POST':
    if form and form.validate() == False and demo == False or form2 and form2.validate() == False and demo == True:
      error_message = gettext('All fields are required and e-mail must be valid')
      flash(error_message)
      return render_template('contact.html', **locals())
    elif form2 and form2.validate() == True:
      msg = Message("Demo Request", sender='*****@*****.**', recipients=['*****@*****.**'])
      msg.body = """
      From: %s <%s>
      %s
      """ % (form.name.data, form.email.data, form.message.data)
      mail.send(msg)
      success = True
      return render_template('contact.html', **locals())
    elif form and form.validate() == True:
      msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**'])
      msg.body = """
      From: %s <%s>
      %s
      """ % (form.name.data, form.email.data, form.message.data)
      mail.send(msg)
      success = True
      return render_template('contact.html', **locals())
    else:
      return render_template('contact.html', **locals())

  elif request.method == 'GET':
    return render_template('contact.html', **locals())
Exemple #3
0
def demoui():
    form = DemoForm()
    if form.validate_on_submit():
        #print(request.form.to_dict())
        args = copy.deepcopy(request.form.to_dict())
        del args['csrf_token']
        return redirect(url_for('demo_app', **args))
    return render_template('demo.html', title='nexo', form=form)
def demo_edit(request, demoid=None):
    """
    Thanks to: http://wiki.ddenis.com/index.php?title=Django,_add_and_edit_object_together_in_the_same_form
    """
    context = RequestContext(request)
    t = get_team(request.user)
    context_dict = {}
    add_isteam_to_context_dict(context_dict, t)

    edit = False
    if t:
        if demoid:
            demo = get_object_or_404(Demo, pk=demoid)
            edit = True
            print demo, demo.id, demo.url
            if demo.team.user != request.user:
                return HttpResponseForbidden()
        else:
            demo = Demo(team=t)
        #Could use this instead -> if request.POST:
        if request.method == 'POST':
            demo_form = DemoForm(request.POST, request.FILES, instance=demo)
            if demo_form.is_valid():
                if 'screenshot' in request.FILES:
                    demo.logo = request.FILES['screenshot']
                demo_form.save()
                return HttpResponseRedirect('/showcase/team/' + str(t.id) +
                                            '/')
            else:
                print demo_form.errors
        else:
            demo_form = DemoForm(instance=demo)

        # Render the template depending on the context.
        return render_to_response('showcase/demo_add.html', {
            'demo_form': demo_form,
            'demoid': demoid,
            'edit': edit
        }, context)
    else:
        return HttpResponse('You need to be a team to add or edit a demo.')