This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.template.defaultfilters import slugify | |
from django.utils import timezone | |
from uuid import uuid4 | |
from django.contrib.auth.models import User | |
class Client(models.Model): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from django.contrib.auth.models import User | |
from django.forms import widgets | |
from .models import * | |
import json | |
class UserLoginForm(forms.ModelForm): | |
username = forms.CharField( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.decorators import user_passes_test | |
#Anonymous required | |
def anonymous_required(function=None, redirect_url=None): | |
if not redirect_url: | |
redirect_url = 'dashboard' | |
actual_decorator = user_passes_test( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@login_required | |
def clients(request): | |
context = {} | |
clients = Client.objects.all() | |
context['clients'] = clients | |
if request.method == 'GET': | |
form = ClientForm() | |
context['form'] = form | |
return render(request, 'invoice/clients.html', context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@login_required | |
def createInvoice(request): | |
#create a blank invoice .... | |
number = 'INV-'+str(uuid4()).split('-')[1] | |
newInvoice = Invoice.objects.create(number=number) | |
newInvoice.save() | |
inv = Invoice.objects.get(number=number) | |
return redirect('create-build-invoice', slug=inv.slug) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@login_required | |
def createBuildInvoice(request, slug): | |
#fetch that invoice | |
try: | |
invoice = Invoice.objects.get(slug=slug) | |
pass | |
except: | |
messages.error(request, 'Something went wrong') | |
return redirect('invoices') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from django.forms import widgets | |
from .models import * | |
#Form Layout from Crispy Forms | |
from crispy_forms.helper import FormHelper | |
from crispy_forms.layout import Layout, Submit, Row, Column | |
class DateInput(forms.DateInput): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Dont forget the view imports | |
def emailDocumentInvoice(request, slug): | |
#fetch that invoice | |
try: | |
invoice = Invoice.objects.get(slug=slug) | |
pass | |
except: | |
messages.error(request, 'Something went wrong') | |
return redirect('invoices') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.template.defaultfilters import slugify | |
from django_resized import ResizedImageField | |
from django.utils import timezone | |
from uuid import uuid4 | |
from django.urls import reverse | |
class Category(models.Model): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def categoryPage(request, slug): | |
category = Category.objects.get(slug=slug) | |
images = Image.objects.filter(category=category).order_by('-date_created')[:6] | |
for x in images: | |
x.shortDescription = x.description[:130] | |
context = {} | |
context['images'] = images | |
context['category'] = category |
OlderNewer