示例#1
0
    def report(self):
        ''' Activates chore if necessary, otherwise nudges/logs infraction. '''
        message = ""
        if not self.active:
            usr = self.appliance.last_user
            ud = usr.userdetail
            if(ud.is_absent):
                Infraction.objects.create(chore=self, user=usr)
                message = "{0} is absent. An infraction was logged.".format(usr.username)
            else:
                self.assigned_time=timezone.now()
                self.active = True
                self.assignee = usr
                self.reset_nudges()
                self.save()

                from dishes.tasks import sendemail
                title = "[COLEMASS] Appliance chore assignment"
                body = "Dear {0},\n\nYou left the appliance {1} in an unsatisfactory condition."  \
                " Please fix it".format(self.assignee.username, self.appliance)
                sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
                to = [self.asignee.email, ]
                sendemail(title, body, sender, to)

                message = "{0} has been notified to complete the chore \"{1}\".".format(usr.username, self.name)
        else:
            message = super(ApplianceChore, self).report()
        return message
示例#2
0
文件: models.py 项目: d4sc/COLEMASS
    def complete(self, user):
        ''' Base chore completion + round-robin reassignment. '''
        super(RecurringChore, self).complete(user)
        self.send_to_end(user)

        from dishes.tasks import sendemail
        title = "[COLEMASS] Chore assignment"
        body = "Hi {0},\n\nThe chore \"{1}\" has been assigned to you.".format(self.assignee.username, self.name)
        sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
        to = [self.assignee.email, ]
        sendemail(title, body, sender, to)
示例#3
0
def newuser(request):
    '''
    Checks for the validity of the email.
    Checks if space is available for more users
    Creates a user with email as the username and also creates a valid key which
    is used for security purpose.
    '''
    try:
        cards = Card.objects.filter(user=None).exclude(is_broken=True)
        if ((request.method=='POST') & (validatemail(request.POST.get('newuser')))) & (len(cards)>0):
            if not (User.objects.filter(email=request.POST.get('newuser')).exists()) or not (User.objects.filter(username=request.POST.get('newuser')).exists()):
                randstring = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(32)])
                try:
                    nwuser = User.objects.create_user(request.POST.get('newuser'), request.POST.get('newuser'))
                    nwuser.is_active=False
                    nwuser.save()
                    UserDetail.objects.create(user=nwuser)
                except:
                    messages.error(request, "Database Connectivity Error:Please try again.")
                try:
                    userdet=UserDetail.objects.get(user=nwuser)
                    userdet.valid_key=randstring
                    userdet.valid_key_time = timezone.now()
                    userdet.save()
                except:
                    nwuser.delete()
                    messages.error(request, "Database Connectivity Error:Please try again.")
                try:
                    resetlink='http://'+request.get_host()+'/user/register/'+request.POST.get('newuser')+'/'+randstring

                    from dishes.tasks import sendemail
                    title = "[COLEMASS] Invitation"
                    body = "Hi {0},\n\nYou have been invited to join COLEMASS by {1}. Please follow the link to join our network and set your COLEMASS password.\n{2} \nRegards,\nColemass Team".format(request.POST.get('newuser'), request.user, resetlink)
                    sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
                    to = [request.POST.get('newuser'), ]
                    sendemail(title, body, sender, to)
                    j='09'
                    messages.success(request, "Invitation sent.")
                except:
                    nwuser.delete()
                    messages.error(request, "Error in sending email Please try again later.")
            else:
                messages.error(request, "User has already been invited")
        else:
            if not (validatemail(request.POST.get('newuser'))):
                messages.error(request, "Please provide a valid email address.")
            elif len(cards)<1:
                messages.error(request, "There are not enough cards for a new user.")
            else:
                messages.error(request, "Error.")
    except:
        messages.error(request, "Unknown Error: Please try again")
    return redirect('users:settings')
示例#4
0
文件: views.py 项目: d4sc/COLEMASS
def completed_chore_challenge(request):
    completed_chore = get_object_or_404(CompletedChore, pk=request.POST.get('pk'))
    completed_chore.challenge()
    messages.error(request, "You rejected {0}'s completion of \"{1}\"".format(completed_chore.user.username, completed_chore.chore.name))

    from dishes.tasks import sendemail
    title = "[COLEMASS] Chore completion refused"
    body = "Hi {0},\n\nThe chore \"{1}\" that you've completed was declined. You've been reassigned the chore".format(completed_chore.user, completed_chore.chore)
    sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
    to = [completed_chore.user.email, ]
    sendemail(title, body, sender, to)

    return redirect('mycolemass')
示例#5
0
    def complete(self, user):
        ''' Base chore completion + round-robin reassignment. '''
        super(RecurringChore, self).complete(user)
        self.send_to_end(user)

        from dishes.tasks import sendemail
        title = "[COLEMASS] Chore assignment"
        body = "Hi {0},\n\nThe chore \"{1}\" has been assigned to you.".format(
            self.assignee.username, self.name)
        sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
        to = [
            self.assignee.email,
        ]
        sendemail(title, body, sender, to)
