On Sep 8, 3:26 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Sep 8, 9:16 pm, KillaBee <[EMAIL PROTECTED]>
> wrote:
>
> > I keep getting this error on this view named timesheets, the code
> > looks like this.
>
> <snip tons of irrelevant code>
>
>
>
> > ViewDoesNotExist: Could not import intraweb.apps.timesheets.views.
> > Error was: cannot import name entrys
>
> The traceback quite clearly states that the error is in
> timesheets.views, but you've just given us timesheets.models. In your
> views.py you're obviously doing something like from
> intraweb.apps.timesheets.models import entrys, but there's no such
> model - there is only one called Entry. So import that instead.
> --
> DR.
yes I am doing that , but how do you do just import the entry and
JobPosition?

=========================================================================================
from django.contrib.auth.decorators import user_passes_test
from django.http import HttpResponse, HttpResponseRedirect
from django.template import Context, loader
from django.shortcuts import get_object_or_404, render_to_response
from datetime import date
from django.http import Http404
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
#from interweb.apps import timesheets
from django.contrib.auth.models import User
from django.oldforms import FormField
from django.contrib import admin

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++
from django.template import Context
# needs meta
from intraweb.apps.timesheets.models.timesheets import entrys
from intraweb.apps.timesheets.models.timesheets import jobpositions
from intraweb.apps.timesheets.models.timesheets import Timesheet
#======================================================================================


