python - Getting Data from Database Imports not working -


i trying set script run every half house or sort jobs out priority's.

#from jobs.models import jobs #from django.db import models #from jobs.states import repairstates # jobs # models # states  job_set = jobs.objects.filter(status="invoiced") jobs in job_set:     print(jobs.status)  print("hello")  # loop through jobs not have status of "invoiced" # calculate how many days until due date / how many days past due date # check state job in , add or take away points depending on state # return points  # quote accepted = - 2 # assigned engineer = -1 # request components = 0 # order fulfilled = 1 # test + 2 # completed + 3 # dispatch + 4 # completed + 100  #do every half hour, hour. 

i have fallen @ first hurdle cant seem import table data need have tried many times using different locations doesn't seem work.

my directory this

 twm--       other files(not important)       twm--            accounts            api            component            customer            engineering            goods            jobs             personal           on.... 

now model in jobs.models have tried that,

from jobs.models import jobs  

but spits out error telling me

     c:\users\staff\documents\tsl\twm\twm>python priorityalgorithm.py   traceback (most recent call last):    file "priorityalgorithm.py", line 1, in <module>     jobs.models import jobs   file "c:\users\staff\documents\tsl\twm\twm\jobs\models.py", line 4, in     <module>     django.db import models    file "c:\python34\lib\site-packages\django\db\models\__init__.py", line 6, in <module>     django.db.models.query import q, queryset, prefetch  # noqa    file "c:\python34\lib\site-packages\django\db\models\query.py", line 16, in <module>      django.db.models import sql    file "c:\python34\lib\site-packages\django\db\models\sql\__init__.py", line 2, in <module>      django.db.models.sql.subqueries import *  # noqa    file "c:\python34\lib\site-packages\django\db\models\sql\subqueries.py", line 9, in <module>     django.db.models.sql.query import query    file "c:\python34\lib\site-packages\django\db\models\sql\query.py", line 17, in <module>      django.db.models.aggregates import count    file "c:\python34\lib\site-packages\django\db\models\aggregates.py", line 5, in <module>      django.db.models.expressions import func, star   file "c:\python34\lib\site-packages\django\db\models\expressions.py", line 7, in <module>     django.db.models import fields   file "c:\python34\lib\site-packages\django\db\models\fields\__init__.py", line 19, in <module>     django import forms    file "c:\python34\lib\site-packages\django\forms\__init__.py", line 6, in <module>     django.forms.fields import *  # noqa   file "c:\python34\lib\site-packages\django\forms\fields.py", line 21, in <module>     django.forms.utils import from_current_timezone, to_current_timezone    file "c:\python34\lib\site-packages\django\forms\utils.py", line 12, in <module>     django.utils.html import escape, format_html, format_html_join, html_safe   file "c:\python34\lib\site-packages\django\utils\html.py", line 13, in <module>     django.utils.http import rfc3986_gendelims, rfc3986_subdelims   file "c:\python34\lib\site-packages\django\utils\http.py", line 10, in <module>     email.utils import formatdate   file "c:\users\staff\documents\tsl\twm\twm\email.py", line 1, in <module>     django.core.mail import emailmultialternatives   file "c:\python34\lib\site-packages\django\core\mail\__init__.py", line 14, in <module>     django.core.mail.message import (   file "c:\python34\lib\site-packages\django\core\mail\message.py", line 8, in <module> email import ( importerror: cannot import name 'charset' 

does have idea why happening?

edit requested jobs.models edit - file working on located within twm app next jobs module

