Exemplo n.º 1
0
def send_email(request, form):
    data=deserialize_form(form)
    dajax=Dajax()
    event = Event.objects.get(pk=data['event_id'])
    if data['email_type'] == 'single':
        new_mail = MailLog.objects.create(from_email=data['from_email'], \
            to_email=data['to_email'], subject=data['subject'], \
            body=data['body'], created_by=request.user)
        mail.send(
            [data['to_email']],data['from_email'],
            subject=data['subject'],
            html_message=data['body'],
        )
        to_return ={
            'mail': new_mail,
        }
        html_content = render_to_string('mailer/sent_preview.html', to_return, RequestContext(request))
        if html_content:
            dajax.assign("#registration_data", "innerHTML", html_content)
            show_alert(dajax, 'info', 'Your email has been sent!')
    elif data['email_type'] == 'group':
        email_list=[]
        event = Event.objects.get(pk=data['event_id'])
        registrations = EventRegistration.objects.filter(event= event)
        if event.is_team:
            for regn in registrations:
                for mem in regn.team.members.all():
                    email_list.append(mem.email)
                email_list.append(regn.participant.email)
        elif not event.is_team:
            for regn in registrations:
                email_list.append(regn.participant.email)
        email_list = list(set(email_list))

        to_string=json.dumps(email_list)
        new_mail = MailLog.objects.create(from_email=data['from_email'], \
            to_email=to_string, subject=data['subject'], \
            body=data['body'], created_by=request.user, needs_approval=True)
        
        to_return ={
        'msg':'Submitted for Core approval',
        'to_string':to_string,
        'mail': new_mail,
        }
        html_content = render_to_string('mailer/sent_preview.html', to_return, RequestContext(request))
        if html_content:
            dajax.assign("#registration_data", "innerHTML", html_content)
            show_alert(dajax, 'info', 'Your email has been submitted for core approval!')
            event_cores = User.objects.filter(userprofile__status='core').filter(userprofile__dept__name='events')
            event_core_email = list(set([core.email for core in event_cores]))
            mail.send(
                event_core_email, subject='Email for Approval: Saarang ERP',
                html_message = html_content,
            )

    return dajax.json()
Exemplo n.º 2
0
def hello(request):
    """
        Test dajax
    """
    dajax = Dajax()
    dajax.assign('#btn1', 'value', 'Click here!')

    show_alert(dajax, 'error', "There were some errors : please rectify them") # show alert
    
    return dajax.json()
Exemplo n.º 3
0
def core_approve_email(request, mail_id):
    dajax=Dajax()
    email = MailLog.objects.get(pk=mail_id)
    email.is_approved=True
    email.save()
    mail.send(
        json.loads(email.to_email),email.from_email,
        subject=email.subject,
        html_message=email.body,
    )
    to_return ={
        'msg':'Email has been sent',
        'mail': email,
    }
    show_alert(dajax,'info', 'Email has been sent')
    html_content = render_to_string('mailer/sent_preview.html', to_return, RequestContext(request))
    if html_content:
        dajax.assign("#content", "innerHTML", html_content)
    return dajax.json()
Exemplo n.º 4
0
def new_user(request, form):
    data = deserialize_form(form)
    print data
    dajax = Dajax()
    if re.match(r'[^@]+@[^@]+\.[^@]+', data['email']):
        try:
            user=SaarangUser.objects.get(email=data['email'])
            show_alert(dajax,'info', 'You are already registered at Saarang')
        except:
            if re.match(r'^\d{10}$', data['mobile']):
                if data['password'] == data['repassword'] and data['password'] !='':
                    mail.send(
                        [data['email']], template='email/main/register_activate',
                        context={'encoded_email':base64.b64encode(data['email']),}
                    )
                    new_user=SaarangUser.objects.create(email=data['email'], mobile=data['mobile'], password=data['password'])
                    new_user.saarang_id = auto_id(new_user.pk)
                    if data['college'] != '0':
                        college = College.objects.get(pk=data['college'])
                        new_user.college = college.name + ', ' + college.city
                    new_user.save()
                    try:
                        college = data['new_college_text']
                        mail.send(
                            ['*****@*****.**', '*****@*****.**'], data['email'],
                            template='email/main/add_college',
                            context={'name':data['email'], 'college':college,}
                            )
                    except:
                        pass
                    dajax.assign('#success-alert', 'innerHTML', '<center><strong>Registration successfull. Please click on the link sent to your email to activate your account</strong>')
                    dajax.script("$('#registration').hide();$('#success-alert').show();")
                else:
                    show_alert(dajax, 'error', 'Passwords does not match!')
            else:
                show_alert(dajax, 'error', 'Mobile number should be exactly 10 digits!')
    else:
        show_alert(dajax, 'error', 'Please enter a valid email!')
    return dajax.json()
Exemplo n.º 5
0
def process_login(request, form):
    data=deserialize_form(form)
    dajax = Dajax()
    try:
        user = SaarangUser.objects.get(email=data['email'])
        if user.password == data['password']:
            if user.activate_status != 0:
                request.session['saaranguser_email'] = user.email
                user.last_login = dt.datetime.now()
                user.save()
                show_alert(dajax, 'info', 'Logged in')
                dajax.assign('#success-alert', 'innerHTML', '<center>Welcome ' + user.email)
                dajax.script("$('#registration').hide();$('#success-alert').show();")
                dajax.script("var msg='success';var user='******'; parent.postMessage([msg, user], 'http://saarang.org');")
            else:
                show_alert(dajax, 'warning', 'Please click on the link sent to your email to activate your account!')
        else:
            show_alert(dajax, 'error', 'Did you mis-spell your password?')
    except:
        show_alert(dajax, 'warning', 'Is your email id correct?')
    dajax.assign('#signin_button', 'value', 'Try again?')
    dajax.remove_css_class('#signin_button', 'btn-warning')
    return dajax.json()
Exemplo n.º 6
0
def loading_email(request):
    dajax=Dajax()
    show_alert(dajax, 'info', 'Please wait while the emails are being send')
    return dajax.json()