Exemple #1
0
def change_password(request):
    form = PasswordChangeForm(request.user)
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, data=request.POST)
        if form.is_valid():
            form.save()
            return reverse_redirect('profile')
    return {'form': form}
Exemple #2
0
def change_password(request):
	form = PasswordChangeForm(request.user)
	if request.method == 'POST':
		form = PasswordChangeForm(request.user, data=request.POST)
		if form.is_valid():
			form.save()
			return reverse_redirect('profile')
	return {'form':form}
Exemple #3
0
def edit_profile(request):
    profile = request.user.get_profile()
    initial = { 'first_name': profile.user.first_name, 'last_name': profile.user.last_name, 'email': profile.user.email }
    if request.method == "POST":
        form = EditProfileForm(request.POST, request.FILES, instance=profile)
        if form.is_valid():
            form.save()
            return reverse_redirect('profile')
        else:
			form = EditProfileForm(initial=initial, instance=profile)
        return {'form': form,'profile':profile}
	return {'profile':profile}
Exemple #4
0
def add_game_level(request, game_id=None):
    game = get_object_or_None(Game, pk=game_id)
    form = GameLevelForm()
    if request.method == 'POST':
	form = GameLevelForm(request.POST)
	if form.is_valid():
	    level = form.save(commit=False)
	    level.game = game
	    import datetime
	    level.date_created = datetime.datetime.today()
	    level.created_by = request.user
	    level.save()
	    return reverse_redirect('view-game', args=[game.id])
    return { 'form':form, 'game':game }
Exemple #5
0
def delete_payment(request, payment_id):
    payment = get_object_or_404(InvoicePayment.objects.select_related(),
                                pk=payment_id)
    payment.is_active = False
    payment.modified_by = request.user
    payment.save()
    invoice = payment.invoice
    invoice.update_fully_paid()
    msg = "Payment {0} deleted.".format(payment)
    messages.add_message(request, settings.DELETE_MESSAGE, msg)
    action.send(request.user,
                verb='deleted payment record',
                action_object=payment)
    return reverse_redirect('invoice:view_invoice', [payment.invoice.id])
Exemple #6
0
def add_apt(request, game_id=None, game_level_id=None):
    level = get_object_or_None(GameLevel, pk=game_level_id)
    form = APTForm()
    if request.method == 'POST':
	form = APTForm(request.POST)
	if form.is_valid():
	    apt = form.save(commit=False)
	    apt.user = request.user
	    apt.game_level = level
	    import datetime
	    apt.date_added = datetime.datetime.today()
	    apt.added_by = request.user
	    apt.save()
	    return reverse_redirect('view-game', args=[level.game.id])
    return { 'form':form, 'level':level }
Exemple #7
0
def update_invoice(request, invoice):
    args = {}
    company_id = request.POST.get('company')
    company = get_object_or_None(Company, pk=company_id)
    pay_level_ids = request.POST.getlist('pay_levels')
    total_amount = request.POST.get('total_amount')
    args['company'] = company
    pay_levels = PayrollRate.objects.filter(id__in=pay_level_ids)
    args['pay_levels'] = pay_levels
    payments, total_paid = invoice.get_total_paid()
    args['balance'] = invoice.total_amount - total_paid
    args['add_types'] = ADD_INVOICE_ITEM_TYPE
    args['deduct_types'] = DEDUCT_INVOICE_ITEM_TYPE
    args['invoice'] = invoice
    invoiceform = InvoiceForm(request.POST, instance=invoice)
    formset = InvoiceItemFormset(request.POST,
                                 prefix='invoiceitem',
                                 instance=invoice)
    args['formset'] = formset
    args['invoiceform'] = invoiceform

    if not invoiceform.is_valid():
        messages.error(request, "Error updating invoice")
        return render(request, 'invoice/invoice_detail.html', args)

    for form in formset.forms:
        if not form.is_valid():
            messages.error(request, "Error updating invoice")
            return render(request, 'invoice/invoice_detail.html', args)

    invoice = invoiceform.save(commit=False)
    invoice.total_amount = total_amount
    invoice.company = company
    invoice.modified_by = request.user
    invoice.update_fully_paid()
    invoiceform.save_m2m()
    for form in formset.forms:
        if form in formset.deleted_forms:
            form.instance.delete()
        else:
            item = form.save(commit=False)
            item.created_by = request.user
            item.modified_by = request.user
            item.invoice = invoice
            item.save()
    messages.success(request, "Invoice updated.")
    action.send(request.user, verb='updated invoice', action_object=invoice)
    return reverse_redirect('invoice:view_invoice', [invoice.id])
