From 91fefeed0c040126bd5161a70f87634b357b0a86 Mon Sep 17 00:00:00 2001 From: Niko Savola Date: Fri, 7 Jan 2022 20:20:34 +0200 Subject: [PATCH] Lint the code --- bulletin.py | 9 ++++--- gui.py | 76 +++++++++++++++-------------------------------------- utils.py | 4 +-- 3 files changed, 29 insertions(+), 60 deletions(-) diff --git a/bulletin.py b/bulletin.py index 9f822cc..b847ed6 100644 --- a/bulletin.py +++ b/bulletin.py @@ -1,7 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from functools import partial -from jinja2 import Environment, FileSystemLoader, Markup + +from jinja2 import Environment, FileSystemLoader +from markupsafe import Markup + from utils import grouper, category_sort, categories, categories_en, week, all_entries @@ -37,10 +40,10 @@ def nl2br(s): template_short = env.get_template('cells_short.html') variables = { "title": "Fyysikkokillan viikkotiedote", - "header": week+"/2020\n"+"Kilta tiedottaa\nGuild News", + "header": week+"/2022\n"+"Kilta tiedottaa\nGuild News", "category_events": pairs, "category_events_en": pairs_en, - "communications_officer": "Niko Savola", + "communications_officer": "Jaakko Johansson", "telegram_nick": "viestintavastaava", "email": "viestintavastaava@fyysikkokilta.fi", "week": week diff --git a/gui.py b/gui.py index e4c2e09..19f7e8e 100755 --- a/gui.py +++ b/gui.py @@ -3,15 +3,16 @@ from PyQt5 import QtCore, QtGui from PyQt5.QtCore import QDateTime from PyQt5.QtWidgets import (QApplication, QDialog, QGridLayout, QGroupBox, - QRadioButton, QHBoxLayout, QVBoxLayout, QStyleFactory, QLineEdit, - QTextEdit, QLabel, QPushButton, QTabWidget, QWidget, QButtonGroup, - QDateEdit, QCheckBox, QShortcut, QTextBrowser) + QRadioButton, QHBoxLayout, QVBoxLayout, QStyleFactory, QLineEdit, + QTextEdit, QLabel, QPushButton, QButtonGroup, + QDateEdit, QCheckBox) + from utils import save_entry class MainWindow(QDialog): def __init__(self, parent=None): - super(MainWindow, self).__init__(parent) + super().__init__(parent) self.createCategorySelectionGroupBox() self.createTextEditLayout() @@ -28,8 +29,8 @@ def __init__(self, parent=None): self.setWindowIcon(QtGui.QIcon('templates/fi.png')) # Always-on-top mode. Currently does not work on Windows. - #alwaysOnTopShortcut = QShortcut(QtGui.QKeySequence("Ctrl+O"), self) - #alwaysOnTopShortcut.activated.connect(lambda: + # alwaysOnTopShortcut = QShortcut(QtGui.QKeySequence("Ctrl+O"), self) + # alwaysOnTopShortcut.activated.connect(lambda: # super(MainWindow, self).__init__(parent, QtCore.Qt.WindowStaysOnTopHint)) def createCategorySelectionGroupBox(self): @@ -73,46 +74,27 @@ def createCategorySelectionGroupBox(self): self.categorySelectionLayout.addWidget(dateLabel) self.categorySelectionLayout.addWidget(self.dateEdit) - - def otherLanguageText(self, text): # convert to dictionary - - if (text == "Guild's events"): + @staticmethod + def otherLanguageText(text): # convert to dictionary + if text == "Guild's events": return "Killan tapahtumat" - elif (text == "Killan tapahtumat"): + elif text == "Killan tapahtumat": return "Guild's events" - elif (text == "Other events"): + elif text == "Other events": return "Muut tapahtumat" - elif (text == "Muut tapahtumat"): + elif text == "Muut tapahtumat": return "Other events" - elif (text == "General"): + elif text == "General": return "Yleistä" - elif (text == "Yleistä"): + elif text == "Yleistä": return "General" - elif (text == "Studies"): + elif text == "Studies": return "Opinnot" - elif (text == "Opinnot"): + elif text == "Opinnot": return "Studies" else: raise Exception("Wrong value for otherLanguageText") - """ - categoriesDict_en = { - "Guild's events":"Killan tapahtumat", - "Other events":"Muut tapahtumat", - "General":"Yleistä", - "Studies":"Opinnot" - } - - categoriesDict_fi = dict(reversed(item) for item in categoriesDict_en.items()) - categoriesDict = dict(categoriesDict_en, categoriesDict_fi) - - try: - return categoriesDict(text) - except ValueError: - raise Exception("Wrong value for otherLanguageText") - """ - - def languageCheckBoxClicked(self, state): if state == QtCore.Qt.Checked: self.radioButton1.setText("Guild's events") @@ -125,21 +107,11 @@ def languageCheckBoxClicked(self, state): self.radioButton3.setText("Yleistä") self.radioButton4.setText("Opinnot") - - - #def hide(self): - # self.headerLineEdit.hide() - # self.textBrowser = QTextBrowser() - # self.textBrowser.setGeometry(QtCore.QRect(390, 10, 531, 681)) - # self.textBrowser.setObjectName("textBrowser") - # self.textBrowser.show() - - def createTextEditLayout(self): self.textEditLayout = QVBoxLayout() self.additionalWeeksEdit = QLineEdit() - self.additionalWeeksEdit.setText("0") # default + self.additionalWeeksEdit.setText("0") # default self.headerLineEdit = QLineEdit() self.imageUrl = QLineEdit() self.contentTextEdit = QTextEdit() @@ -162,8 +134,6 @@ def createTextEditLayout(self): self.textEditLayout.addWidget(contentLabel) self.textEditLayout.addWidget(self.contentTextEdit) - - def createButtonLayout(self): self.buttonLayout = QHBoxLayout() @@ -177,7 +147,6 @@ def createButtonLayout(self): self.buttonLayout.addStretch(1) self.buttonLayout.addWidget(savePushButton) - def save(self): category = self.categorySelectionButtonGroup.checkedButton().text() date = [self.dateEdit.date().day(), self.dateEdit.date().month(), self.dateEdit.date().year()] @@ -192,20 +161,19 @@ def save(self): 'header': header, 'image': image, 'content': content - }, self.languageCheckBox.isChecked(), weeks) + }, self.languageCheckBox.isChecked(), weeks) if self.toBothBulletinsCheckBox.isChecked(): save_entry({ - 'category': self.otherLanguageText(category), # both languages fix here + 'category': self.otherLanguageText(category), # both languages fix here 'date': date, 'header': header, 'image': image, 'content': content - }, not self.languageCheckBox.isChecked(), weeks) + }, not self.languageCheckBox.isChecked(), weeks) self.clear() - def clear(self): self.headerLineEdit.clear() self.imageUrl.clear() @@ -215,9 +183,7 @@ def clear(self): self.dateEdit.setDateTime(QDateTime.currentDateTime()) - if __name__ == '__main__': - import sys app = QApplication(sys.argv) diff --git a/utils.py b/utils.py index 5a6434e..d04e541 100644 --- a/utils.py +++ b/utils.py @@ -19,7 +19,7 @@ # Database logic. -def save_entry(dict, isEnglish=False, addWeeks=0): +def save_entry(entry, isEnglish=False, addWeeks=0): """Save entry to database.""" for i in range(addWeeks+1): week_number = str(int(week)+i).zfill(2) @@ -28,7 +28,7 @@ def save_entry(dict, isEnglish=False, addWeeks=0): else: path = 'data/week'+week_number+'.json' db = TinyDB(path, ensure_ascii=False, sort_keys=True, indent=4, separators=(',', ': ')) - db.insert(dict) + db.insert(entry) def all_entries(isEnglish=False): """Return all events from database for this week."""