예제 #1
0
파일: views.py 프로젝트: kelvinn/helomx
def add_company(request):
    from django.contrib.auth.models import User, Permission
    site_form = AddCompanyForm()
    name_form = UpdateNameForm()
    if request.method == 'POST':
        site_form = AddCompanyForm(request.POST)
        try:
            name_form = UpdateNameForm(request.POST)
        except:
            name_form = None

        #engineer = Engineer.objects.get(user__username=request.user.username)
        if site_form.is_valid() and name_form.is_valid():
            if request.user.is_authenticated():
                new_company = Company(primary_contact=request.user,
                                    name=site_form.cleaned_data['name'],
                                    slug=slugify(site_form.cleaned_data['name']),
                                    street=site_form.cleaned_data['street'],
                                    city=site_form.cleaned_data['city'],
                                    state=site_form.cleaned_data['state'],
                                    postcode=site_form.cleaned_data['postcode'],
                                    country=site_form.cleaned_data['country'],
                                    telephone=site_form.cleaned_data['telephone'],
                                    )
                new_company.save()
                new_user = request.user
                perm = Permission.objects.get(codename="delete_mailserver")
                new_user.user_permissions.add(perm)
                perm = Permission.objects.get(codename="change_mailserver")
                new_user.user_permissions.add(perm)
                perm = Permission.objects.get(codename="add_mailserver")
                new_user.user_permissions.add(perm)
                perm = Permission.objects.get(codename="change_company")
                new_user.user_permissions.add(perm)
                perm = Permission.objects.get(codename="add_invoicehistory")
                new_user.user_permissions.add(perm)
                perm = Permission.objects.get(codename="change_credit")
                new_user.user_permissions.add(perm)

                credit_obj = Credit(company=new_company, credit_left=0)
                credit_obj.save()

                engineer_list = Engineer.objects.filter(user__username=request.user.username)
                if len(engineer_list) > 0:
                    return HttpResponseRedirect('/dashboard/')
                else:
                    name_form = UpdateNameForm(data=request.POST, instance=request.user)
                    name_form.save()
                    new_engineer = Engineer(user=request.user,
                                            timezone=site_form.cleaned_data['timezone'],
                                            company=new_company,
                                            )
                    new_engineer.save()
                    return HttpResponseRedirect('/add/mailserver/')

        return render_to_response("profiles/firstlogin.html", {
                                    'company_form': site_form,
                                    'name_form': name_form,
                                    },
                                    context_instance=RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: kelvinn/helomx
def add_engineer(request):
    from django.contrib.auth.models import User, Permission
    from django.template.defaultfilters import slugify
    site_form = AddEngineerForm()
    perm_form = EngineerPermForm()
    message = None
    engineer = Engineer.objects.get(user__username=request.user.username)
    mailserver_list = get_mx_list(engineer.company)
    company = engineer.company
    engineer_list = Engineer.objects.filter(company=company)
    if request.method == 'POST':
        site_form = AddEngineerForm(request.POST)
        if site_form.is_valid():
            if request.user.is_authenticated():
                new_user = User.objects.create_user(
                    slugify(site_form.cleaned_data['user']),
                    site_form.cleaned_data['email'],
                    site_form.cleaned_data['password1'])
                new_user.is_active = True
                new_user.first_name = site_form.cleaned_data['first_name']
                new_user.last_name = site_form.cleaned_data['last_name']
                new_user.save()
                if site_form.cleaned_data['can_edit_mx'] == True:
                    perm = Permission.objects.get(codename="delete_mailserver")
                    new_user.user_permissions.add(perm)
                    perm = Permission.objects.get(codename="change_mailserver")
                    new_user.user_permissions.add(perm)
                    perm = Permission.objects.get(codename="add_mailserver")
                    new_user.user_permissions.add(perm)
                if site_form.cleaned_data['can_edit_company'] == True:
                    perm = Permission.objects.get(codename="change_company")
                    new_user.user_permissions.add(perm)
                if site_form.cleaned_data['can_edit_billing'] == True:
                    perm = Permission.objects.get(
                        codename="add_invoicehistory")
                    new_user.user_permissions.add(perm)
                    perm = Permission.objects.get(codename="change_credit")
                    new_user.user_permissions.add(perm)
                new_engineer = Engineer(
                    user=new_user,
                    timezone=site_form.cleaned_data['timezone'],
                    company=company,
                    mobile=site_form.cleaned_data['mobile'])
                new_engineer.save()
                message = "Engineer added successfully"
    return render_to_response("profiles/add_engineer.html", {
        'mailserver_list': mailserver_list,
        'engineer_form': site_form,
        'message': message,
        'company': company,
        'engineer_list': engineer_list,
    },
                              context_instance=RequestContext(request))
예제 #3
0
파일: views.py 프로젝트: kelvinn/helomx
def add_engineer(request):
    from django.contrib.auth.models import User, Permission
    from django.template.defaultfilters import slugify
    site_form = AddEngineerForm()
    perm_form = EngineerPermForm()
    message = None
    engineer = Engineer.objects.get(user__username=request.user.username)
    mailserver_list = get_mx_list(engineer.company)
    company = engineer.company
    engineer_list = Engineer.objects.filter(company=company)
    if request.method == 'POST':
        site_form = AddEngineerForm(request.POST)
        if site_form.is_valid():
            if request.user.is_authenticated():
                new_user = User.objects.create_user(slugify(site_form.cleaned_data['user']), site_form.cleaned_data['email'], site_form.cleaned_data['password1'])
                new_user.is_active = True
                new_user.first_name = site_form.cleaned_data['first_name']
                new_user.last_name = site_form.cleaned_data['last_name']
                new_user.save()
                if site_form.cleaned_data['can_edit_mx'] == True:
                    perm = Permission.objects.get(codename="delete_mailserver")
                    new_user.user_permissions.add(perm)
                    perm = Permission.objects.get(codename="change_mailserver")
                    new_user.user_permissions.add(perm)
                    perm = Permission.objects.get(codename="add_mailserver")
                    new_user.user_permissions.add(perm)
                if site_form.cleaned_data['can_edit_company'] == True:
                    perm = Permission.objects.get(codename="change_company")
                    new_user.user_permissions.add(perm)
                if site_form.cleaned_data['can_edit_billing'] == True:
                    perm = Permission.objects.get(codename="add_invoicehistory")
                    new_user.user_permissions.add(perm)
                    perm = Permission.objects.get(codename="change_credit")
                    new_user.user_permissions.add(perm)
                new_engineer = Engineer(user=new_user,
                                      timezone=site_form.cleaned_data['timezone'],
                                      company=company,
                                      mobile=site_form.cleaned_data['mobile'])
                new_engineer.save()
                message = "Engineer added successfully"
    return render_to_response("profiles/add_engineer.html", {
                                'mailserver_list': mailserver_list,
                                'engineer_form': site_form,
                                'message': message,
                                'company': company,
                                'engineer_list': engineer_list,
                                },
                                context_instance=RequestContext(request))
예제 #4
0
파일: views.py 프로젝트: kelvinn/helomx
def add_company(request):
    from django.contrib.auth.models import User, Permission
    site_form = AddCompanyForm()
    name_form = UpdateNameForm()
    if request.method == 'POST':
        site_form = AddCompanyForm(request.POST)
        try:
            name_form = UpdateNameForm(request.POST)
        except:
            name_form = None

        #engineer = Engineer.objects.get(user__username=request.user.username)
        if site_form.is_valid() and name_form.is_valid():
            if request.user.is_authenticated():
                new_company = Company(
                    primary_contact=request.user,
                    name=site_form.cleaned_data['name'],
                    slug=slugify(site_form.cleaned_data['name']),
                    street=site_form.cleaned_data['street'],
                    city=site_form.cleaned_data['city'],
                    state=site_form.cleaned_data['state'],
                    postcode=site_form.cleaned_data['postcode'],
                    country=site_form.cleaned_data['country'],
                    telephone=site_form.cleaned_data['telephone'],
                )
                new_company.save()
                new_user = request.user
                perm = Permission.objects.get(codename="delete_mailserver")
                new_user.user_permissions.add(perm)
                perm = Permission.objects.get(codename="change_mailserver")
                new_user.user_permissions.add(perm)
                perm = Permission.objects.get(codename="add_mailserver")
                new_user.user_permissions.add(perm)
                perm = Permission.objects.get(codename="change_company")
                new_user.user_permissions.add(perm)
                perm = Permission.objects.get(codename="add_invoicehistory")
                new_user.user_permissions.add(perm)
                perm = Permission.objects.get(codename="change_credit")
                new_user.user_permissions.add(perm)

                credit_obj = Credit(company=new_company, credit_left=0)
                credit_obj.save()

                engineer_list = Engineer.objects.filter(
                    user__username=request.user.username)
                if len(engineer_list) > 0:
                    return HttpResponseRedirect('/dashboard/')
                else:
                    name_form = UpdateNameForm(data=request.POST,
                                               instance=request.user)
                    name_form.save()
                    new_engineer = Engineer(
                        user=request.user,
                        timezone=site_form.cleaned_data['timezone'],
                        company=new_company,
                    )
                    new_engineer.save()
                    return HttpResponseRedirect('/add/mailserver/')

        return render_to_response("profiles/firstlogin.html", {
            'company_form': site_form,
            'name_form': name_form,
        },
                                  context_instance=RequestContext(request))