Ejemplo n.º 1
0
    def templateParams(self):
        defaults = super(ActivityView, self).templateParams()
        user = get_current_user()
        aid = self.actobj.key().id()
        specialOps = []
        if (hasActPrivilige(user, self.actobj, "edit")):
            sop = SpecialOp('edit', urldict['ActivityEdit'].path(aid), False)
            specialOps.append(sop)
        urlcfg = urldict['ActivityParticipate']
        soplist = ['join', 'quit', 'confirm']
        if (self.actobj.isBilled):
            soplist.append("rebill")
        else:
            soplist.append("bill")
        for oper in soplist:
            if (hasActPrivilige(user, self.actobj, oper)):
                data = [
                    ('target', user.email()),
                ]
                sop = SpecialOp(oper, urlcfg.path(aid, oper), True, data)
                specialOps.append(sop)
        defaults['specialOps'] = specialOps

        participatorOps = []
        for oper in ('confirm', ):
            if (hasActPrivilige(user, self.actobj, oper)):
                sop = SpecialOp(oper, urlcfg.path(aid, oper), True, [])
                participatorOps.append(sop)
        defaults['participatorOps'] = participatorOps
        apq = ActivityParticipator.all()
        apq.filter('activity = ', self.actobj)
        defaults['participators'] = apq
        return defaults
Ejemplo n.º 2
0
	def templateParams(self):
		defaults = super (ActivityView, self).templateParams()
		user = get_current_user();
		aid = self.actobj.key().id()
		specialOps = []
		if (hasActPrivilige(user, self.actobj, "edit" )):
			sop = SpecialOp('edit', urldict['ActivityEdit'].path(aid), False)
			specialOps.append(sop)
		urlcfg = urldict['ActivityParticipate']
		soplist = ['join', 'quit', 'confirm']
		if (self.actobj.isBilled):
			soplist.append("rebill")
		else:
			soplist.append("bill")
		for oper in soplist:
			if (hasActPrivilige(user, self.actobj, oper) ):
				data = [('target', user.email()), ]
				sop = SpecialOp(oper, urlcfg.path(aid, oper), True, data)
				specialOps.append(sop)
		defaults['specialOps'] = specialOps
		
		participatorOps = []
		for oper in ('confirm', ):
			if (hasActPrivilige(user, self.actobj, oper) ):
				sop = SpecialOp(oper, urlcfg.path(aid, oper), True, [])
				participatorOps.append(sop)
		defaults['participatorOps'] = participatorOps
		apq = ActivityParticipator.all()
		apq.filter ('activity = ', self.actobj)
		defaults['participators'] = apq
		return defaults
Ejemplo n.º 3
0
    def post(self, *args):
        urlcfg = urldict['ActivityParticipate']
        id, oper = urlcfg.analyze(self.request.path)
        id = int(id)
        actobj = self.getActModel(id)
        if (not actobj):
            return errorPage(self.response, urldict['ClubList'].path(),
                             "No such activity", 404)
        user = get_current_user()
        if (not user):
            return errorPage(self.response, "Not login",
                             create_login_url(self.request.url), 403)
        target = self.request.get('target')
        cluburl = urldict['ClubView'].path(actobj.club.slug)
        if (not hasActPrivilige(user, actobj, oper, target)):
            return errorPage(self.response, "Can not access", cluburl, 403)
        if (target):
            targetUser = User(target)
            if (not targetUser):
                return errorPage(self.response, "Illegal access", cluburl, 403)
        else:  #if target omitted, use current user as target
            targetUser = user

        mem = Membership.between(targetUser, actobj.club)
        if (not mem):
            return errorPage(self.response, "Not a member", cluburl, 403)

        acturl = urldict['ActivityView'].path(id)
        if (oper == 'join'):
            actp = ActivityParticipator.between(mem, actobj)
            if (not actp):
                actp = ActivityParticipator(member=mem, activity=actobj)
                actp.put()
            return infoPage(
                self.response, "Successfully Joined",
                "%s has join activity %s" % (mem.name, actobj.name), acturl)
        elif (oper == 'quit'):
            actp = ActivityParticipator.between(mem, actobj)
            if (actp):
                if (actp.confirmed):
                    return errorPage(self.response,
                                     "Cannot delete confirmed participator",
                                     acturl, 403)
                else:
                    actp.delete()
            return infoPage(
                self.response, "Successfully Quited",
                "%s success quit activity %s" % (mem.name, actobj.name),
                acturl)
        elif (oper == 'confirm'):
            actp = ActivityParticipator.between(mem, actobj)
            if (actp):
                actp.confirmed = not actp.confirmed
                actp.put()
                return infoPage(
                    self.response, "Successfully Confirmed",
                    "success confirmed %s join activity %s" %
                    (mem.name, actobj.name), acturl)
            else:
                return errorPage(self.response, "No Such a Member", acturl,
                                 404)
        elif (oper == 'bill' or oper == "rebill"):
            billobj = ActivityBill.generateBill(
                actobj, oper ==
                "rebill")  #If in rebill operation, we could enable rebill
            if (billobj):
                billobj.put()
                billDict = dict(billobj=billobj)
                return infoPage(self.response, "Successfully Billded",
                                str(billobj.memberBill), acturl)
            else:
                return errorPage(self.response, "Error Will Generate Bill",
                                 acturl, 501)