def index(request, year=date.today().year, username=""):
    if request.user.is_anonymous(): return  HttpResponseRedirect('/app/
accounts/login/?next=%s' % request.path)
    if request.user.username != username and not
request.user.has_perm('timesheets.admin'):
        return HttpResponse("Permission denied for user(%s)" %
username)
    if request.user.get_timesheets_jobposition().address1=='':
       return create_update_address(request, request.user.username)

    t = loader.get_template('timesheets/year_index')
    c = Context( { 'year': year, 'user': request.user,   } )
    return HttpResponse(t.render(c))

def detail_user(request, username):
    if request.user.is_anonymous(): return  HttpResponseRedirect('/app/
accounts/login/?next=%s' % request.path)
    if request.user.username != username and not
request.user.has_perm('timesheets.admin'):
        return HttpResponse("Permission denied")
    u = users.get_object(username__exact = username)
    t = loader.get_template('timesheets/usersummary')
    c = Context({ 'user': u},)
    return HttpResponse(t.render(c))

def detail_year(request, username, year):
    if request.user.is_anonymous(): return  HttpResponseRedirect('/app/
accounts/login/?next=%s' % request.path)
    if request.user.username != username and not
request.user.has_perm('timesheets.admin'):
        return HttpResponse("Permission denied")
    return HttpResponse("Hello, %s. You're at the timesheet detail for
%s." % (username, year))

def timesheet_print(request, username, year, month, period):
    if request.user.is_anonymous(): return  HttpResponseRedirect('/app/
accounts/login/?next=%s' % request.path)
    if request.user.username != username and not
request.user.has_perm('timesheets.admin'):
        return HttpResponse("Permission denied")

    u = get_object_or_404(users, username__exact=username)
    if period == 'p1':   day = 1
    else:  day=16
    d = date(int(year),int(month),int(day))
    ts = Timesheet(username, d)

    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment;
filename=somefilename.pdf'

    # Create the PDF object, using the response object as its "file."
    p = canvas.Canvas(response, pagesize=letter)
    p.setFont('Helvetica', 18)

    # Draw things on the PDF. Here's where the PDF generation happens.
    # See the ReportLab documentation for the full list of
functionality.
    p.drawString(100, letter[1]-50, "Iowa Democratic Party
Timesheet.")
    p.drawString(100, letter[1]-75, ts.__repr__())

    h = 150
    p.setFont('Helvetica', 12)
    for e in ts.get_all_entrys():
      if e.worked: s = '%s:\t\t %d%% Federal Activities' %
(e.date.strftime("%x"),e.time)
      else: s = '%s:\t\t Did not work' % (e.date.strftime("%x"))
      p.drawString(100, letter[1]-h, s)
      h = h + 18

    p.setFont('Helvetica', 14)
    p.line(100, letter[1]-h, 100+2.5*inch, letter[1]-h)
    h = h + 20
    p.drawString(100, letter[1]-h, 'Total Federal Time: %d%%' %
(ts.gettime()))


    p.line(100, 150, 100+3.5*inch, 150)
    p.line(100+4*inch, 150, 100+5.5*inch, 150)
    p.drawString(105, 130, 'Signature')
    p.drawString(105+4*inch, 130, 'Date')

    # Close the PDF object cleanly, and we're done.
    p.showPage()
    p.save()
    return response



def detail_timesheet(request, username, year, month, period):
    if request.user.is_anonymous(): return  HttpResponseRedirect('/app/
accounts/login/?next=%s' % request.path)
    if request.user.username != username and not
request.user.has_perm('timesheets.admin'):
        return HttpResponse("Permission denied")

    u = get_object_or_404(users, username__exact=username)

    if period == 'p1':
      day = 1
    else:
      day=16
    d = date(int(year),int(month),int(day))

    ts = Timesheet(username, d)
    try:
      jp = ts.get_user().get_timesheets_jobposition()
    except jobpositions.JobPositionDoesNotExist:
      jp = None


    t = loader.get_template('timesheets/timesheet')
    c = Context({'timesheet': ts,'path':request.path,'jobposition':
jp})
    return HttpResponse(t.render(c))


def create_update_entry(request, username, year, month, day):
    if request.user.is_anonymous(): return  HttpResponseRedirect('/app/
accounts/login/?next=%s' % request.path)
    if request.user.username != username and not
request.user.has_perm('timesheets.admin'):
        return HttpResponse("Permission denied")

    u = get_object_or_404(users, username__exact=username)
    d = date(int(year),int(month),int(day))
    e = None
    try:
         e = entrys.get_object(user__username__exact=username,
date__exact = d)
         man = entrys.ChangeManipulator(e.id)
         title = "Change"
    except(entrys.EntryDoesNotExist):
         man = entrys.AddManipulator()
         title = "Add"

    if d.day <= 15:
          timesheet_url = "/app/timesheets/%s/%s/%s/p1/" %
(u.username, year, month)
    else:
          timesheet_url = "/app/timesheets/%s/%s/%s/p2/" %
(u.username, year, month)


    if request.POST:
      # if data was POSTed, we're trying to create a new entry
      new_data = request.POST.copy()

      new_data["user"]=u.id
      new_data["date"]="%s" % d


      # validate
      errors = man.get_validation_errors(new_data)

      if not errors:
        man.do_html2python(new_data)
        new_entry = man.save(new_data)
        return HttpResponseRedirect(timesheet_url)

    else:  # No POST, so new form with no data or errors
      if e: new_data = e.__dict__
      else: new_data = {'worked':True, 'time':0}
      errors = {}


    form = formfields.FormWrapper(man, new_data, errors)
    return render_to_response('timesheets/edit_entry_form', {'form':
form, 'date': d, 'errors':errors, 'title':title, 'data':new_data,
 
'ts_url':timesheet_url,})


def create_update_address(request, username):
    if request.user.is_anonymous(): return  HttpResponseRedirect('/app/
accounts/login/?next=%s' % request.path)
    if request.user.username != username and not
request.user.has_perm('timesheets.admin'):
        return HttpResponse("Permission denied")

    u = get_object_or_404(users, username__exact=username)
    j = None

    from django.models.timesheets import jobpositions
    try:
         j = u.get_timesheets_jobposition()
         man = jobpositions.ChangeManipulator(j.user_id)
         title = "Change"
    except(jobpositions.JobPositionDoesNotExist):
         man = jobpositions.AddManipulator()
         title = "Add"

    timesheet_url = "/app/timesheets/%s/" % (u.username)

    if request.POST:
      # if data was POSTed, we're trying to create a new entry
      new_data = request.POST.copy()

      new_data["user_id"]=str(u.id)
      if j: new_data["position"]=j.position
      else: new_data["position"] = "none"

      # validate
      errors = man.get_validation_errors(new_data)

      if not errors:
        man.do_html2python(new_data)
        new_data["user"] = u.id
        new_entry = man.save(new_data)
        return HttpResponseRedirect(timesheet_url)

    else:  # No POST, so new form with no data or errors
      if j: new_data = j.__dict__
      else: new_data = {"position":"None", "user_id": str(u.id)}
      errors={}


    form = formfields.FormWrapper(man, new_data, errors)
    return render_to_response('timesheets/edit_address_form', {'form':
form, 'errors':errors, 'title':title, 'data':new_data,
 
'ts_url':timesheet_url,})




def logout(request, next_page=None):
    "Logs out the user and redirects to login."
    try:
        del request.session[users.SESSION_KEY]
    except KeyError:
        return HttpResponseRedirect('/app/accounts/login/?next=/app/
timesheets')
    else:
        # Redirect to this page until the session has been cleared.
        return HttpResponseRedirect(next_page or request.path)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to