Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from SetManu/feature-hide-authentification
Browse files Browse the repository at this point in the history
UserDefinedForm created
  • Loading branch information
Manuel Werder committed Oct 10, 2019
2 parents 06c2aa5 + 76b7d3f commit b617a89
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 31 deletions.
12 changes: 2 additions & 10 deletions .idea/dataSources.local.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion cronjob/forms/cronjob/cronjobforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TitleForm(forms.Form):


class AuthenticateForm(forms.Form):
box = forms.BooleanField(required=False)
box = forms.BooleanField(required=False, label='Needs Authentication', label_suffix=' ')
username = forms.CharField(max_length=30, required=False,
label_suffix=' ', label='Username')
password = forms.CharField(max_length=20, widget=forms.PasswordInput,
Expand All @@ -30,6 +30,11 @@ class DaysFrom(forms.Form):
every_minute_day = forms.IntegerField(min_value=0, max_value=59, initial=0, label_suffix=' ', required=False)


class UserDefinedTimeForm(forms.Form):
user_defined = forms.CharField(min_length=9, max_length=20, initial='* * * * *',
label='User defined', label_suffix=' ')


class UserMessageForm(forms.Form):
failed_job = forms.BooleanField(required=False, label_suffix=' ')
successful_job = forms.BooleanField(required=False, label_suffix=' ')
Expand Down
3 changes: 3 additions & 0 deletions cronjob/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ class CronJob(models.Model):
automatic_job_stopper_when_to_many_failures = models.BooleanField()

will_save_message = models.BooleanField()

def __str__(self):
return 'Cron Job - Username: {0}, Cron job title: {1}'.format(self.user.username, self.title)
Empty file.
8 changes: 8 additions & 0 deletions cronjob/static/scripts/hide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function displayHidden() {
if (getComputedStyle(document.getElementById("optionalLogin"), null).display == "none"){
document.getElementById("optionalLogin").style.display = "block";
}
else{
document.getElementById("optionalLogin").style.display = "none";
}
}
40 changes: 28 additions & 12 deletions cronjob/templates/cronjob/cronjob.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@

<section>
<h2>Title, Address</h2>
{{ title }}
{% for tag in title %}
{{ tag.label_tag }}
{{ tag }}
<br>
{% endfor %}
</section>

<section>
{# TODO: Make it so that if not set, no input possible #}
<div><h2>{{ authenticate.box }} Needs HTTP-Authentication</h2></div>
<div>
{{ authenticate.username.label_tag }}
{{ authenticate.username }}
</div>
<br>
<div>
{{ authenticate.password.label_tag }}
{{ authenticate.password }}
</div>

{# <label>Authentication needed?#}
{# <input name="Auth" type="checkbox" value="True" onclick="displayHidden()"/>#}
{# <span class="checkmark"></span>#}
{# </label>#}
{#$(document).ready(function() {#}
{# $(".my_form input[type=checkbox]").change(function() {#}
{# //Some code here#}
{# });#}
{# }); #}

{% for form in authenticate %}
{% ifequal form.id_for_label 'id_box' %}
<h2>{{ form }} {{ form.label_tag }}</h2>
{% else %}
{{ form.label_tag }}
{{ form }}<br>
{% endifequal %}
{% endfor %}

</section>

<section>
Expand All @@ -41,7 +55,8 @@ <h2>Time to run</h2>
</label>
<br>
<label>
<input type="radio" name="id_times" value="user_defined" required> User defined
<input type="radio" name="id_times" value="user_defined" required>
{{ user_defined }}
</label>
</section>

Expand Down Expand Up @@ -77,6 +92,7 @@ <h2>General</h2>
<input name="input" type="submit" value="Make Cron-Job">

</section>
<br><a href="{% url 'cronjob:home' %}">Quit create Job</a>
</form>

{% include 'partials/lowerbody.html' %}
3 changes: 3 additions & 0 deletions cronjob/templates/partials/upperbody.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
{% load static %}
<link rel="stylesheet" href="{% static 'cronjob/godmode.css' %}">

{% load static %}
<link rel="script" href="{% static 'scripts/hide.js' %}">

<title>{{ website_title }}</title>

</head>
Expand Down
11 changes: 6 additions & 5 deletions cronjob/views/cronjobview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from cronjob.forms.cronjob.cronjobforms import AuthenticateForm, TitleForm, UserMessageForm, GeneralForm
from cronjob.forms.cronjob.cronjobforms import MinutesForm, HoursFrom, DaysFrom
from cronjob.forms.cronjob.cronjobforms import MinutesForm, HoursFrom, DaysFrom, UserDefinedTimeForm
from cronjob.models import CronJob


Expand All @@ -18,13 +18,14 @@ def createCronJob(request):
minutes = MinutesForm(data=request.POST or None)
hours = HoursFrom(data=request.POST or None)
days = DaysFrom(data=request.POST or None)
user_defined = UserDefinedTimeForm(data=request.POST or None)
user_message = UserMessageForm(data=request.POST or None)
general = GeneralForm(data=request.POST or None)
context = {'website_title': website_title, 'title': title, 'authenticate': authenticate,
'minutes': minutes, 'hours': hours, 'days': days,
'minutes': minutes, 'hours': hours, 'days': days, 'user_defined': user_defined,
'user_message': user_message, 'general': general}
if request.method == 'POST':
execution_time = calcSchedule(request, minutes, hours, days)
execution_time = calcSchedule(request, minutes, hours, days, user_defined)
cron_job = CronJob(
user=auth.get_user(request),
title=title['title'].value(),
Expand All @@ -46,7 +47,7 @@ def createCronJob(request):

# Original Gangster Programmer (OGP) of calcSchedule(request): Vincenz Gregori
# OGP changer: Manuel Werder
def calcSchedule(request, minutes, hours, days):
def calcSchedule(request, minutes, hours, days, user_defined):
if request.POST.get('id_times') == 'minutes':
return '*/' + str(minutes['each_minute'].value()) + ' * * * *'
elif request.POST.get('id_times') == 'hours':
Expand All @@ -57,4 +58,4 @@ def calcSchedule(request, minutes, hours, days):
' ' + str(days['every_hours_day'].value()) + \
' ' + str(days['every_month_day'].value()) + ' * *'
elif request.POST.get('id_times') == 'user_defined':
return '* * * * *'
return str(user_defined['user_defined'].value())
Binary file modified db.sqlite3
Binary file not shown.

0 comments on commit b617a89

Please sign in to comment.