~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to mainpage/views.py

  • Committer: franku
  • Date: 2016-07-02 12:38:06 UTC
  • mfrom: (404.2.56 widelands)
  • Revision ID: somal@arcor.de-20160702123806-q69u3d48s1prrxds
merged the django1_8 branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
def legal_notice(request):
22
22
    """The legal notice page to fullfill law."""
23
 
 
24
23
    if request.method == 'POST':
25
24
        form = ContactForm(request.POST)
26
25
        if form.is_valid():
32
31
                                form.cleaned_data['inquiry']])
33
32
            sender = 'legal_note@widelands.org'
34
33
 
35
 
            ## get email addresses which are in a tuple of ('name','email'),
 
34
            ## get email addresses which are in form of ('name','email'),
36
35
            recipients = []
37
36
            for recipient in INQUIRY_RECIPIENTS:
38
37
                recipients.append(recipient[1])
 
38
                print('recipeients: ', recipients)
39
39
 
40
40
            send_mail(subject, message, sender,
41
41
                recipients, fail_silently=False)
43
43
 
44
44
    else:
45
45
        form = ContactForm() # An unbound form
46
 
 
 
46
    
47
47
    return render(request, 'mainpage/legal_notice.html', {
48
48
        'form': form,
 
49
        'inquiry_recipients': INQUIRY_RECIPIENTS,
49
50
        })
50
51
 
51
52
def legal_notice_thanks(request):
52
53
    return render(request, 'mainpage/legal_notice_thanks.html')
53
54
 
54
 
 
55
 
from forms import RegistrationWithCaptchaForm
56
 
from registration.backends.default import DefaultBackend
57
 
 
58
 
 
59
 
def register(request):
60
 
    """Overwritten view from registration to include a captcha.
61
 
 
62
 
    We only need this because the remote IP addr must be passed to the
63
 
    form; the registration doesn't do this
64
 
 
65
 
    """
66
 
    remote_ip = request.META['REMOTE_ADDR']
67
 
    if request.method == 'POST':
68
 
        form = RegistrationWithCaptchaForm(remote_ip, data=request.POST,
69
 
                                           files=request.FILES)
70
 
        if form.is_valid():
71
 
            new_user = DefaultBackend().register(request, **form.cleaned_data)
72
 
            return HttpResponseRedirect(reverse('registration_complete'))
73
 
    else:
74
 
        form = RegistrationWithCaptchaForm(remote_ip)
75
 
 
76
 
    return render_to_response('registration/registration_form.html',
77
 
                              {'registration_form': form},
78
 
                              context_instance=RequestContext(request))
79
 
 
80
 
 
 
55
from wlprofile.models import Profile
 
56
from registration.backends.hmac.views import RegistrationView
 
57
from django.contrib.auth.models import User
 
58
 
 
59
class OwnRegistrationView(RegistrationView):
 
60
    """
 
61
    Overwriting the default function to save also the extended User model (wlprofile)
 
62
    """
 
63
    def create_inactive_user(self, form):
 
64
        """
 
65
        Additionally save the custom enxtended user data.
 
66
        """
 
67
        new_user = form.save(commit=False)
 
68
        new_user.is_active = False
 
69
        new_user.save()
 
70
        reg_user = User.objects.get(username=new_user)
 
71
        ext_profile = Profile(user=reg_user)
 
72
        ext_profile.save()
 
73
 
 
74
        self.send_activation_email(new_user)
 
75
 
 
76
        return new_user
 
77
    
81
78
def developers(request):
82
79
    """This reads out some json files in the SVN directory, and returns it as a
83
80
    wl_markdown_object.