Add basic event system

This commit is contained in:
Nathan Chapman 2021-07-28 18:10:07 -06:00
parent fa98be63fa
commit 391fe5c42a
12 changed files with 91 additions and 39 deletions

View File

@ -25,7 +25,7 @@
</section> </section>
<p><a href="{% url 'event-create' %}" class="action-button">Add event</a></p> <p><a href="{% url 'event-create' %}" class="action-button">Add event</a></p>
<section> <section>
<h3>Upcoming</h3> <h3>Upcoming (next seven days)</h3>
<div> <div>
{% for event in upcoming_events %} {% for event in upcoming_events %}
<div class="today__event"> <div class="today__event">
@ -49,9 +49,13 @@
<h5>{{date.grouper|date:"D, M j"}}</h5> <h5>{{date.grouper|date:"D, M j"}}</h5>
{% for entry in date.list %} {% for entry in date.list %}
<p class="activity__item"> <p class="activity__item">
{{entry.notes}} <span>{{entry.created_at|time:"TIME_FORMAT"}}</span>
<em>for</em> <span>
<a href="{% url 'employee-detail' entry.employee.pk %}">{{entry.employee}}</a> {{entry.notes}}
<em>for</em>
<a href="{% url 'employee-detail' entry.employee.pk %}">{{entry.employee}}</a>
</span>
<span><a href="{% url 'entry-update' entry.employee.pk entry.pk %}">Edit</a></span>
</p> </p>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}

View File

@ -60,9 +60,11 @@
{% for date in activity %} {% for date in activity %}
<h5>{{date.grouper|date:"D, M j"}}</h5> <h5>{{date.grouper|date:"D, M j"}}</h5>
{% for entry in date.list %} {% for entry in date.list %}
<p class="activity__item"> <p class="activity__item">
<span>{{entry.created_at|time:"H:i"}}</span> <span>{{entry.created_at|time:"TIME_FORMAT"}}</span>
<span>{{entry.notes}}</span></p> <span>{{entry.notes}}</span>
<span><a href="{% url 'entry-update' employee.pk entry.pk %}">Edit</a></span>
</p>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
</section> </section>

View File

@ -8,7 +8,8 @@
{% for employee in employee_list %} {% for employee in employee_list %}
<p> <p>
<a href="{% url 'employee-detail' employee.pk %}"><strong>{{employee.full_name}}</strong></a><br> <a href="{% url 'employee-detail' employee.pk %}"><strong>{{employee.full_name}}</strong></a><br>
<small>Hire date: {{employee.hire_date|date:"SHORT_DATE_FORMAT"}}</small> <small>Hire date: {{employee.hire_date|date:"SHORT_DATE_FORMAT"}}</small><br>
<small>Department: {{employee.department}}</small>
</p> </p>
{% endfor %} {% endfor %}
</section> </section>

View File

@ -8,7 +8,7 @@
{% csrf_token %} {% csrf_token %}
{{form.as_p}} {{form.as_p}}
<p> <p>
<input class="action-button" type="submit" value="Create Event"> or <a href="{% url 'event-list' %}">cancel</a> <input class="action-button" type="submit" value="Create Event"> or <a href="{% url 'profile-detail' %}">cancel</a>
</p> </p>
</form> </form>
</section> </section>

View File

@ -8,7 +8,7 @@
{% csrf_token %} {% csrf_token %}
{{form.as_p}} {{form.as_p}}
<p> <p>
<input class="action-button" type="submit" value="Save changes"> or <a href="{% url 'event-list' %}">cancel</a> <input class="action-button" type="submit" value="Save changes"> or <a href="{% url 'profile-detail' %}">cancel</a>
</p> </p>
</form> </form>
</section> </section>

View File

@ -20,5 +20,22 @@
<p>There are no events yet.</p> <p>There are no events yet.</p>
{% endfor %} {% endfor %}
</section> </section>
<section class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1">&laquo; first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</section>
</article> </article>
{% endblock %} {% endblock %}

View File

