示例#1
0
文件: api.py 项目: chiptip/equality
def unreserve(request, year, month, day):
    result = { 'success': 0, 'description': None }

    if request.user.is_authenticated():
        user = request.user
        slug = request.POST.get('slug', None)
        period = request.POST.get('period', None)
        try:
            selected_date = date(int(year), int(month), int(day))
            
            try:
                removeReservation(user, selected_date, slug, period)
                reservations = getReservations(user, selected_date)
                result['success'] = 1
                result['reservations'] = reservations
            except Exception as e:
                result['description'] = str(e)
            
        except:
            result['description'] = 'Not a valid date: YYYY - %s, MM - %s, DD - %s' % (year, month, day)
        
    else:
        result['description'] = NOT_AUTH_MSG
        
    return render_to_json(result)
示例#2
0
文件: admin.py 项目: chiptip/equality
    def changelist_view(self, request, extra_context=None):
        
        # get queried date
        selected_year, selected_month, selected_day = self._get_selected_date(request)
        selected_date = date(selected_year, selected_month, selected_day)
        user = request.user
        
        reservations = getReservations(user, selected_date)
        
        # appending tags to context to render advanced tag filter panel
        extra_context = { 
                         'selected_year': selected_year, 
                         'selected_month': selected_month,
                         'selected_day': selected_day,
                         'reservations': reservations
                         }

        # call super class render method, but using extract context
        return super(ReservationAdmin, self).changelist_view(request, extra_context)