-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stapf functions #55
Open
JanLuca
wants to merge
5
commits into
ZaPF:main
Choose a base branch
from
JanLuca:stapfFuncs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Stapf functions #55
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from flask import Blueprint | ||
|
||
stapf_blueprint = Blueprint('stapf', __name__, template_folder='templates/') | ||
|
||
from . import models, views | ||
|
||
def init_app(app): | ||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import email.utils | ||
from app.db import db | ||
from .models import Recipient | ||
from flask import current_app | ||
from flask_mail import Message | ||
|
||
def import_recipients_from_list(mail_list): | ||
result = [] | ||
for line in mail_list.splitlines(): | ||
parsed_mail = email.utils.parseaddr(line) | ||
recipient = Recipient() | ||
recipient.name = parsed_mail[0] | ||
recipient.mail = parsed_mail[1] | ||
recipient.comment = 'Automatisch importiert (bitte überprüfen)' | ||
db.session.add(recipient) | ||
result.append(recipient) | ||
db.session.commit() | ||
return result | ||
|
||
def send_batch_mails(batch): | ||
with current_app.mail.connect() as conn: | ||
for recipients_list in batch.decision.recipients_lists: | ||
for recipient in recipients_list.recipients: | ||
if not recipient.mail: | ||
continue | ||
msg = Message(batch.subject, recipients=[recipient.mail], | ||
body=batch.message, sender=current_app.config['MAIL_STAPF']) | ||
with current_app.open_resource(batch.decision.file_path) as fp: | ||
msg.attach(batch.decision.filename, "application/pdf", fp.read()) | ||
conn.send(msg) | ||
|
||
#msg = Message(batch.subject, recipients=[current_app.config['MAIL_STAPF']], | ||
# body=batch.message, sender=current_app.config['MAIL_STAPF']) | ||
#with current_app.open_resource(batch.decision.file_path) as fp: | ||
# msg.attach(batch.decision.filename, "application/pdf", fp.read()) | ||
#conn.send(msg) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from app.db import db | ||
from app.user.models import User | ||
from flask import Blueprint, abort, current_app, json | ||
|
||
RecipientToList = db.Table('recipient_to_list', | ||
db.Column('list_id', db.Integer, db.ForeignKey('recipients_lists.id'), primary_key=True), | ||
db.Column('recipient_id', db.Integer, db.ForeignKey('recipients.id'), primary_key=True), | ||
info={'bind_key': 'stapf'} | ||
) | ||
|
||
DecisionRecipientsLists = db.Table('decision_recipients_lists', | ||
db.Column('decision_id', db.Integer, db.ForeignKey('decisions.id'), primary_key=True), | ||
db.Column('recipients_list_id', db.Integer, db.ForeignKey('recipients_lists.id'), primary_key=True), | ||
info={'bind_key': 'stapf'} | ||
) | ||
|
||
class Recipient(db.Model): | ||
__bind_key__ = 'stapf' | ||
__tablename__ = 'recipients' | ||
id = db.Column(db.Integer(), primary_key = True) | ||
name = db.Column(db.Text()) | ||
organisation_name = db.Column(db.Text()) | ||
addressline1 = db.Column(db.Text()) | ||
addressline2 = db.Column(db.Text()) | ||
street = db.Column(db.Text()) | ||
postal_code = db.Column(db.Integer()) | ||
locality = db.Column(db.Text()) | ||
country = db.Column(db.Text()) | ||
mail = db.Column(db.Text()) | ||
comment = db.Column(db.Text()) | ||
|
||
@property | ||
def has_address(self): | ||
return self.street and self.locality | ||
|
||
class RecipientsList(db.Model): | ||
__bind_key__ = 'stapf' | ||
__tablename__ = 'recipients_lists' | ||
id = db.Column(db.Integer(), primary_key = True) | ||
name = db.Column(db.Text(), unique = True) | ||
recipients = db.relationship("Recipient", secondary=RecipientToList, backref=db.backref('lists', lazy=True)) | ||
comment = db.Column(db.Text()) | ||
|
||
class Decision(db.Model): | ||
__bind_key__ = 'stapf' | ||
__tablename__ = 'decisions' | ||
id = db.Column(db.Integer(), primary_key = True) | ||
title = db.Column(db.Text()) | ||
decided = db.Column(db.Date()) | ||
recipients_lists = db.relationship("RecipientsList", secondary=DecisionRecipientsLists, backref=db.backref('decisions', lazy=True)) | ||
filename = db.Column(db.Text()) | ||
file_path = db.Column(db.Text()) | ||
comment = db.Column(db.Text()) | ||
|
||
class Batch(db.Model): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a more descriptive name here might be better, e.g. |
||
__bind_key__ = 'stapf' | ||
__tablename__ = 'batches' | ||
id = db.Column(db.Integer(), primary_key = True) | ||
subject = db.Column(db.Text()) | ||
message = db.Column(db.Text()) | ||
decision_id = db.Column(db.Integer(), db.ForeignKey('decisions.id')) | ||
decision = db.relationship("Decision", backref=db.backref('batches', lazy=True)) | ||
sent = db.Column(db.Boolean(), default=False) | ||
sent_at = db.Column(db.DateTime()) | ||
comment = db.Column(db.Text()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{% extends "base.html" %} | ||
{% import "bootstrap/wtf.html" as wtf %} | ||
|
||
{% block styles %} | ||
{{super()}} | ||
<link rel="stylesheet" | ||
href="{{url_for('static', filename='plugin-bootstrap-select-1.12.4/css/bootstrap-select.min.css')}}"> | ||
{% endblock %} | ||
|
||
{% block scripts %} | ||
{{super()}} | ||
<script src="{{url_for('static', filename='plugin-bootstrap-select-1.12.4/js/bootstrap-select.min.js')}}"></script> | ||
{% endblock %} | ||
|
||
{% macro show_form_errors(form, container = True) %} | ||
{% if form.errors -%} {# don't output anything if there are no errors #} | ||
{% if container -%} | ||
<div class="row"> | ||
<div class="col-sm-12"> | ||
{% endif -%} | ||
<div class="alert alert-danger" role="alert"> | ||
<p><strong>Errors when validating form data:</strong></p> | ||
{{ wtf.form_errors(form) }} | ||
</div> | ||
{% if container %} | ||
</div> | ||
</div> | ||
{% endif -%} | ||
{% endif -%} | ||
{% endmacro -%} | ||
|
||
{% block title %}Mail-Auftrag bearbeiten{% endblock %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
<form class="form-horizontal" method="POST"> | ||
{{ form.hidden_tag() }} | ||
|
||
<div class="form-horizontal"> | ||
{{ show_form_errors(form) }} | ||
|
||
<div class="form-group row"> | ||
{{ form.subject.label(class='col-sm-3 control-label') }} | ||
<div class="col-sm-9">{% if readonly %}{{ form.subject(class='form-control', readonly='readonly') }}{% else %}{{ form.subject(class='form-control') }}{% endif %}</div> | ||
</div> | ||
<div class="form-group row{% if form.decision.errors %} has-error{% endif %}"> | ||
{{ form.decision.label(class='col-sm-3 control-label') }} | ||
<div class="col-sm-9"> | ||
{% if readonly %} | ||
{{form.decision(class='form-control', readonly='readonly')}} | ||
{% else %} | ||
{{form.decision(class='form-control selectpicker', **{'data-live-search':'true', 'data-selected-text-format':'count > 3'})}} | ||
{% endif %} | ||
</div> | ||
</div> | ||
<div class="form-group row"> | ||
{{ form.message.label(class='col-sm-3 control-label') }} | ||
<div class="col-sm-9">{% if readonly %}{{ form.message(class='form-control', readonly='readonly') }}{% else %}{{ form.message(class='form-control') }}{% endif %}</div> | ||
</div> | ||
<div class="form-group row"> | ||
{{ form.comment.label(class='col-sm-3 control-label') }} | ||
<div class="col-sm-9">{% if readonly %}{{ form.comment(class='form-control', readonly='readonly') }}{% else %}{{ form.comment(class='form-control') }}{% endif %}</div> | ||
</div> | ||
<div class="form-group row"> | ||
<div class="col-sm-offset-3 col-sm-9"> | ||
{{ form.submit(class='btn btn-lg btn-default') }} | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}Mail-Aufträge{% endblock %} | ||
|
||
{% block scripts %} | ||
{{ super() }} | ||
<script type="text/javascript"> | ||
// Adapted from http://jsfiddle.net/ukW2C/3/ | ||
$("#search").keyup(function () { | ||
//split the current value of search | ||
var data = this.value.split(" "); | ||
|
||
//create a jquery object of the rows | ||
var jo = $("#batches").find("tr"); | ||
if (this.value == "") { | ||
jo.show(); | ||
$("#search-group").removeClass("has-error"); | ||
$("#search-group").removeClass("has-success"); | ||
return; | ||
} | ||
//hide all the rows | ||
jo.hide(); | ||
|
||
//Recusively filter the jquery object to get results. | ||
filtered = jo.filter(function (i, v) { | ||
var $t = $(this); | ||
for (var d = 0; d < data.length; ++d) { | ||
if ($t.is(":contains('" + data[d] + "')")) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}); | ||
//show the rows that match. | ||
filtered.show(); | ||
|
||
//update the search bar validation status | ||
if (filtered.length) { | ||
$("#search-group").addClass("has-success"); | ||
$("#search-group").removeClass("has-error"); | ||
} else { | ||
$("#search-group").addClass("has-error"); | ||
$("#search-group").removeClass("has-success"); | ||
} | ||
}).focus(function () { | ||
this.value = ""; | ||
$(this).unbind('focus'); | ||
}); | ||
</script> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
<h1>Mail-Aufträge</h1> | ||
|
||
<div id="search-group" class="form-group has-feedback"> | ||
<label class="control-label sr-only" for="search">Suche für Adressaten</label> | ||
<div class="input-group"> | ||
<span class="input-group-addon"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></span> | ||
<input id="search" type="text" class="form-control input-lg" placeholder="Suche"> | ||
</div> | ||
</div> | ||
|
||
<div class="btn-group" role="group"> | ||
<a class="btn btn-default" href="{{url_for('stapf.batch_new')}}"> | ||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Neuer Auftrag | ||
</a> | ||
</div> | ||
|
||
<br /> | ||
|
||
<div class="table-responsive"> | ||
<table class='table'> | ||
<tr> | ||
<th>Betreff</th> | ||
<th>Versendet</th> | ||
<th>Versendet am</th> | ||
<th>Kommentar</th> | ||
<th>Aktionen</th> | ||
</tr> | ||
<tbody id="batches"> | ||
{% for batch in batches %} | ||
<tr> | ||
<td>{{ batch.subject }}</td> | ||
<td>{% if batch.sent %}<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>{% endif %}</td> | ||
<td>{% if batch.sent %}{{ batch.sent_at }}{% endif %}</td> | ||
<td>{{ batch.comment }}</td> | ||
<td> | ||
<div class="btn-group" role="group"> | ||
{% if not batch.sent %} | ||
<a class="btn-default btn" href="{{url_for('stapf.batch_send', batch_id=batch.id)}}"> | ||
<span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> Versenden | ||
</a> | ||
<a class="btn-default btn" href="{{url_for('stapf.batch', batch_id=batch.id)}}"> | ||
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span> Bearbeiten | ||
</a> | ||
<a class="btn-danger btn" href="{{url_for('stapf.batch_delete', batch_id=batch.id)}}"> | ||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Löschen | ||
</a> | ||
{% else %} | ||
<a class="btn-default btn" href="{{url_for('stapf.batch', batch_id=batch.id)}}"> | ||
<span class="glyphicon glyphicon-search" aria-hidden="true"></span> Details | ||
</a> | ||
{% endif %} | ||
</div> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
{% endblock %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly does a
Decision
represent? Maybe we can find better naming for this class...