def get_article_by_barcode(req, barcode): bc = barcode.strip() bc = h.extract_barcode(bc) try: article = Article.objects.select_related().get(barcode=bc) except Article.DoesNotExist: article = None if article is not None: orders = Order.objects.select_related().filter( state=u'ordered', article=article).order_by('ordered') if orders: for o in orders: o.delivered = 0 for d in DeliveredOrder.objects.filter(order=o): o.delivered += d.count ctx = dict(orders=orders, article=article, olen=len(orders)) return render(req, 'orders/delivery/known_bc.html', ctx) else: ctx = dict(article=article) return render(req, 'orders/delivery/error.html', ctx) else: articles = Article.objects.filter( order__state=u'ordered', barcode=u'').order_by('name') ctx = dict(articles=articles, barcode=bc) return render(req, 'orders/delivery/new_bc.html', ctx)
def internal_phonelist(req): profiles = UserProfile.objects.select_related().filter( external=False ).exclude(user__username='******').order_by('user__last_name') ctx = dict(page_title=_(u'Internal Phonelist'), menus=menus, profiles=profiles, dt=True) return render(req, 'colleagues/phonelist.html', ctx)
def generate_pdf(req): oday_id = int(req.POST.get('oday_id')) header = req.POST.get('header', u'') oday = OrderDay.objects.get(id=oday_id) orders = get_orders(oday) supplier = [] for s in [x[0].article.supplier for x in orders]: s.ocount = 0 s.osum = Decimal() for o in Order.objects.filter(article__supplier=s, order_day=oday, state__in=[u'accepted', u'ordered']): s.ocount += 1 s.osum += o.price() supplier.append(s) supplier_ids = [x[0].article.supplier.id for x in orders] req.session['extra_orders'] = [] req.session['oday_id'] = None printouts = Printout.objects.filter(order_day=oday) ctx = dict(page_title=_(u'PDF-Printouts'), menus=menus, oday=oday, subtitle=u'für {0}'.format(unicode(oday)), need_ajax=True, ids=supplier_ids, supplier=supplier, header=header, printouts=printouts) return render(req, 'orders/printouts.html', ctx, app=u'orders')
def edit_student(req, sid): s = Student.objects.get(id=int(sid)) initial = dict(cabinet=s.cabinet, key=s.key, exam_1=s.exam_1, exam_2=s.exam_2, finished=s.finished) form = StudentEditForm(initial=initial) ctx = dict(student=s, form=form) return render(req, 'students/edit_short.html', ctx)
def list_all_companies(req, only_with_students=False): q = Company.objects.select_related().all( ).exclude(**settings.EXCLUDE_FROM_COMPANY_LIST).order_by('name') if only_with_students: company_list = [x for x in q if x.has_students()] title = u'Firmen mit Azubis ({n})' else: company_list = list(q) title = u'Firmen ({n})' paginator = Paginator(company_list, 15) try: page = int(req.GET.get('page', '1')) except ValueError: page = 1 try: companies = paginator.page(page) except (EmptyPage, InvalidPage): companies = paginator.page(paginator.num_pages) ctx = dict( page_title=title.format(n=len(company_list)), companies=companies, menus=menus, only_with_students=only_with_students, single_view=False, page=page, start=(page - 1) * 15 + 1 ) return render(req, 'companies/list_all.html', ctx)
def presence_overview(req): d = date.today() month = d.month year = d.year last_month = month - 1 if month > 1 else 12 lyear = year if last_month != 12 else year - 1 q = Q(date__month=month) & Q(date__year=year) q |= Q(date__month=last_month) & Q(date__year=lyear) q2 = Q(entry__isnull=True) | Q(entry__exact=u'') jobs = StudentGroup.objects.values_list('job', flat=True) jobs = list(set(jobs)) jobs.sort() groups = [] for j in jobs: gr = StudentGroup.objects.select_related().filter(job=j).order_by( 'start_date') gr = [x for x in gr if not x.finished()] for g in gr: g.pdfs = g.presence_printouts.filter(q).order_by('-date') g.pdays = PresenceDay.objects.filter( student__group=g, date__month=last_month, date__year=lyear ).exclude(q2).count() groups.append((j, gr)) ctx = dict(page_title=_(u'Presence Overview'), groups=groups, menus=menus, month=last_month, jobs=jobs, dp=True, dt=True) return render(req, 'presence/overview.html', ctx)
def list_companies(req, startchar=''): if req.method == 'POST': form = SearchForm(req.POST) if form.is_valid(): s = form.cleaned_data['search'] companies = Company.objects.select_related().filter( Q(name__icontains=s) | Q(short_name__icontains=s)) else: companies = Company.objects.none() messages.error(req, u'Ungültige Suche.') else: form = SearchForm() if not startchar: companies = Company.objects.select_related().all() for c in string.ascii_uppercase: companies = companies.exclude(name__istartswith=c) else: companies = Company.objects.select_related().filter( name__istartswith=startchar) companies = companies.exclude(**settings.EXCLUDE_FROM_COMPANY_LIST) ptitle = u'Firmen: {0} ({1})'.format( startchar or '-', companies.count() ) ctx = dict( page_title=ptitle, companies=companies, menus=menus, chars=string.ascii_uppercase, form=form, single_view=False ) return render(req, 'companies/list.html', ctx)
def index(req): drafts = OperatingInstructionDraft.objects.select_related().filter( released__isnull=True).order_by('-edited') released = OperatingInstructionDraft.objects.select_related().filter( released__isnull=False).order_by('-edited') ctx = dict(drafts=drafts, released=released, menu=oic_menu) return render(req, 'oic/index.html', ctx)
def accident_add(req): form = AccidentForm() form.fields['student'].queryset = Student.objects.filter( finished=False).order_by('lastname') form.fields['employee'].queryset = User.objects.exclude( username='******').order_by('last_name') return render(req, 'accidents/add.html', {'form': form})
def edit_map(req, floor_id): floor = Floor.objects.select_related().get(pk=int(floor_id)) ctx = dict(title=_('Edit Map'), floor=floor, building=floor.building, storages=_get_json_storages(floor)) return render(req, 'floor_map/edit_map.html', ctx)
def add_supplier(req): if req.method == 'POST': form = ShortSupplierForm(req.POST) if form.is_valid(): cd = form.cleaned_data c, created = Company.objects.get_or_create(name=cd['name']) if not created: messages.error(req, u'Lieferant %s existiert bereits.' % c.name) return redirect('orders-index') c.customer_number = cd['customer_number'] c.phone = cd['phone'] c.fax = cd['fax'] c.email = cd['email'] c.web = cd['web'] c.rating_users.add(req.user) c.save() messages.success(req, u'Neuer Lieferant %s gespeichert.' % c.name) messages.success(req, u'Sie wurden als Bewerter für diesen ' u'Lieferanten eingetragen.') return redirect('orders-index') messages.error(req, u'Bitte korrigieren Sie die falschen Felder.') else: form = ShortSupplierForm(initial={'web': 'http://'}) ctx = dict(page_title=_(u'Add new Supplier'), menus=menus, form=form, need_ajax=True) return render(req, 'orders/new_supplier.html', ctx, app=u'orders')
def index(req, days=30): orders = [] for o in Order.objects.select_related().filter( state=u'ordered').order_by('-ordered', 'article__name'): o.dsum = 0 for d in DeliveredOrder.objects.filter(order=o): o.dsum += d.count o.missing = o.count - o.dsum o.userlist = [x.username for x in o.users.all()] orders.append(o) tmp = set() last = date.today() - timedelta(days=int(days)) for d in DeliveredOrder.objects.select_related().filter( order__state=u'delivered', date__gte=last): if d.order.is_complete(): tmp.add(d.order.id) dorders = [] for o in Order.objects.select_related().filter( id__in=list(tmp)).order_by('-ordered', 'article__name'): avg_days = 0 counter = 0 for d in DeliveredOrder.objects.filter(order=o): dt = d.date - o.ordered avg_days += dt.days counter += 1 o.avg_days = avg_days / float(counter) o.userlist = [x.username for x in o.users.all()] dorders.append(o) ctx = dict(page_title=_(u'Delivery'), menus=menus, orders=orders, dorders=dorders, dt=True, need_ajax=True, days=days) return render(req, 'orders/delivery/index.html', ctx, app=u'orders')
def add_oday(req): if req.method == 'POST': form = OrderDayForm(req.POST) form.fields['user'].choices = h.get_user_choices() if form.is_valid(): if form.cleaned_data['user'].is_anonymous(): messages.error(req, u'Der Benutzer ist nicht gültig.') return redirect('orders-manage') oday = OrderDay.objects.create( day=form.cleaned_data['day'], user=form.cleaned_data['user'], accepted=False ) oday.save() messages.success( req, u'Neuer Bestelltag %s hinzugefügt.' % unicode(oday) ) return redirect('orders-add-oday') else: messages.error(req, u'Bitte korrigieren Sie das Formular.') else: form = OrderDayForm() form.fields['user'].choices = h.get_user_choices() odays = h.get_next_odays(True) ctx = dict(page_title=_(u'Add new orderday'), menus=menus, form=form, odays=[unicode(x) for x in odays], dp=True) return render(req, 'orders/add_oday.html', ctx, app=u'orders')
def do_login(req): if req.method == 'POST': next_page = req.POST.get('next', '/') form = AuthenticationForm(req, req.POST) if form.is_valid(): user = authenticate( username=form.cleaned_data['username'].lower(), password=form.cleaned_data['password'] ) if user is not None: p = user.userprofile if user.is_active and p.can_login: login(req, user) if user.is_superuser: count = utils.remove_old_sessions() messages.success( req, u'{0} alte Sitzungen gelöscht'.format(count) ) messages.success(req, u'Login akzeptiert.') return redirect(next_page) else: messages.error(req, u'Account ist deaktiviert.') else: messages.error(req, u'Benutzer und/oder Passwort falsch.') else: next_page = req.GET.get('next', '/') form = AuthenticationForm() req.session.set_test_cookie() ctx = dict(page_title=_(u'Login Page'), form=form, next_page=next_page) return render(req, 'login.html', ctx)
def order_detail(req, order_id): oid = int(order_id) oday = OrderDay.objects.get(id=oid) orders = Order.objects.select_related().filter( order_day=oday).order_by('-added', 'article__name') order_sum = 0 for o in orders: o.userlist = [x.username for x in o.users.all()] o.costlist = [u'%s: %d%%' % (unicode(x.cost), x.percent) for x in CostOrder.objects.filter(order=o)] order_sum += o.fullprice() o.netto = o.count * o.article.get_price() if ( req.user.username in o.userlist and o.users.count() == 1 and o.state in (u'new', u'accepted', u'rejected') ): o.deleteable = True else: o.deleteable = False ctx = dict( page_title=u'Offene Bestellungen', menus=menus, oday=oday, orders=orders, order_sum=order_sum, subtitle=unicode(oday), dt=True, need_ajax=True ) return render(req, 'orders/orderday.html', ctx, app=u'orders')
def delete_group(req, gid): group = StudentGroup.objects.select_related().get(id=int(gid)) gname = unicode(group) if req.method == 'POST': group.presence_printouts.all().delete() deleted = [] for stud in group.students.all(): try: _id = stud.id name, count = h.delete_one_student(_id, True) deleted.append(_id) except Exception as e: messages.error( req, u'Beim Löschen eines Teilnehmers ist ein Fehler ' u'aufgetreten: {0}'.format(e) ) try: group.delete() req.session['group_name'] = gname req.session['deleted'] = deleted return redirect('core-group-delete-success') except Exception as e: messages.error( req, u'Beim Löschen der Gruppe ist ein Fehler' u'aufgetreten: {0}'.format(e) ) ctx = dict(page_title=u'Gruppe löschen', group=group, menus=menus, subtitle=gname) return render(req, 'students/delete_group.html', ctx)
def mypresence(req): if req.method == 'POST': start = req.POST['start'] or None end = req.POST['end'] or None else: start = end = None _d = date.today() d = _d - timedelta(days=7) start = utils.get_date(start, d) end = utils.get_date(end, _d) if start > end: messages.error(req, u'Das Enddatum liegt vor dem Startdatum!') return redirect('core-presence') req.session['presence_start'] = start.strftime('%Y-%m-%d') req.session['presence_end'] = end.strftime('%Y-%m-%d') dt = end - start _studs = h.get_students(req.user) _students = h.sort_students_for_presence(_studs) students = h.get_presence(_students, start, end) days = (start + timedelta(days=x) for x in xrange(dt.days + 1)) ctx = dict( page_title=_(u'My Presence'), students=students, menus=menus, start=start, end=end, days=[x for x in days if x.weekday() not in (5, 6)], choices=[x[0] for x in PRESENCE_CHOICES], legend=PRESENCE_CHOICES[1:], today=date.today(), dt=True, need_ajax=True ) return render(req, 'presence/group.html', ctx)
def get_next_birthdays(req): days = int(req.GET.get('days', '14')) choice = [7, 14, 30, 90, 180] start = date.today() today = (start.month, start.day) start = start - timedelta(days=10) dates = [start + timedelta(days=x) for x in xrange(days)] users = [] students = [] for d in dates: for p in UserProfile.objects.select_related( ).filter(birthdate__month=d.month, birthdate__day=d.day): p.bsclass = utils.get_birthday_color( (p.birthdate.month, p.birthdate.day), today) p.bdate = d users.append(p) for s in Student.objects.select_related( ).filter(birthdate__month=d.month, birthdate__day=d.day): s.bsclass = utils.get_birthday_color( (s.birthdate.month, s.birthdate.day), today) s.bdate = d students.append(s) ctx = dict( page_title=_(u'Birthdays, next {0} days'.format(days)), menus=menus, users=users, students=students, choice=choice, days=days, today=start ) return render(req, 'colleagues/birthdays.html', ctx)
def order(req, article_id=0): if req.user.has_perm('orders.can_order'): choice_filter = {'day__gte': date.today() - timedelta(days=1)} else: choice_filter = {'day__gt': date.today()} if req.method == 'POST': form = OrderForm(req.POST) form.fields['oday'].choices = h.get_oday_choices(choice_filter) if form.is_valid(): cleaned = form.cleaned_data company = Company.objects.get(id=cleaned['art_supplier_id']) costs = h.get_costs(req.POST) art, created = h.search_article( cleaned['art_id'].strip(), cleaned['art_name'], cleaned['art_q'], company ) art.tax = int(req.POST.get('tax', '19')) if created: art.tox_control = cleaned['tox'] art.save() _price = h.get_price(cleaned['art_price']) if _price and art.price != _price: art.price = _price art.save() order = Order.objects.create( count=cleaned['count'], article=art, order_day=OrderDay.objects.get(id=int(cleaned['oday'])) ) order.save() for cost, percent in costs: co = CostOrder.objects.create(percent=percent, order=order, cost=cost) co.save() order.memo = cleaned['memo'] order.for_test = cleaned['exam'] order.for_repair = cleaned['repair'] order.users.add(req.user) order.save() # Add orderer to rating_users if req.user.id not in [x.id for x in company.rating_users.all()]: company.rating_users.add(req.user) company.save() messages.success(req, u'Sie wurden als Bewerter für %s ' u'hinzugefügt.' % company.name) messages.success(req, u'Ihre Bestellung %s wurde gespeichert.' % order) return redirect('orders-detail', order_id=order.order_day.id) messages.error(req, u'Bitte füllen Sie die benötigten Felder aus.') else: form = OrderForm() form.fields['oday'].choices = h.get_oday_choices(choice_filter) costs = Cost.objects.all().order_by('ident') ctx = dict( page_title=_(u'New Order'), form=form, menus=menus, costs=costs, article_id=article_id, costs_msg=_(u'Sum of costs must be 100!'), cur_msg=u'Preis in %s.' % settings.CURRENCY[0], extra=False, need_ajax=True ) return render(req, 'orders/order.html', ctx, app=u'orders')
def mystudents(req): profile = req.user.userprofile config = profile.config() pgroups = config.get('pgroups', []) students = Student.objects.select_related().filter( group__id__in=pgroups, finished=False).order_by( 'group__job_short', 'lastname') return render(req, 'presence/studentlist.html', {'students': students})
def compare(req, pid, chem_id): parsed = ParsedData.objects.select_related().get(pk=pid) chem = Chemical.objects.select_related().get(pk=chem_id) req.session['new'] = False req.session['chem_id'] = chem.id data = utils.get_data(chem, parsed) ctx = dict(title=_('Comparison'), chem=chem, parsed=parsed, data=data) return render(req, 'msds/transfer/compare.html', ctx)
def presence_for_student_overview(req, student_id): student = Student.objects.select_related().get(id=int(student_id)) student = h.get_presence_details(student) q = Q(entry__in=[u'T', u'F', u'K', u'|', u'U']) | Q(lateness__gt=0) days = student.presence_days.select_related().filter(q).order_by('date') ctx = dict(page_title=u'Anwesenheitsübersicht', subtitle=unicode(student), menus=menus, student=student, days=days, dt=True) return render(req, 'students/presence_overview.html', ctx)
def student_added(req, student_id): s = Student.objects.select_related().get(id=int(student_id)) ctx = dict(page_title=_(u'New student added'), s=s, menus=menus, subtitle=u'{last}, {first}'.format(last=s.lastname, first=s.firstname)) return render(req, 'students/add/success.html', ctx)
def presence_printouts(req, job): groups = StudentGroup.objects.select_related().filter( job=job).order_by('-start_date', 'job_short') jobs = StudentGroup.objects.values_list('job', flat=True) jobs = list(set(jobs)) jobs.sort() ctx = dict(page_title=u'Anwesenheiten {0}'.format(job), menus=menus, jobs=jobs, groups=groups) return render(req, 'presence/list_printouts.html', ctx)
def export_to_csv(req): if req.method == 'POST': ids = map(int, req.POST.getlist('export')) return _export(ids) to_export = DeliveredOrder.objects.select_related().filter( exported=False, order__article__tox_control=True).order_by('date') ctx = dict(page_title=u'Toxolution Export', menus=menus, to_export=to_export, subtitle=u'Gelieferte Bestellungen') return render(req, 'orders/delivery/csv_export.html', ctx, app=u'orders')
def ask_order(req): if req.method == 'POST': article_id = req.POST.get('article_id') if article_id: return redirect('orders-order', article_id) else: messages.error(req, u'Kein Artikel ausgewählt.') ctx = dict(page_title=_(u'Make order'), menus=menus) return render(req, 'orders/select_article.html', ctx, app=u'orders')
def transfer(req, uid): up = UploadedMSDS.objects.select_related().get(pk=uid) parsed = up.parsed.first() exact, similar = utils.find_similar(parsed) ctx = dict(title=_('Transfer to DB'), parsed=parsed, exact=exact, similar=similar) return render(req, 'msds/transfer/similar.html', ctx)
def list_colleagues(req): internal = UserProfile.objects.select_related().filter( external=False ).exclude(user__username='******').order_by('user__last_name') external = UserProfile.objects.select_related().filter( external=True ).exclude(user__username='******').order_by('user__last_name') ctx = dict(page_title=_(u'Colleagues'), menus=menus, internal=internal, external=external) return render(req, 'colleagues/list.html', ctx)
def edit_profile(req): profile = req.user.userprofile if req.method == 'POST': form = ProfileForm(req.POST, instance=profile) form.save() messages.success(req, u'Alle Änderungen gespeichert.') else: form = ProfileForm(instance=profile) ctx = dict(page_title=_(u'My Profile'), menus=menus, form=form, dp=True) return render(req, 'colleagues/profile.html', ctx)
def show_old_orders(req): orders = h.get_order_for_every_article() try: first = Order.objects.all().order_by('added')[0] dt = first.added.strftime(settings.DEFAULT_DATE_FORMAT) except: # noqa: E722 dt = u'' ctx = dict(page_title=_(u'All ordered articles'), menus=menus, orders=orders, dt=True, subtitle=u'Seit {0}'.format(dt)) return render(req, 'orders/old_orders.html', ctx, app=u'orders')
def contact(request, template='contact.html'): context = {} return render(request, template, context)
def home(request, template='home.html'): context = { 'login_form': AuthenticationForm(), 'register_form': UserCreationForm(), } return render(request, template, context)