@ -3,10 +3,10 @@
{% block content %} {% block content %}
<article> <article>
<h1>Delete {{logentry}}</h1> <h1>Delete {{logentry}}</h1>
<form method="post" action="{% url 'logentry-delete' logentry.pk %}"> <form method="post" action="{% url 'entry-delete' employee.pk logentry.pk %}">
{% csrf_token %} {% csrf_token %}
<p> <p>
<input class="action-button action-delete" type="submit" value="Confirm Delete {{logentry}}"> or <a href="{% url 'logentry-detail' logentry.pk %}">cancel</a> <input class="action-button action-button--danger" type="submit" value="Confirm Delete"> or <a href="{% url 'employee-detail' employee.pk %}">cancel</a>
</p> </p>
</form> </form>
</article> </article>

View File

@ -2,9 +2,18 @@
{% block content %} {% block content %}
<article> <article>
<h1></h1> <header>
<section> <h1>Update Event</h1>
<p><a class="action-button action-button--danger" href="{% url 'entry-delete' employee.pk logentry.pk %}">Delete this entry</a></p>
</section> </header>
</article> <section>
<form method="POST" action="{% url 'entry-update' employee.pk logentry.pk %}">
{% csrf_token %}
{{form.as_p}}
<p>
<input class="action-button" type="submit" value="Save changes"> or <a href="{% url 'employee-detail' employee.pk %}">cancel</a>
</p>
</form>
</section>
</article>
{% endblock %} {% endblock %}

View File

@ -118,7 +118,14 @@ class LogEntryUpdateView(LoginRequiredMixin, UpdateView):
class LogEntryDeleteView(LoginRequiredMixin, DeleteView): class LogEntryDeleteView(LoginRequiredMixin, DeleteView):
model = LogEntry model = LogEntry
pk_url_kwarg = 'entry_pk' pk_url_kwarg = 'entry_pk'
success_url = reverse_lazy('entry-list')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['employee'] = Employee.objects.get(pk=self.kwargs['pk'])
return context
def get_success_url(self):
return reverse('employee-detail', kwargs={'pk': self.kwargs['pk']})
# Todos # Todos
@ -177,6 +184,8 @@ class TodoDeleteDoneView(LoginRequiredMixin, TemplateView):
# Events # Events
class EventListView(LoginRequiredMixin, ListView): class EventListView(LoginRequiredMixin, ListView):
model = Event model = Event
paginate_by = 100
ordering = ('-date', '-time')
class EventCreateView(LoginRequiredMixin, CreateView): class EventCreateView(LoginRequiredMixin, CreateView):
model = Event model = Event
@ -194,4 +203,3 @@ class EventUpdateView(LoginRequiredMixin, UpdateView):
class EventDeleteView(LoginRequiredMixin, DeleteView): class EventDeleteView(LoginRequiredMixin, DeleteView):
model = Event model = Event
success_url = reverse_lazy('profile-detail') success_url = reverse_lazy('profile-detail')

View File

@ -25,7 +25,7 @@ with open('/etc/secret_key.txt') as f:
SECRET_KEY = f.read().strip() SECRET_KEY = f.read().strip()
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DJANGO_DEBUG', '') != 'False' DEBUG = False
ALLOWED_HOSTS = ['onboard.windmillapps.org', '127.0.0.1'] ALLOWED_HOSTS = ['onboard.windmillapps.org', '127.0.0.1']
@ -53,7 +53,6 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'onboard.middleware.TimezoneMiddleware',
] ]
ROOT_URLCONF = 'onboard.urls' ROOT_URLCONF = 'onboard.urls'
@ -127,10 +126,11 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/ # https://docs.djangoproject.com/en/3.2/howto/static-files/
STATICFILES_DIRS = [
BASE_DIR / 'static'
]
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATIC_ROOT = [BASE_DIR / 'static/'] STATIC_ROOT = '/var/www/onboard.windmillapps.org/static/'
STATICFILES_DIRS = [BASE_DIR / 'static']
# Default primary key field type # Default primary key field type
@ -163,7 +163,7 @@ LOGGING = {
# Email # Email
ANYMAIL = { ANYMAIL = {
"MAILGUN_API_KEY": os.environ.get('MAILGUN_API_KEY'), "MAILGUN_API_KEY": "key-b65d1f9e486825a7d01d099fd3062c2b",
} }
SERVER_EMAIL = 'noreply@onboard.windmillapps.org' SERVER_EMAIL = 'noreply@onboard.windmillapps.org'
@ -174,10 +174,8 @@ ADMINS = (
) )
MANAGERS = ADMINS MANAGERS = ADMINS
EMAIL_BACKEND = os.environ.get('EMAIL_BACKEND') EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'
SECURE_HSTS_SECONDS = True
SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = os.environ.get('DJANGO_SECURE_HSTS_SECONDS', '') != 'False' SESSION_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = os.environ.get('DJANGO_SECURE_SSL_REDIRECT', '') != 'False' CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = os.environ.get('DJANGO_SESSION_COOKIE_SECURE', '') != 'False'
CSRF_COOKIE_SECURE = os.environ.get('DJANGO_CSRF_COOKIE_SECURE', '') != 'False'

