def export(request): import datetime from tuition.settings import SITE_SUPPORT_EMAIL from tuition.utils.manager import AppManager from tuition.tools.models import Expenses from tuition.utils.utils import ExportSelector, EXPORT_HANDLE_LABELS, getMonthEnd serializedObjectList = [] linkToFile = None fileName = None isSaved = False invalidHandle = True response = {} exportHandle = request.GET.get('handle', None) exportDate = datetime.datetime.strptime(request.GET.get('date', datetime.date.today().strftime('%d_%m_%Y')), '%d_%m_%Y') firstOfMonth = datetime.date(exportDate.year, exportDate.month, 1) endOfMonth = datetime.date(exportDate.year, exportDate.month, getMonthEnd(exportDate.month, exportDate.year)) loggedInEmployee = AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email()) expensesList = Expenses.all().filter('user ='******'dateOfExpense >=', firstOfMonth).filter('dateOfExpense <=', endOfMonth).order('-dateOfExpense').fetch(limit=1000) if expensesList: for expense in expensesList: serializedObjectList.append(expense.toDict) exporterClass = ExportSelector.get(exportHandle) if exporterClass: invalidHandle = False exporterInstance = exporterClass( serializedObjects=serializedObjectList, request=request, remove=['key', 'user'], date=exportDate ) response = exporterInstance.upload() if isinstance(response, dict): isSaved = response.get('isSaved') linkToFile = response.get('fileResponse', {}).get('alternateLink') fileName = response.get('fileResponse', {}).get('title') template_values = { 'isSaved' : isSaved, 'linkToFile' : linkToFile, 'fileName' : fileName, 'handle' : EXPORT_HANDLE_LABELS.get(exportHandle, exportHandle), 'invalidHandle' : invalidHandle, 'loggedInEmployee' : loggedInEmployee, 'url' : AppManager.createLogoutURL(), 'homePage' : '/', 'supportEmail' : SITE_SUPPORT_EMAIL } return render_to_response('exportFinish.html', template_values) else: return response
def home(request): from tuition.settings import SITE_SUPPORT_EMAIL from tuition.utils.manager import AppManager, UserFilter UserFilter().checkUserRole(request.path) template_values = { 'loggedInEmployee' : AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email()), 'url' : AppManager.createLogoutURL(), 'homePage' : '/', 'supportEmail' : SITE_SUPPORT_EMAIL } return render_to_response('home.html', template_values)
def addAnExpense(request): from tuition.settings import SITE_SUPPORT_EMAIL from forms import ExpenseForm from tuition.utils.manager import AppManager form = ExpenseForm(initial={'dateOfExpense' : datetime.date.today().strftime('%d/%m/%Y')}) template_values = { 'form' : form, 'loggedInEmployee' : AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email()), 'url' : AppManager.createLogoutURL(), 'homePage' : '/', 'supportEmail' : SITE_SUPPORT_EMAIL } return render_to_response('newExpense.html', template_values)
def addRole(request): from tuition.settings import SITE_SUPPORT_EMAIL from tuition.role.forms import RoleAddForm from tuition.utils.manager import UserFilter, AppManager UserFilter().checkUserRole(request.path) template_values = { 'loggedInEmployee' : AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email()), 'url' : AppManager.createLogoutURL(), 'homePage' : '/', 'supportEmail' : SITE_SUPPORT_EMAIL, 'permissions' : PERMISSIONS, 'form' : RoleAddForm() } return render_to_response('addRole.html', template_values)
def contextProcessor(request): import datetime from tuition.settings import SITE_SUPPORT_EMAIL from tuition.utils.utils import ExportHandle, ExportClassHandle from tuition.utils.manager import AppManager return { 'url': AppManager.createLogoutURL(), 'homePage': '/', 'supportEmail': SITE_SUPPORT_EMAIL, 'spreadSheetHandle': ExportHandle.SPREADSHEET, 'expenseExportHandle': ExportClassHandle.EXPENSE, 'debtExportHandle': ExportClassHandle.DEBT, 'startOfMonth': datetime.date.today().replace(day=1) }
def viewRoles(request): from tuition.settings import SITE_SUPPORT_EMAIL from tuition.role.models import Role from tuition.utils.manager import UserFilter, AppManager UserFilter().checkUserRole(request.path) roles = Role.all().fetch(limit = 1000) template_values = { 'loggedInEmployee' : AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email()), 'url' : AppManager.createLogoutURL(), 'homePage' : '/', 'supportEmail' : SITE_SUPPORT_EMAIL, 'roles' : roles, 'permissions' : PERMISSIONS } return render_to_response('viewRoles.html', template_values)
def viewUserExpenses(request, userKey=None): from tuition.settings import SITE_SUPPORT_EMAIL from tuition.utils.manager import AppManager from models import Expenses from forms import ExpenseForm, ExpenseYearFilter from tuition.utils.appConstants import MONTH_NUM_FULL_NAME_DICT from tuition.utils.utils import ExportHandle loggedInEmployee = AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email()) form = ExpenseForm(initial={'dateOfExpense' : datetime.date.today().strftime('%d/%m/%Y')}) template_values = { 'loggedInEmployee' : loggedInEmployee, 'url' : AppManager.createLogoutURL(), 'homePage' : '/', 'supportEmail' : SITE_SUPPORT_EMAIL, 'yearFilterForm' : ExpenseYearFilter(), 'monthNameDict' : MONTH_NUM_FULL_NAME_DICT, 'exportHandle' : ExportHandle.asDict(), 'form' : form } return render_to_response('viewExpenses.html', template_values)
def profile(request): from tuition.settings import SITE_SUPPORT_EMAIL from tuition.utils.utils import GooglePlusService from tuition.utils.manager import AppManager from forms import UserRegistrationForm user = AppManager.getCurrentLoggedInUser() loggedInEmployee = AppManager.getUserByEmail(user.email()) loggedInEmployee.id = user.user_id() response = GooglePlusService(request=request, loggedInEmployee=loggedInEmployee).getUserInfo(setImageSize=250) if isinstance(response, dict): locationFromPlus = response.get("userInfo", {}).get("currentLocation", "") if not locationFromPlus: placesLived = response.get("userInfo", {}).get("placesLived", []) if placesLived and placesLived[0].get("primary"): locationFromPlus = placesLived[0].get("value") template_values = { "form": UserRegistrationForm( initial={ "firstName": loggedInEmployee.firstName, "lastName": loggedInEmployee.lastName, "alternateEmail": loggedInEmployee.alternateEmail, "dob": loggedInEmployee.dob.strftime("%d/%m/%Y"), "about": loggedInEmployee.about or "", } ), "loggedInEmployee": loggedInEmployee, "url": AppManager.createLogoutURL(), "homePage": "/", "supportEmail": SITE_SUPPORT_EMAIL, "publicProfile": response.get("userInfo", {}).get("url", "#"), "imageUrl": response.get("userInfo", {}).get("image", {}).get("url", "/images/emptyProfile.gif"), "locationFromPlus": locationFromPlus, "about": response.get("userInfo", {}).get("aboutMe", ""), } return render_to_response("userProfile.html", template_values) return response
def register(request): from tuition.settings import SITE_SUPPORT_EMAIL from forms import UserRegistrationForm from tuition.utils.manager import AppManager from tuition.utils.utils import URLCreator from tuition.urlPatterns import UrlPattern from tuition.utils.utils import GooglePlusService queryString = int(request.GET.get("firstLogin", 0)) loggedInEmployee = AppManager.getCurrentLoggedInUser() if not AppManager.isCurrentUserAppAdmin(): if not queryString or AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email()): raise Exception("Unauthorized Access") else: loggedInEmployee = AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email()) template_values = { "form": UserRegistrationForm(), "loggedInEmployee": loggedInEmployee, "url": AppManager.createLogoutURL(), "homePage": "/", "supportEmail": SITE_SUPPORT_EMAIL, "queryString": queryString, } return render_to_response("userRegistration.html", template_values)