Esempio n. 1
0
def export(request):
  import datetime
  from tuition.settings import SITE_SUPPORT_EMAIL
  from tuition.utils.manager import AppManager
  from tuition.utils.utils import ExportSelector, EXPORT_HANDLE_LABELS, getMonthEnd

  serializedObjectList = []
  linkToFile = None
  fileName = None
  isSaved = False
  noData = True
  invalidHandle = True
  response = {}

  classHandle = request.GET.get('classHandle', None)
  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())

  classWrapper = ExportSelector.getClass(classHandle)
  dataList = classWrapper().getForPeriod(loggedInEmployee.key(), firstOfMonth, endOfMonth)
  if dataList:
    noData = False
    for data in dataList:
      serializedObjectList.append(data.toDict)
    exporterClass = ExportSelector.getHandle(exportHandle)
    if exporterClass:
      invalidHandle = False
      exporterInstance = exporterClass(
          serializedObjects=serializedObjectList, 
          request=request, 
          remove=['key', 'user', 'calendarReminderURL', 'createdOn', 'updatedOn'],
          date=exportDate,
          namePrefix=classHandle
      )
      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),
      'classHandle'        : classHandle,
      'invalidHandle'      : invalidHandle,
      'noData'             : noData,
      'loggedInEmployee'   : loggedInEmployee
    }
    return render_to_response('exportFinish.html', template_values, context_instance=RequestContext(request))
  else:
    return response
Esempio n. 2
0
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 getExpenseThisMonth(self, values):
		import datetime
		from tuition.tools.models import Expenses
		from tuition.utils.manager import AppManager
		from tuition.utils.utils import getMonthEnd

		serializedObjects = []
		year = int(values.get('year', 2013))
		month = int(values.get('month', datetime.date.today().month))
		loggedInEmployee = AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email())
		firstOfMonth = datetime.date(year, month, 1)
		endOfMonth = datetime.date(year, month, getMonthEnd(month, year))
		thisMonthExpense = Expenses.all().filter('user ='******'dateOfExpense >=', firstOfMonth).filter('dateOfExpense <=', endOfMonth).order('-dateOfExpense')
		thisMonthExpense = thisMonthExpense.fetch(limit=1000)
		for expense in thisMonthExpense:
			serializedObjects.append(expense.toDict)
		return self.respond(expenses=serializedObjects)
Esempio n. 4
0
    def getDebtThisMonth(self, values):
        import datetime
        from tuition.tools.models import Debt
        from tuition.utils.manager import AppManager
        from tuition.utils.utils import getMonthEnd

        serializedObjects = []
        year = int(values.get('year', 2013))
        month = int(values.get('month', datetime.date.today().month))
        loggedInEmployee = AppManager.getUserByEmail(
            AppManager.getCurrentLoggedInUser().email())
        firstOfMonth = datetime.date(year, month, 1)
        endOfMonth = datetime.date(year, month, getMonthEnd(month, year))
        thisMonthDebts = Debt.all().filter(
            'user ='******'incurredDate >=',
                firstOfMonth).filter('incurredDate <=',
                                     endOfMonth).order('-incurredDate')
        thisMonthDebts = thisMonthDebts.fetch(limit=1000)
        for debt in thisMonthDebts:
            serializedObjects.append(debt.toDict)
        return self.respond(debts=serializedObjects)
Esempio n. 5
0
def export(request):
    import datetime
    from tuition.settings import SITE_SUPPORT_EMAIL
    from tuition.utils.manager import AppManager
    from tuition.utils.utils import ExportSelector, EXPORT_HANDLE_LABELS, getMonthEnd

    serializedObjectList = []
    linkToFile = None
    fileName = None
    isSaved = False
    noData = True
    invalidHandle = True
    response = {}

    classHandle = request.GET.get('classHandle', None)
    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())

    classWrapper = ExportSelector.getClass(classHandle)
    dataList = classWrapper().getForPeriod(loggedInEmployee.key(),
                                           firstOfMonth, endOfMonth)
    if dataList:
        noData = False
        for data in dataList:
            serializedObjectList.append(data.toDict)
        exporterClass = ExportSelector.getHandle(exportHandle)
        if exporterClass:
            invalidHandle = False
            exporterInstance = exporterClass(
                serializedObjects=serializedObjectList,
                request=request,
                remove=[
                    'key', 'user', 'calendarReminderURL', 'createdOn',
                    'updatedOn'
                ],
                date=exportDate,
                namePrefix=classHandle)
            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),
            'classHandle': classHandle,
            'invalidHandle': invalidHandle,
            'noData': noData,
            'loggedInEmployee': loggedInEmployee
        }
        return render_to_response('exportFinish.html',
                                  template_values,
                                  context_instance=RequestContext(request))
    else:
        return response