def plan_read_page(request): page = html.read_plan_page page.web_language = t.get_lang_act(request) form_data = process_post(request) plans = [] try: query = Q(user_id=request.user.id) query.add(Q(is_active=1), Q.AND) # Show only active planning plans = Plan.objects.all().filter(query) except ObjectDoesNotExist: pass plans = plans[::-1] # Reverse plan order num = 1 for plan in plans: # Update plans for html page plan.num = num plan.date = str(plan.date) plan.time_start = str(plan.time_start)[:5] plan.time_end = str(plan.time_end)[:5] num += 1 # Update page values page.rows_count = len(plans) page.max_per_page = init.web_max_logs_plans_per_page page.link_act = form_data['link_act'] return {'page': page, 'form_data': form_data, 'plans': plans}
def plan_write_page(request): page = html.write_plan_page page.web_language = t.get_lang_act(request) form_data = process_post(request) return {'page': page, 'form_data': form_data}
def read_log_view(request): page = html.read_log_page page.web_language = t.get_lang_act(request) return render( request, "read-log.html", log_read_page( request ) )
def about_view(request): page = html.about_page page.web_language = t.get_lang_act(request) content = { 'page': page } return render(request, "about.html", content)
def home_view(request): page = html.home_page page.web_language = t.get_lang_act(request) content = { 'page': page } return render(request, "home.html", content)
def read_plan_view(request): page = html.read_plan_page page.web_language = t.get_lang_act(request) return render( request, "read-plan.html", plan_read_page( request ) )
def write_log_view(request): page = html.write_log_page page.web_language = t.get_lang_act(request) return render( request, "write-log.html", log_write_page( request ) )
def write_plan_view(request): page = html.write_plan_page page.web_language = t.get_lang_act( request ) page.time_hh_s = fn.get_now_hh_plus_1() page.time_hh_e = fn.get_now_hh_plus_2() return render( request, "write-plan.html", plan_write_page( request ) )
def language_page(request): page = html.lang_page if request.user.is_authenticated: if request.method == 'GET': lang = request.GET.get('lang') if lang.upper() in ['NL', 'EN']: init.web_language = lang.upper() # Update database set = Settings.objects.get(user_id_id=request.user.id) set.language = init.web_language set.save() page.web_language = t.get_lang_act(request) return {'page': page}
def notes_page(request): page = html.notes_page page.web_language = t.get_lang_act(request) post, succes, err, succes_text = False, False, err_h.Error(False, []), '' form_data = {'title': '', 'err_title': err, 'text': '', 'date_set': ''} if request.method == 'POST': # Check if something is posted post = True if request.POST.get( 'save_note' ) == 'save_note': # Check if the save note button is used title, err_title = err_h.check_string_base( err_h.Error(False, []), request.POST.get('inputTitle'), 'Title') form_data = { 'title': title, 'err_title': err_title, 'text': request.POST.get('inputText'), 'date_set': request.POST.get('inputDateSet') } # Check for errors if (err_title.found): succes = False else: succes = True succes_text = 'Notitie succesvol toegevoegd' note = Note() note.title = form_data['title'] note.text = form_data['text'] note.date = form_data['date_set'] note.user_id = request.user.id note.is_active = 1 note.save() # Save in DB elif request.POST.get('delete_note') == 'delete_note': succes = True note_id = request.POST.get('note_id') query = Q(user_id=request.user.id) query.add(Q(id=note_id), Q.AND) query.add(Q(is_active=1), Q.AND) Note.objects.all().filter(query).update(is_active=0) succes_text = 'Notitie succesvol verwijderd' # Read all data from database query = Q(user_id=request.user.id) query.add(Q(is_active=1), Q.AND) notes = Note.objects.all().filter(query) notes = notes[::-1] # Reverse log order # Add nums id's for pagination num = 1 for note in notes: note.num = num num += 1 page.rows_count = len(notes) page.max_per_page = init.web_max_notes_per_page return { 'page': page, 'notes': notes, 'succes': succes, 'succes_txt': succes_text, 'form_data': form_data }
def login_page(request): page = html.login_page page.web_language = t.get_lang_act(request) post, succes, err = False, False, err_h.Error(False, []) form_data = { 'email': '', 'password': '', 'err_email': err, 'err_password': err, 'email_class': '', 'password_class': '', } if request.method == 'POST': # Check if something is posted if request.POST.get( 'login') == 'login': # check if the register button is used # Get post vars email = request.POST.get('inputEmail') password = request.POST.get('inputPassword') # Error checking email, err_email = err_h.check_email(err_h.Error(False, []), email, 'email') password, err_password = err_h.check_password( err_h.Error(False, []), password, 'password') # Update form data form_data = { 'email': email, 'password': password, 'err_email': err_email, 'err_password': err_password, 'email_class': ' is-invalid' if err_email.found else ' is-valid', 'password_class': ' is-invalid' if err_password.found else ' is-valid', } # Check for errors if (err_password.found or err_email.found): succes = False else: succes = True username = User.objects.get(email=email.lower()).username user = authenticate(request, username=username, password=password) if user is not None: login(request, user) else: pass return { 'page': page, 'post': post, 'succes': succes, 'form_data': form_data }