예제 #1
0
def monthcal(user, size = 'small', year = date.today().year, month = date.today().month):
    year, month = int(year), int(month)
    event_list = []
    events = Milestone.objects.filter(Q(responsible = None) | Q(responsible = user), due_date__year = year, due_date__month = month, completion_date = None)
    for event in events:
        project = event.project
        if checkperm(PERMISSIONS_MILESTONE_VIEW, user, project):
            event_list.append(event)
    first_day_of_month = date(year, month, 1)
    last_day_of_month = get_last_day_of_month(year, month)
    first_day_of_calendar = first_day_of_month - timedelta(first_day_of_month.weekday())
    last_day_of_calendar = last_day_of_month + timedelta(7 - last_day_of_month.weekday())

    month_cal = []
    week = []
    week_headers = []

    i = 0
    day = first_day_of_calendar
    while day <= last_day_of_calendar:
        if i < 7:
            week_headers.append(day)
        cal_day = {}
        cal_day['day'] = day
        cal_day['event'] = None
        for event in event_list:
            if day >= event.due_date.date() and day <= day <= event.due_date.date():
                if day < date.today():
                    cal_day['event'] = 'late'
                else:
                    cal_day['event'] = 'upcoming'
        if day.month == month:
            cal_day['in_month'] = True
        else:
            cal_day['in_month'] = False
        if day == date.today():
            cal_day['today'] = True
        week.append(cal_day)
        if day.weekday() == 6:
            month_cal.append(week)
            week = []
        i += 1
        day += timedelta(1)
    #TODO: ROCHA: this has to be refactored to really work for a month
    today = date.today()
    next_month = first_day_of_month + datetime.timedelta(days = 31)
    previous_month = first_day_of_month - datetime.timedelta(days = 5)
    return {'calendar': month_cal, 'headers': week_headers, 'size': size,
            'today': today, 'next_month': next_month, 'previous_month': previous_month, 'current_month': first_day_of_month}
예제 #2
0
    def render(self, context):
        try:
            user = template.Variable(self.user).resolve(context)
            if self.object:
                object = template.Variable(self.object).resolve(context)
            else:
                object = None
            if self.project:
                project = template.Variable(self.project).resolve(context)
            else:
                project = None

            permission = eval('permissions.%s' % self.permission)

            if permissions.checkperm(permission, user, project, object):
                return self.nodelist_true.render(context)
        # If either variable fails to resolve, return nothing.
        except template.VariableDoesNotExist:
            return ''
        # If the types don't permit comparison, return nothing.
        except TypeError:
            return ''
        return self.nodelist_false.render(context)
예제 #3
0
    def render(self, context):
        try:
            user = template.Variable(self.user).resolve(context)
            if self.object:
                object = template.Variable(self.object).resolve(context)
            else:
                object = None
            if self.project:
                project = template.Variable(self.project).resolve(context)
            else:
                project = None

            permission = eval('permissions.%s'%self.permission)

            if permissions.checkperm(permission, user, project, object):
                return self.nodelist_true.render(context)
        # If either variable fails to resolve, return nothing.
        except template.VariableDoesNotExist:
            return ''
        # If the types don't permit comparison, return nothing.
        except TypeError:
            return ''
        return self.nodelist_false.render(context)
예제 #4
0
def genmenu(context, menu_title, active_menu, url=None, before_text=None, on_name=None):
    if not on_name:
        on_name=u'active'

    if url:
        if type(url) in (int, long): #to support when user only puts a variable
            args = [url]
        else:
            args = [Variable(arg).resolve(context) for arg in url.split(',')]
    else:
        args = []

    try:
        active_menu = active_menu
        if active_menu[-1]==u'/':
            active_menu = active_menu[0:-1]
        if active_menu[0]==u'/':
            active_menu = active_menu[1:]
    except IndexError:
        pass

    open_before_text = u''
    close_before_text = u''
    if before_text:
        open_before_text = u'<'+before_text+u'>'
        close_before_text = u'</'+before_text+u'>'
    menus = u'<ul>'
    menu = u''

    project = context.get('project')
    user = context.get('user')
    for label, url_final, id, perm in MENUS[str(menu_title)]:
        #check permission
        if permissions.checkperm(perm, user, project):
            menu+=u'<li'

            if url_final[-1]==u'/':
                url_final = url_final[0:-1]
            if url_final[0]==u'/':
                url_final = url_final[1:]
            if active_menu!=u'':
                if id==active_menu:
                    menu+=u' class="%s">' % on_name
                else:
                    menu+=u'>'
            else:
                menu+=u'>'

            if len(args) != 0:
                number_of_params_to_replace = url_final.count('%s')
                difference = number_of_params_to_replace - len(args)
                if difference > 0:
                    for i in xrange(0, difference):
                        args.append(args[-1])
                for arg in args:
                    url_final = url_final.replace('%s', str(arg), 1)

            menu+=u'<a href="/%s">%s%s%s</a></li>'%(url_final, open_before_text,label, close_before_text)

    menus+=menu+u'</ul>'

    return {'menu': menus}
예제 #5
0
def monthcal(user,
             size='small',
             year=date.today().year,
             month=date.today().month):
    year, month = int(year), int(month)
    event_list = []
    events = Milestone.objects.filter(Q(responsible=None)
                                      | Q(responsible=user),
                                      due_date__year=year,
                                      due_date__month=month,
                                      completion_date=None)
    for event in events:
        project = event.project
        if checkperm(PERMISSIONS_MILESTONE_VIEW, user, project):
            event_list.append(event)
    first_day_of_month = date(year, month, 1)
    last_day_of_month = get_last_day_of_month(year, month)
    first_day_of_calendar = first_day_of_month - timedelta(
        first_day_of_month.weekday())
    last_day_of_calendar = last_day_of_month + timedelta(
        7 - last_day_of_month.weekday())

    month_cal = []
    week = []
    week_headers = []

    i = 0
    day = first_day_of_calendar
    while day <= last_day_of_calendar:
        if i < 7:
            week_headers.append(day)
        cal_day = {}
        cal_day['day'] = day
        cal_day['event'] = None
        for event in event_list:
            if day >= event.due_date.date(
            ) and day <= day <= event.due_date.date():
                if day < date.today():
                    cal_day['event'] = 'late'
                else:
                    cal_day['event'] = 'upcoming'
        if day.month == month:
            cal_day['in_month'] = True
        else:
            cal_day['in_month'] = False
        if day == date.today():
            cal_day['today'] = True
        week.append(cal_day)
        if day.weekday() == 6:
            month_cal.append(week)
            week = []
        i += 1
        day += timedelta(1)
    #TODO: ROCHA: this has to be refactored to really work for a month
    today = date.today()
    next_month = first_day_of_month + datetime.timedelta(days=31)
    previous_month = first_day_of_month - datetime.timedelta(days=5)
    return {
        'calendar': month_cal,
        'headers': week_headers,
        'size': size,
        'today': today,
        'next_month': next_month,
        'previous_month': previous_month,
        'current_month': first_day_of_month
    }