Exemple #8
0
def profile(request, username=''):    
    mine = False
    if username == '':
        if request.user.is_authenticated():
            profile = request.user.get_profile()
            mine = True
        else:
            return reverse_redirect('index')
    else:
        user = get_object_or_404(User, username=username)
        profile = user.get_profile()
        me = UserProfile.objects.get(user=request.user)
        if user == request.user:
            mine = True
    
    return {'profile': profile, 'mine': mine}
Exemple #9
0
def profile(request, username=''):
    mine = False
    if username == '':
        if request.user.is_authenticated():
            profile = request.user.get_profile()
            mine = True
        else:
            return reverse_redirect('home')
    else:
        user = get_object_or_404(User, username=username)
        profile = user.get_profile()
        me = UserProfile.objects.get(user=request.user)
        if user == request.user:
            mine = True

    return {'profile': profile, 'mine': mine}
Exemple #10
0
def profile(request, username=""):
    mine = False
    if username == "":
        if request.user.is_authenticated():
            profile = request.user.get_profile()
            mine = True
        else:
            return reverse_redirect("home")
    else:
        user = get_object_or_404(User, username=username)
        profile = user.get_profile()
        me = UserProfile.objects.get(user=request.user)
        if user == request.user:
            mine = True

    return {"profile": profile, "mine": mine}
Exemple #11
0
def save_invoice(request, costcenter):
    args = {}
    cost_center = get_object_or_None(CostCenter, id=costcenter)
    args['costcenter'] = cost_center
    if cost_center.detachment:
        company = cost_center.detachment.company
    elif cost_center.company:
        company = cost_center.company
    args['company'] = company
    total_amount = request.POST.get('total_amount')
    args['invoiceform'] = InvoiceForm(request.POST)
    args['formset'] = InvoiceItemFormset(request.POST, prefix='invoiceitem')
    args['title'] = 'Create Invoice'
    args['add_types'] = ADD_INVOICE_ITEM_TYPE
    args['deduct_types'] = DEDUCT_INVOICE_ITEM_TYPE

    invoiceform = InvoiceForm(request.POST)
    if not invoiceform.is_valid():
        messages.error(request, 'Error saving invoice')
        return render(request, 'invoice/create_invoice.html', args)

    formset = InvoiceItemFormset(request.POST, prefix='invoiceitem')
    for form in formset.forms:
        if not form.is_valid():
            messages.error(request, 'Error saving invoice')
            return render(request, 'invoice/create_invoice.html', args)

    invoice = invoiceform.save(commit=False)
    invoice.total_amount = total_amount
    invoice.created_by = request.user
    invoice.modified_by = request.user
    invoice.save()
    invoiceform.save_m2m()

    formset = InvoiceItemFormset(request.POST, prefix='invoiceitem')
    for form in formset.forms:
        if not form.has_changed():
            continue
        else:
            item = form.save(commit=False)
            item.created_by = request.user
            item.modified_by = request.user
            item.invoice = invoice
            item.save()
    messages.success(request, "Invoice saved.")
    action.send(request.user, verb='saved invoice', action_object=invoice)
    return reverse_redirect('invoice:view_invoice', [invoice.id])
Exemple #12
0
def edit_profile(request):
    profile = request.user.get_profile()
    if not profile.department is "Human Resource Department":
        initial = {
            "first_name": profile.user.first_name,
            "last_name": profile.user.last_name,
            "email": profile.user.email,
        }
        if request.method == "POST":
            form = EditProfileForm(request.POST, request.FILES, instance=profile)
            if form.is_valid():
                form.save()
                return reverse_redirect("profile")
        else:
            form = EditProfileForm(initial=initial, instance=profile)
        return {"form": form, "profile": profile}
    return {"profile": profile}
Exemple #13
0
def add_game(request):
    form = GameForm()
    if request.method == 'POST':
	form = GameForm(request.POST)
	if form.is_valid():
	    game = form.save(commit=False)
	    import uuid, hmac
	    try:
		from hashlib import sha1
	    except ImportError:
		import sha
		sha1 = sha.sha
	    new_uuid = uuid.uuid4()
	    api_key = hmac.new(str(new_uuid), digestmod=sha1).hexdigest()[0:24]
	    game.game_id = str(new_uuid)[0:8]
	    game.api_key = api_key
	    game.created_by = request.user
	    game.save()
	    return reverse_redirect('all-games')
    return { 'form':form }
