Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from timtec.settings import ACCOUNT_REQUIRED_FIELDS as fields
from accounts.models import UserSocialAccount
from hcaptcha2.fields import hCaptchaField


User = get_user_model()
Expand Down Expand Up @@ -77,6 +78,7 @@ class SignupForm(AcceptTermsForm):
city = forms.CharField(max_length=50, label=_('City'), widget=forms.Select, required=False)
how_you_know = forms.CharField(max_length=50, label=_('How do you know the platform?'), required=False)
how_you_know_complement = forms.CharField(max_length=50, label=_('Complement for "How do you know the platform?"'), required=False)
hcaptcha = hCaptchaField()

def __init__(self, *args, **kwargs):
super(SignupForm, self).__init__(*args, **kwargs)
Expand Down
3 changes: 3 additions & 0 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from django.contrib.auth import get_user_model
from django.conf import settings

from hcaptcha2.fields import hCaptchaField

from .models import Class
import logging

Expand All @@ -17,6 +19,7 @@ class ContactForm(forms.Form):
name = forms.CharField(label=_('Name'), max_length=128)
email = forms.EmailField(label=_('Email'))
message = forms.CharField(label=_('Message'), max_length=255)
hcaptcha = hCaptchaField()

def send_email(self):
subject = self.cleaned_data.get('subject')
Expand Down
41 changes: 31 additions & 10 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from braces.views import LoginRequiredMixin
from notes.models import Note
from django.http import HttpResponse
import pychrome
import base64

from .serializers import (CourseSerializer, CourseProfessorSerializer,
CourseThumbSerializer, LessonSerializer,
Expand All @@ -43,7 +46,7 @@

from .forms import (ContactForm, RemoveStudentForm)

from .permissions import IsProfessorCoordinatorOrAdminPermissionOrReadOnly, IsAdminOrReadOnly, MessageAnswerPermission
from .permissions import IsProfessorCoordinatorOrAdminPermissionOrReadOnly, IsAdminOrReadOnly, MessageAnswerPermission, IsAdmin


class HomeView(ListView):
Expand Down Expand Up @@ -412,17 +415,34 @@ def render_to_response(self, context, **response_kwargs):

width, height = CERTIFICATE_SIZE
url = self.request.build_absolute_uri().split('download')[0] + 'print/'

png_path = os.path.join(MEDIA_ROOT, certificate.link_hash + '.png')
pdf_filename = certificate.link_hash + today + '.pdf'
pdf_path = os.path.join(MEDIA_ROOT, pdf_filename)

driver = webdriver.PhantomJS(executable_path=PHANTOMJS_PATH)
driver.set_window_size(width, height)
driver.get(url)
driver.save_screenshot(filename=png_path)

driver.service.process.send_signal(SIGTERM)
driver.quit()

# FIXME: remover esse hardcode do localhost e porta daqui
browser = pychrome.Browser(url="http://127.0.0.1:9222")
tab = browser.new_tab()

def request_will_be_sent(**kwargs):
print("loading: %s" % kwargs.get('request').get('url'))

tab.Network.requestWillBeSent = request_will_be_sent

tab.start()
tab.Network.enable()
tab.Page.navigate(url=url, _timeout=5)
tab.wait(2)


try:
data = tab.Page.captureScreenshot()
with open(png_path, 'wb') as fd:
fd.write(base64.b64decode(data['data']))
finally:
tab.stop()
browser.close_tab(tab)

Image.open(png_path).convert("RGB").save(pdf_path, format='PDF', quality=100, dpi=(300, 300))

response = HttpResponse(content_type='application/pdf')
Expand Down Expand Up @@ -639,7 +659,8 @@ def list(self, request, *args, **kwargs):

serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)


