1. uniqx
  2. freieit

Commits

Florian Schweikert  committed 6e76e09

save new expert profile as unavailable

send mail notification for new registration

  • Participants
  • Parent commits 76da021
  • Branches default

Comments (0)

Files changed (2)

File freieit/templates/newexpert.html

View file
 {% extends "base.html" %}
 
+{% load i18n %}
+
 {% block html_header %}
 
 <style>
 
 {% block content %}
 
+{% if expert %}
+
+<h1>{% trans "Thank you!" %}</h1>
+
+<p>
+    {% blocktrans with name=expert.name %}New expert profile created for "{{ name }}".</br>Your profile will be checked and activated soon.{% endblocktrans %}
+</p>
+
+{% else %}
+
 <h1>Lass Dich als Fachkraft für <a href="http://fsfe.org/about/basics/freesoftware.de.html" title="Was ist Freie Software?">Freie Software</a> finden!</h1>
 
 <p>Nur Personen, die sich zu unserer <a href="dienste.htm">Selbstverpflichtung</a> bekennen, nehmen wir in dieses Verzeichnis auf.</p>
     <input type="submit" value="Anmeldung abschicken">
 </form>
 
+{% endif %}
+
 {% endblock content %}

File freieit/views/newexpert.py

View file
 from django.shortcuts import render
 from django.http import HttpResponseRedirect
 from django.core.mail import EmailMessage
+from django.contrib.auth.models import User
+
 from freieit.forms.expert import ExpertProfileForm
 from freieit import settings
 
 def show(request):
     if request.method == 'POST':
         form = ExpertProfileForm(request.POST, request.FILES)
+
         if form.is_valid():
+            email = form.data['email']
+
+            u, created = User.objects.get_or_create(username=email, email=email)
+            if created:
+                u.set_unusable_password()
+                u.save()
+
+            expert = form.save(commit=False)
+            expert.available = False
+            expert.user = u
+            expert.save()
+            
             email_msg = """
             Name:
             %(name)s
 
             Services:
             %(services)s
-            """ % form.data
 
-            subject = "[New expert] %s" % form.data['name']
-            email_from = form.data['email']
+            View and accept (set available to True)
+            http://test.freie.it/admin/freieit/expertprofile/%(id)s
+            """ % expert.__dict__
+
+            subject = "[New expert] %s" % expert.name
+            email_from = email
             email_to = settings.DEFAULT_FROM_EMAIL
 
             email = EmailMessage(subject, email_msg, email_from, [email_to])
 
-            if 'image' in request.FILES:
-                img = request.FILES['image']
-                email.attach(img.name, img.read(), img.content_type)
+            #if 'image' in request.FILES:
+            #    img = request.FILES['image']
+            #    email.attach(img.name, img.read(), img.content_type)
                 
             email.send(fail_silently=False)
-            
-            return HttpResponseRedirect('/')
+
+            return render(request, 'newexpert.html', {'expert': expert})
     else:
         form = ExpertProfileForm()
         
-    return render(request, 'newexpert.html', {'form':form})
+    return render(request, 'newexpert.html', {'form': form})