示例#6
0
文件: views.py 项目: d4sc/COLEMASS
def refusal_challenge(request):
    refused_chore = get_object_or_404(RefusedChore, pk=request.POST.get('pk'))
    refused_chore.confirm()
    messages.error(request, "You rejected {0}'s reason for refusing \"{1}\"".format(refused_chore.user.username, refused_chore.chore.name))

    from dishes.tasks import sendemail
    title = "[COLEMASS] Chore refusal rejected"
    body = "Hi {0},\n\nThe refusal of chore \"{1}\" was declined. You've been reassigned the chore".format(refused_chore.user, refused_chore.chore)
    sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
    to = [refused_chore.user.email, ]
    sendemail(title, body, sender, to)



    return redirect('mycolemass')
示例#7
0
文件: models.py 项目: d4sc/COLEMASS
    def refuse(self, reason):
        ''' Base chore refusal + round-robin reassignment. '''
        refusing_user = self.assignee
        super(RecurringChore, self).refuse(reason)
        self.send_to_end(self.assignee)
        print(self.assignee.username)
        print(self.name)
        print(refusing_user.username)

        from dishes.tasks import sendemail
        title = "[COLEMASS] Chore assignment"
        body = "Hi {0},\n\nThe chore \"{1}\" has been refused by {2} and it has been assigned to you.\nYou can challenge this assignment in your Colemass.".format(self.assignee.username, self.name, refusing_user.username)
        sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
        to = [self.assignee.email, ]
        sendemail(title, body, sender, to)
示例#8
0
    def report(self):
        '''
        Nudges assignee, possibly logs infraction. Emails relevant user.
        Returns a message to be displayed in the web app
        '''
        message = "It is too early to nudge {0} for \"{1}\"".format(
            self.assignee.username, self.name)
        if (timezone.now() -
                self.last_nudge) > datetime.timedelta(seconds=NUDGE_DELAY):
            # anti spam check
            self.nudges += 1
            self.last_nudge = timezone.now()
            self.save()
            if (self.nudges % INFRACTION_THRESHOLD
                    == 0) and not (self.nudges == 0):
                # every three reports, log an infraction
                Infraction.objects.create(chore=self, user=self.assignee)

                from dishes.tasks import sendemail
                title = "[COLEMASS] Infraction"
                body = "Hi {0},\n\n An infraction has been logged " \
                    "for not completing \"{1}\".".format(self.assignee.username, self.name)
                sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
                to = [
                    self.assignee.email,
                ]
                sendemail(title, body, sender, to)

                message = "{0} was nudged for \"{1}\" and an infraction was logged.".format(
                    self.assignee.username, self.name)
            else:

                from dishes.tasks import sendemail
                title = "[COLEMASS] Friendly reminder"
                body = "Hi {0},\n\nYou have been nudged {1} time{2} " \
                "to complete the chore \"{3}\".".format(self.assignee.username, self.nudges, ('s','')[self.nudges==1], self.name)
                sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
                to = [
                    self.assignee.email,
                ]
                sendemail(title, body, sender, to)

                message = "{0} was nudged for \"{1}\".".format(
                    self.assignee.username, self.name)
        return message
示例#9
0
    def refuse(self, reason):
        ''' Base chore refusal + round-robin reassignment. '''
        refusing_user = self.assignee
        super(RecurringChore, self).refuse(reason)
        self.send_to_end(self.assignee)
        print(self.assignee.username)
        print(self.name)
        print(refusing_user.username)

        from dishes.tasks import sendemail
        title = "[COLEMASS] Chore assignment"
        body = "Hi {0},\n\nThe chore \"{1}\" has been refused by {2} and it has been assigned to you.\nYou can challenge this assignment in your Colemass.".format(
            self.assignee.username, self.name, refusing_user.username)
        sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
        to = [
            self.assignee.email,
        ]
        sendemail(title, body, sender, to)
示例#10
0
def refusal_challenge(request):
    refused_chore = get_object_or_404(RefusedChore, pk=request.POST.get('pk'))
    refused_chore.confirm()
    messages.error(
        request, "You rejected {0}'s reason for refusing \"{1}\"".format(
            refused_chore.user.username, refused_chore.chore.name))

    from dishes.tasks import sendemail
    title = "[COLEMASS] Chore refusal rejected"
    body = "Hi {0},\n\nThe refusal of chore \"{1}\" was declined. You've been reassigned the chore".format(
        refused_chore.user, refused_chore.chore)
    sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
    to = [
        refused_chore.user.email,
    ]
    sendemail(title, body, sender, to)

    return redirect('mycolemass')