View File

@ -1,8 +1,9 @@
:root { :root {
--white: #fdfdff; --white: #f8f8fb;
--black: #393d3f; --black: #393d3f;
--grey: #a7b4bb; --grey: #a7b4bb;
--blue: #10638c; --blue: #10638c;
--red: #8c1016;
} }
html { html {
@ -98,9 +99,11 @@ article {
font-weight: 900; font-weight: 900;
} }
.navbar__menu { .navbar__mobile .menu__items {
text-align: center;
} }
.navbar__menu_title { .navbar__menu_title {
font-weight: 900; font-weight: 900;
padding: 0.2rem 1rem; padding: 0.2rem 1rem;
@ -200,6 +203,10 @@ article {
text-decoration: none; text-decoration: none;
} }
.action-button--danger {
background-color: var(--red);
}
/* FORMS */ /* FORMS */
input[type=text]:not([name=description]), input[type=text]:not([name=description]),
@ -326,4 +333,13 @@ hgroup {
margin-bottom: 2rem; margin-bottom: 2rem;
padding-bottom: 0.5rem; padding-bottom: 0.5rem;
border-bottom: 0.046rem solid var(--grey); border-bottom: 0.046rem solid var(--grey);
}
.activity__item {
display: grid;
grid-template-columns: 0.25fr 2fr 0.25fr;
column-gap: 0.5rem;
margin-bottom: 1rem;
} }

View File

@ -27,7 +27,6 @@
</form> </form>
<div class="nav__employees"> <div class="nav__employees">
<a href="{% url 'profile-detail' %}">Today</a> <a href="{% url 'profile-detail' %}">Today</a>
<a href="{% url 'event-list' %}">Events</a>
<a href="{% url 'employee-list' %}">Employees</a> <a href="{% url 'employee-list' %}">Employees</a>
</div> </div>
<div class="nav__auth"> <div class="nav__auth">
@ -45,7 +44,7 @@
</nav> </nav>
<nav class="navbar__mobile"> <nav class="navbar__mobile">
{% if user.is_authenticated %} {% if user.is_authenticated %}
<details class="menu_"> <details class="menu">
<summary class="menu__title">Menu</summary> <summary class="menu__title">Menu</summary>
<dl class="menu__items"> <dl class="menu__items">
<dt> <dt>
@ -56,8 +55,6 @@
<br> <br>
<dt><a href="{% url 'profile-detail' %}">Today</a></dt> <dt><a href="{% url 'profile-detail' %}">Today</a></dt>
<br> <br>
<dt><a href="{% url 'event-list' %}">Events</a></dt>
<br>
<dt><a href="{% url 'employee-list' %}">Employees</a></dt> <dt><a href="{% url 'employee-list' %}">Employees</a></dt>
<br> <br>
<dt><a class="action-button" href="{% url 'logout' %}">Logout</a></dt> <dt><a class="action-button" href="{% url 'logout' %}">Logout</a></dt>