permission_classes = (IsAdmin,)
def post(self, request, **kwargs):
course = self.get_object()
serializer = CourseSerializer(course, request.data)
Expand Down
2 changes: 1 addition & 1 deletion themes/default/static/less/default/pages/courses.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
color: #000;
}
.info{
height: 85px;
height: 40px;
padding: 0.5em;
h3{
color: #555;
Expand Down
9 changes: 9 additions & 0 deletions themes/default/templates/_contact_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@
<textarea required class="form-control" rows="6" name="{{contact_form.message.name}}"></textarea>
</div>
</div>

{{ contact_form.hcaptcha }}



{% for message in form.captcha.errors %}
<div class="notification is-danger">{{ message }}</div>
{% endfor %}

2 changes: 1 addition & 1 deletion themes/default/templates/_login_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
</p>
</div>
</form>
</div>
</div>
4 changes: 2 additions & 2 deletions themes/default/templates/account/login_modal.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load i18n %}

<!-- Modal -->
<!--my Modal -->
<div id="login-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="loginModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
Expand Down Expand Up @@ -103,7 +103,7 @@ <h3 class="bottom-xs"><i class="fa fa-angle-double-right"></i> {% trans 'Sign Up
<div class="submit textright">
<div class="row">
<div class="col-lg-4 col-lg-offset-8 col-md-5 col-md-offset-7 col-sm-7 col-sm-offset-5 col-xs-12 textright">
<button class="btn btn-success col-xs-12">{% trans 'Sign Up' %}</button>
<button class="btn btn-success col-xs-12">Cadastre-se</button>
</div>
</div>
</div>
Expand Down
196 changes: 191 additions & 5 deletions themes/default/templates/account/signup.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,65 @@
{% extends 'account/base.html' %}
{% extends 'default:account/signup-2.html' %}
{% load i18n %}

{% block js %}
<script type="text/javascript" charset="utf-8">
(function(){

function show_how_you_know_complement() {
$('#div-how_you_know_complement').show();
$('#div-how_you_know_complement input').prop('required', true);
}

function hide_how_you_know_complement() {
$('#div-how_you_know_complement').hide();
$('#div-how_you_know_complement input').prop('required', false);
}

function load_states() {

$.get("/api/states", function(item){
options = "<option value=''>---</option>\n";
for(state in item) {
state = item[state];
options += "<option value='"+ state.code +"'>"+ state.name +"</option>\n";
}
$("select[name=state]").empty().append(options);
});
}

function load_cities(state) {
$.get("/api/cities", {'state': state}, function(item){
options = "<option value=''>---</option>\n";
for(city in item) {
city = item[city];
options += "<option value='"+ city.name +"'>"+ city.name +"</option>\n";
}
$("select[name=city]").empty().append(options);
});
}

$(document).ready(function() {
load_states();

hide_how_you_know_complement();
$("select[name=how_you_know]").change(function(){
current_value = $(this).val();
if(current_value == "Através da Imprensa" || current_value == "Outro") {
show_how_you_know_complement();
} else {
hide_how_you_know_complement();
}
});

$("select[name=state]").change(function(){
current_value = $(this).val();
load_cities(current_value);
});
});
})();
</script>
{% endblock %}

<!-- TABLET AND DESKTOP -->
{% block account_content %}
<h1>
Expand All @@ -15,6 +74,74 @@ <h1>
<input type='hidden' name='{{ redirect_field_name }}' value='{{ request.META.HTTP_REFERER }}'>
{% endif %}

{% with errors=form.how_you_know.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">Como você conheceu a plataforma TIM Tec?</label>
<div class="col-lg-8 col-sm-8">
<select name="how_you_know" class="form-control" required>
<option>Indicação de amigo</option>
<option>Facebook</option>
<option>Twitter</option>
<option>Através da Imprensa</option>
<option>Pesquisa no Google</option>
<option>Vi em minha escola/empresa</option>
<option>Outro</option>
</select>
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.how_you_know_complement.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}" id='div-how_you_know_complement'>
<label class="col-lg-4 col-sm-4 control-label">Onde?</label>
<div class="col-lg-8 col-sm-8">
<input name="how_you_know_complement" type="text" value="{{form.how_you_know_complement.value|default_if_none:""}}" class="form-control" placeholder="Dê mais detalhes de onde nos conheceu" maxlength="50">
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.first_name.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">{{ form.first_name.label }}</label>
<div class="col-lg-8 col-sm-8">
<input name="first_name" type="text" value="{{form.first_name.value|default_if_none:""}}" class="form-control" placeholder="{{ form.first_name.label }}" required>
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.last_name.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">{{ form.last_name.label }}</label>
<div class="col-lg-8 col-sm-8">
<input name="last_name" type="text" value="{{form.last_name.value|default_if_none:""}}" class="form-control" placeholder="{{ form.last_name.label }}" required>
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.state.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">{{ form.state.label }}</label>
<div class="col-lg-8 col-sm-8">
{{ form.state }}
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.city.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">{{ form.city.label }}</label>
<div class="col-lg-8 col-sm-8">
{{ form.city }}
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.username.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">{% trans "Username" %}</label>
Expand Down Expand Up @@ -47,7 +174,9 @@ <h1>
</div>
{% endwith %}

{% block extrafields %}{% endblock %}
{{form.hcaptcha}}
{{form.hcaptcha.errors}}

{% if terms_required %}
{% with errors=form.accept_terms.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
Expand Down Expand Up @@ -94,11 +223,69 @@ <h1>
</div>
</div>
<form onclick="event.stopPropagation()" method="post" action="{% url 'account_signup' %}" class="form-horizontal">{% csrf_token %}
{% with errors=form.how_you_know.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">Como você conheceu a plataforma TIM Tec?</label>
<div class="col-lg-8 col-sm-8">
<select name="how_you_know" class="form-control" required>
<option>Indicação de amigo</option>
<option>Facebook</option>
<option>Twitter</option>
<option>Através da Imprensa</option>
<option>Pesquisa no Google</option>
<option>Vi em minha escola/empresa</option>
<option>Outro</option>
</select>
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.first_name.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">{{ form.first_name.label }}</label>
<div class="col-lg-8 col-sm-8">
<input name="first_name" type="text" value="{{form.first_name.value|default_if_none:""}}" class="form-control" placeholder="{{ form.first_name.label }}" required>
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.last_name.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">{{ form.last_name.label }}</label>
<div class="col-lg-8 col-sm-8">
<input name="last_name" type="text" value="{{form.last_name.value|default_if_none:""}}" class="form-control" placeholder="{{ form.last_name.label }}" required>
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.state.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">{{ form.state.label }}</label>
<div class="col-lg-8 col-sm-8">
{{ form.state }}
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.city.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-lg-4 col-sm-4 control-label">{{ form.city.label }}</label>
<div class="col-lg-8 col-sm-8">
{{ form.city }}
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
{% endwith %}

{% with errors=form.username.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-xs-12 control-label">{% trans "Username" %}</label>
<div class="col-xs-12">
<input name="username" type="text" value="{{form.username.value}}" class="form-control" placeholder="{% trans 'Username' %}" required>
<input name="username" type="text" value="{{form.username.value|default_if_none:""}}" class="form-control" placeholder="{% trans 'Username' %}" required>
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
Expand All @@ -108,7 +295,7 @@ <h1>
<div class="form-group{{ errors|yesno:' has-error,' }}">
<label class="col-xs-12 control-label">{% trans "E-mail" %}</label>
<div class="col-xs-12">
<input name="email" type="email" value="{{form.email.value}}" class="form-control" placeholder="Your e-mail" required>
<input name="email" type="email" value="{{form.email.value|default_if_none:""}}" class="form-control" placeholder="Your e-mail" required>
{% for error in errors %}<small>{{error}}</small>{% endfor %}
</div>
</div>
Expand All @@ -125,7 +312,6 @@ <h1>
</div>
{% endwith %}

{% block extrafields_mobile %}{% endblock %}
{% if terms_required %}
{% with errors=form.accept_terms.errors %}
<div class="form-group{{ errors|yesno:' has-error,' }}">
Expand Down
Loading