示例#11
0
def completed_chore_challenge(request):
    completed_chore = get_object_or_404(CompletedChore,
                                        pk=request.POST.get('pk'))
    completed_chore.challenge()
    messages.error(
        request, "You rejected {0}'s completion of \"{1}\"".format(
            completed_chore.user.username, completed_chore.chore.name))

    from dishes.tasks import sendemail
    title = "[COLEMASS] Chore completion refused"
    body = "Hi {0},\n\nThe chore \"{1}\" that you've completed was declined. You've been reassigned the chore".format(
        completed_chore.user, completed_chore.chore)
    sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
    to = [
        completed_chore.user.email,
    ]
    sendemail(title, body, sender, to)

    return redirect('mycolemass')
示例#12
0
文件: models.py 项目: d4sc/COLEMASS
    def report(self):
        '''
        Nudges assignee, possibly logs infraction. Emails relevant user.
        Returns a message to be displayed in the web app
        '''
        message = "It is too early to nudge {0} for \"{1}\"".format(self.assignee.username, self.name)
        if (timezone.now() - self.last_nudge) > datetime.timedelta(seconds=NUDGE_DELAY):
            # anti spam check
            self.nudges += 1
            self.last_nudge = timezone.now()
            self.save()
            if (self.nudges % INFRACTION_THRESHOLD == 0) and not (self.nudges == 0):
                # every three reports, log an infraction
                Infraction.objects.create(chore=self, user=self.assignee)

                from dishes.tasks import sendemail
                title = "[COLEMASS] Infraction"
                body = "Hi {0},\n\n An infraction has been logged " \
                    "for not completing \"{1}\".".format(self.assignee.username, self.name)
                sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
                to = [self.assignee.email, ]
                sendemail(title, body, sender, to)

                message = "{0} was nudged for \"{1}\" and an infraction was logged.".format(self.assignee.username, self.name)
            else:

                from dishes.tasks import sendemail
                title = "[COLEMASS] Friendly reminder"
                body = "Hi {0},\n\nYou have been nudged {1} time{2} " \
                "to complete the chore \"{3}\".".format(self.assignee.username, self.nudges, ('s','')[self.nudges==1], self.name)
                sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
                to = [self.assignee.email, ]
                sendemail(title, body, sender, to)

                message = "{0} was nudged for \"{1}\".".format(self.assignee.username, self.name)
        return message
示例#13
0
def newuser(request):
    '''
    Checks for the validity of the email.
    Checks if space is available for more users
    Creates a user with email as the username and also creates a valid key which
    is used for security purpose.
    '''
    try:
        cards = Card.objects.filter(user=None).exclude(is_broken=True)
        if ((request.method == 'POST') &
            (validatemail(request.POST.get('newuser')))) & (len(cards) > 0):
            if not (User.objects.filter(email=request.POST.get(
                    'newuser')).exists()) or not (User.objects.filter(
                        username=request.POST.get('newuser')).exists()):
                randstring = ''.join([
                    random.choice(string.ascii_letters + string.digits)
                    for n in range(32)
                ])
                try:
                    nwuser = User.objects.create_user(
                        request.POST.get('newuser'),
                        request.POST.get('newuser'))
                    nwuser.is_active = False
                    nwuser.save()
                    UserDetail.objects.create(user=nwuser)
                except:
                    messages.error(
                        request,
                        "Database Connectivity Error:Please try again.")
                try:
                    userdet = UserDetail.objects.get(user=nwuser)
                    userdet.valid_key = randstring
                    userdet.valid_key_time = timezone.now()
                    userdet.save()
                except:
                    nwuser.delete()
                    messages.error(
                        request,
                        "Database Connectivity Error:Please try again.")
                try:
                    resetlink = 'http://' + request.get_host(
                    ) + '/user/register/' + request.POST.get(
                        'newuser') + '/' + randstring

                    from dishes.tasks import sendemail
                    title = "[COLEMASS] Invitation"
                    body = "Hi {0},\n\nYou have been invited to join COLEMASS by {1}. Please follow the link to join our network and set your COLEMASS password.\n{2} \nRegards,\nColemass Team".format(
                        request.POST.get('newuser'), request.user, resetlink)
                    sender = getattr(settings, "EMAIL_HOST_USER", 'colemass')
                    to = [
                        request.POST.get('newuser'),
                    ]
                    sendemail(title, body, sender, to)
                    j = '09'
                    messages.success(request, "Invitation sent.")
                except:
                    nwuser.delete()
                    messages.error(
                        request,
                        "Error in sending email Please try again later.")
            else:
                messages.error(request, "User has already been invited")
        else:
            if not (validatemail(request.POST.get('newuser'))):
                messages.error(request,
                               "Please provide a valid email address.")
            elif len(cards) < 1:
                messages.error(request,
                               "There are not enough cards for a new user.")
            else:
                messages.error(request, "Error.")
    except:
        messages.error(request, "Unknown Error: Please try again")
    return redirect('users:settings')