Exemple #14
0
def edit_profile(request):

	profile = request.user.get_profile()
	initial = { 'first_name': profile.user.first_name, 'last_name': profile.user.last_name, 'email': profile.user.email }
	form = EditProfileForm(initial=initial, instance=profile)
	if not profile.department.name is 'Human Resource Department':
		if request.method == "POST":
			form = EditProfileForm(request.POST, request.FILES, instance=profile)
			if form.is_valid():
				my_profile = form.save(commit=False)
				my_profile.personnel_id = request.POST['personnel_id']
				my_profile.designation = request.POST['designation']
				department = Department.objects.get(pk=request.POST['department'])
				my_profile.department = department
				my_profile.official_email = request.POST['official_email']
				my_profile.tax_status = request.POST['tax_status']
				my_profile.save()
				return reverse_redirect('profile')         
		else:
			form = EditProfileForm(initial=initial, instance=profile)
		return {'form': form,'profile':profile}
	return {'profile':profile}
Exemple #15
0
def view_invoice(request, invoice_id):
    args = {}
    invoice = get_object_or_None(Invoice, pk=invoice_id)
    if not invoice:
        messages.error(request, "Invoice record not found.")
        return reverse_redirect('invoice:list_invoices')
    payments, total_paid = invoice.get_total_paid()
    items = invoice.invoiceitem_set.order_by('pk')
    InvoiceItemFormset.extra = 0
    args['formset'] = InvoiceItemFormset(instance=invoice,
                                         prefix='invoiceitem',
                                         queryset=items)
    args['invoice'] = invoice
    args['period'] = invoice.period
    args['invoiceform'] = InvoiceForm(instance=invoice)
    args['periods'] = ACTIVE_PERIODS
    args['payment_form'] = InvoicePaymentForm()
    args['balance'] = invoice.total_amount - total_paid
    args['add_types'] = ADD_INVOICE_ITEM_TYPE
    args['deduct_types'] = DEDUCT_INVOICE_ITEM_TYPE
    args['pay_levels'] = invoice.pay_levels.all()
    if request.method == 'POST':
        return update_invoice(request, invoice)
    return render(request, 'invoice/invoice_detail.html', args)
Exemple #16
0
def duplicate_invoice(request, invoice_id):
    args = {}
    invoice = get_object_or_None(Invoice, pk=invoice_id)
    if not invoice:
        messages.error(request, "Invoice record not found.")
        return reverse_redirect('invoice:list_invoices')
    args['invoiceform'] = InvoiceForm(instance=invoice)
    initial = []
    items = InvoiceItem.objects.filter(invoice=invoice,
                                       is_active=True).order_by('pk')
    for i in items:
        initial.append({
            'type': i.type,
            'description': i.description,
            'equivalent_guard_shift': i.equivalent_guard_shift,
            'hours': i.hours,
            'rate': i.rate,
            'amount': i.amount
        })
    DuplicateInvoiceItemFormset.extra = len(items)
    invoiceitem_formset = DuplicateInvoiceItemFormset(
        queryset=InvoiceItem.objects.none(),
        prefix='invoiceitem',
        initial=initial)
    args['formset'] = invoiceitem_formset
    args['add_types'] = ADD_INVOICE_ITEM_TYPE
    args['deduct_types'] = DEDUCT_INVOICE_ITEM_TYPE
    args['invoice'] = invoice
    args['title'] = 'Duplicate Invoice'

    if request.method == 'POST':
        total_amount = request.POST.get('total_amount')
        invoiceform = InvoiceForm(request.POST or None)
        formset = DuplicateInvoiceItemFormset(request.POST,
                                              prefix='invoiceitem')
        args['invoiceform'] = invoiceform
        args['formset'] = formset
        if not invoiceform.is_valid():
            messages.error(request, "Error duplicating invoice.")
            return render(request, 'invoice/create_invoice.html', args)
        for form in formset.forms:
            if not form.is_valid():
                messages.error(request, "Error duplicating invoice.")
                return render(request, 'invoice/create_invoice.html', args)

        invoice = invoiceform.save(commit=False)
        invoice.total_amount = total_amount
        invoice.created_by = request.user
        invoice.modified_by = request.user
        invoice.pk = None
        invoice.save()
        invoiceform.save_m2m()

        for form in formset.forms:
            if form.is_valid():
                item = form.save(commit=False)
                item.created_by = request.user
                item.modified_by = request.user
                item.invoice = invoice
                item.save()
        messages.success(request, "Invoice duplicated.")
        action.send(request.user, verb='duplicated', action_object=invoice)
        return reverse_redirect('invoice:view_invoice', [invoice.id])
    return render(request, 'invoice/create_invoice.html', args)