from decimal import decimal datetime import datetime, timedelta  django.db import models django.conf import settings django.contrib.contenttypes.models import contenttype django.core.urlresolvers import reverse django.core.exceptions import objectdoesnotexist  statemachine.fields import fsm_statefield twm.component.models import manufacturer twm.engineering.models import refurbkit twm.workitem.models import workitem, workitemnote, workitememail twm.jobs.states import repairstates twm.procurement.models import purchaseorderline twm.engineering.models import componentline twm.customer.models import contactemail  class job(workitem):     reference_start = 30000     sla_choices = (('standard', 'standard'), ('next day', 'next day'),)     sla = models.charfield(max_length=20,                            default='standard', choices=sla_choices)     part = models.foreignkey("jobs.part", null=true, blank=true)     serial_no = models.charfield(max_length=50)     status = fsm_statefield(machine=repairstates, default_choices_all=true)     quote_expiry = models.datetimefield(null=true, blank=true)     warranty = models.booleanfield(default=false)     prioritypoints = models.integerfield(default=0, null=false)     #    contact_emails = models.manytomanyfield('customer.contactemail')      ident = "repairs"      def __unicode__(self):         return "%s - %s" % (self.ref_number, self.customer)      def add_note(self, user, note):         return jobnote(user=user, note=note, item=self)      def add_email(self, emails, subject, message, mime_type="text/html"):         return jobemail(item=self,                         sent_to=emails,                         subject=subject,                         note=message,                         upload_mime=mime_type)      def add_customer_as_contact(self):         if self.customer , self.customer.addresses.count() > 0:             address = self.customer.addresses.all()[0]             contact, created = contactemail.objects.get_or_create(customer=self.customer,                                                                   email=address.email,                                                                   defaults={'name': address.contact_name})             self.contact_emails.add(contact)      def set_due_date(self):         if self.status.state.name == "goods_arrived":             deadlines = (1, 4)         else:             deadlines = (1, 6)          if self.sla == 'next day':             due_date = datetime.now() + timedelta(days=deadlines[0])         else:             due_date = datetime.now() + timedelta(days=deadlines[1])              #can't due on weekend! (5=saturday, 6=sunday)             add_days = 7 - due_date.weekday()             if add_days < 3:                 due_date += timedelta(days=add_days)          self.due_date = due_date      def set_quote_expiry(self):         self.quote_expiry = datetime.now() + timedelta(days=30)      def get_notes(self):         return self.notes.all()      def get_open_quote(self):         quotes = self.quote.filter(models.q(accepted__isnull=true) |                                    models.q(accepted__gt=-1)).order_by('-date')         if quotes:             return quotes[0]      def get_accepted_quote(self):         quotes = self.quote.filter(accepted__gt=0).order_by('-date')         if quotes:             return quotes[0]      def get_qa_state(self):         last_qa_state = self.state_history.filter(from_state='production_qa')         if last_qa_state:             return last_qa_state[0]      def update_value(self, save=true):         value = decimal(0)         quotes = self.quote.filter(accepted__gt=0).order_by('-date')         if quotes.count() == 0:             quotes = self.quote.all().order_by('-date')             if quotes.count() > 0:                 quote = quotes[0]                 value += quote.new_price or 0                 value += quote.used_price or 0                 value += quote.repair_price or 0                 value += quote.exchange_price or 0                 value += quote.other_price or 0                 value += quote.inbound_shipping_cost or 0                 value += quote.outbound_shipping_cost or 0         else:             quote in quotes:                 ttl = quote.get_total()                 if ttl:                     value += ttl         self.value = value          if save:             self.save(none)      def update_cost(self, save=true):         po_lines = purchaseorderline.objects.filter(             component_line_id__in=self.components_list.all().values_list('id', flat=true),             component_line_content_type=contenttype.objects.get_for_model(componentline))          price = 0          line in po_lines:             if line.discount == 0:                 if line.get_supplier_discount() > 0:                     line.discount = line.get_supplier_discount()                     line.save()              price += line.get_line_price()          self.cost = price          if save:             self.save(none)      def save(self, *args, **kwargs):         self.update_value(save=false)         self.update_cost(save=false)         super(job, self).save(*args, **kwargs)      def get_absolute_url(self):         if self.id:             if self.status.state:                 return reverse(self.status.state.name, args=[self.id])             else:                 return reverse('repair_created', args=[self.id])         else:             return reverse('repair_added')      def is_order_filled(self):         po_line_type = contenttype.objects.get_for_model(componentline)         line in self.components_list.all():             try:                 po_line = purchaseorderline.objects.get(                     component_line_content_type=po_line_type,                     component_line_id=line.id,                     purpose="repair")             except purchaseorderline.doesnotexist:                 continue              if not po_line.delivered:                 return false          return true      def split(self):         new_repair = super(job, self).split()         # blank bits don't need         new_repair.due_date = none         new_repair.order_number = none         new_repair.tracking_details = none         new_repair.tracking_link = none         #copy bits         new_repair.part = self.part         new_repair.sla = self.sla         new_repair.serial_no = self.serial_no         return new_repair   class jobnote(workitemnote):     item = models.foreignkey('jobs.job', related_name='notes')     upload = models.filefield(upload_to='job_files', null=true, blank=true)   class jobemail(workitememail):     item = models.foreignkey('jobs.job', related_name='email_notes')      def get_absolute_url(self):         return reverse('li-view-email', kwargs={'model': 'job', 'pk': self.id})      def get_raw_url(self):         return reverse('li-raw-email', kwargs={'model': 'job', 'pk': self.id}) 

seems have custom app email. try

>>>import email >>>print email.__file__ 

check email importing from.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -