# Society Self-Service # Copyright © 2018-2019 Yingtong Li (RunasSudo) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . import sqlite3 from django.utils import timezone from . import models import datetime def get_members(): conn = sqlite3.connect('file:onboards.db?mode=ro', uri=True) cur = conn.cursor() cur.execute('SELECT * FROM members') result = cur.fetchall() conn.close() return result def by_email(email): conn = sqlite3.connect('file:onboards.db?mode=ro', uri=True) cur = conn.cursor() cur.execute('SELECT * FROM members WHERE email=? AND imported=0', (email,)) result = cur.fetchone() conn.close() if not result: return None member = models.Member() # id, student_id, email, first_name, last_name, year, is_msa, phone, date, purchased, imported member.student_id = result[1] member.email = result[2] member.first_name = result[3] member.last_name = result[4] member.year = {'Year A': 0, 'Year 1': 1, 'Year 2': 2, 'Year 3B': 3, 'Year 4C': 4, 'Year 5D': 5, 'BMedSci': 97, 'PhD': 98, 'Intermission': 99}[result[5]] member.is_msa = result[6] member.phone = result[7] member.member_type = 1 # Ordinary Member # Calculate expiration date member.expires = timezone.localtime(timezone.now()).date().replace(month=3, day=31) member.expires = member.expires.replace(year=member.expires.year+1) if member.expires < timezone.localtime(timezone.now()).date(): # Add 1 year if after Mar 31, else add 2 years member.expires = member.expires.replace(year=member.expires.year+1) return member def delete_by_email(email): conn = sqlite3.connect('file:onboards.db', uri=True) cur = conn.cursor() cur.execute('UPDATE members SET imported=1 WHERE email=?', (email,)) conn.commit() conn.close() def set_emailed_by_email(email): conn = sqlite3.connect('file:onboards.db', uri=True) cur = conn.cursor() cur.execute('UPDATE members SET emailed=1 WHERE email=?', (email,)) conn.commit() conn.close()