society-self-service/ssmembership/monboard.py

79 lines
2.5 KiB
Python
Raw Normal View History

2019-03-06 10:43:32 +11:00
# 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 <https://www.gnu.org/licenses/>.
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]
2019-06-19 16:04:00 +10:00
member.member_type = 1 # Ordinary Member
2019-03-06 10:43:32 +11:00
# Calculate expiration date
2019-07-22 09:33:20 +10:00
member.expires = timezone.localtime(timezone.now()).date().replace(month=3, day=31)
2019-03-06 10:43:32 +11:00
member.expires = member.expires.replace(year=member.expires.year+1)
2019-07-22 09:33:20 +10:00
if member.expires < timezone.localtime(timezone.now()).date(): # Add 1 year if after Mar 31, else add 2 years
2019-03-06 10:43:32 +11:00
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()