Ejemplo n.º 4
0
	def can_quit(self, *args):
		parti = ActivityParticipator.between(self.user, self.act)
		if (parti):
			return not parti.confirmed
		return False
Ejemplo n.º 5
0
	def post(self, *args):
		urlcfg = urldict['ActivityParticipate']
		id, oper = urlcfg.analyze(self.request.path)
		id = int(id)
		actobj = self.getActModel(id)
		if (not actobj):
			return errorPage (self.response,  urldict['ClubList'].path(),  "No such activity",  404 )
		user = get_current_user();
		if (not user):
			return errorPage ( self.response,  "Not login",   create_login_url(self.request.url),   403)
		target = self.request.get ('target')
		cluburl = urldict['ClubView'].path(actobj.club.slug)
		if (not hasActPrivilige(user, actobj, oper,target) ):
			return errorPage ( self.response,  "Can not access",   cluburl,   403)
		if (target):
			targetUser = User(target)
			if(not targetUser):
				return errorPage ( self.response,  "Illegal access",   cluburl,   403)
		else: #if target omitted, use current user as target
			targetUser = user
			
		mem = Membership.between (targetUser, actobj.club)
		if (not mem):
			return errorPage ( self.response,  "Not a member",   cluburl,   403)
		
		acturl = urldict['ActivityView'].path(id)
		if (oper == 'join'):
			actp = ActivityParticipator.between (mem, actobj)
			if (not actp):
				actp = ActivityParticipator(member = mem, activity = actobj)
				actp.put()
			return infoPage (self.response, "Successfully Joined", "%s has join activity %s" % (mem.name, actobj.name), acturl)
		elif (oper == 'quit'):
			actp = ActivityParticipator.between(mem, actobj)
			if (actp):
				if (actp.confirmed):
					return errorPage ( self.response,  "Cannot delete confirmed participator",   acturl,   403)
				else:
					actp.delete()
			return infoPage (self.response, "Successfully Quited", "%s success quit activity %s" % (mem.name, actobj.name), acturl)
		elif (oper == 'confirm'):
			actp = ActivityParticipator.between(mem, actobj)
			if (actp):
				actp.confirmed = not actp.confirmed 
				actp.put()
				return infoPage (self.response, "Successfully Confirmed", "success confirmed %s join activity %s" % (mem.name, actobj.name), acturl)
			else:
				return errorPage ( self.response,  "No Such a Member",   acturl,   404)
		elif (oper == 'bill' or oper == "rebill"):
			billobj = ActivityBill.generateBill(actobj, oper == "rebill")#If in rebill operation, we could enable rebill
			if (billobj):
				billobj.put()
				billDict = dict(billobj = billobj)
				return infoPage (self.response, "Successfully Billded", str(billobj.memberBill), acturl)
			else:
				return errorPage (self.response, "Error Will Generate Bill", acturl, 501)