Ejemplo n.º 1
0
def logging_delete(sender, instance, **kwargs):

    if sender.__name__ in list_of_models:
        from django.forms.models import model_to_dict

        company = None
        user_str = "System"
        obj_attr = ""

        if 'company' in dir(instance) and instance.company:
            company = instance.company

        http_request = get_request()
        if http_request:
            request_user = get_request().user
            user_str = 'User %s' % request_user
            if not company:
                if not request_user.is_authenticated():
                    # if 'User AnonymousUser' == user_str:
                    user_str = 'Anonymous User'
                elif request_user.profile.company:
                    company = request_user.profile.company

        for key in model_to_dict(instance).keys():
            obj_attr += key.replace('_', ' ').upper() + ': ' + str(model_to_dict(instance)[key]) + '; '
        note = 'User %s deleted %s: %s \n %s' % (user_str, sender.__name__, str(instance), obj_attr)
        Log.objects.create(company=company, note=note)
Ejemplo n.º 2
0
    def deliver(self, recipient, sender, notice_type, extra_context):
        context = self.default_context()
        context.update(extra_context)

        if shadow_ban_applies(notice_type, recipient, context):
            return

        template = 'notice.html'
        message = self.get_formatted_messages([template], notice_type.label,
                                              context)[template]
        level = persistent_messages.INFO

        try:
            request = get_request()
            persistent_messages.add_message(request,
                                            level,
                                            message,
                                            user=recipient,
                                            from_user=sender)
        except IndexError:
            persistent_message = Message(user=recipient,
                                         from_user=sender,
                                         level=level,
                                         message=message)
            persistent_message.save()
Ejemplo n.º 3
0
def threaded_messages_thread_post_save(sender, instance, created, **kwargs):
    if created:
        try:
            request = get_request()
        except IndexError:
            # This may happen during unit testing
            return

        messages.success(request, _("Message sent"))
Ejemplo n.º 4
0
def threaded_messages_thread_post_save(sender, instance, created, **kwargs):
    if created:
        try:
            request = get_request()
        except InexError:
            # This may happen during unit testing
            return

        messages.success(request, _("Message sent"))
Ejemplo n.º 5
0
def construct_log_entry(**kwargs):
    instance = kwargs['instance']
    content_type = ContentType.objects.get_for_model(instance)
    user = get_request().user
    log_entry = {}
    log_entry['user'] = user
    log_entry['object_repr'] = str(instance)
    log_entry['content_type'] = content_type
    log_entry['object_id'] = instance.id if hasattr(instance, 'id') else -1
    return log_entry
Ejemplo n.º 6
0
def construct_log_entry(**kwargs):
    instance = kwargs['instance']
    content_type = ContentType.objects.get_for_model(instance)
    user = get_request().user
    log_entry = {}
    log_entry['user'] = user
    log_entry['object_repr'] = str(instance)
    log_entry['content_type'] = content_type 
    log_entry['object_id'] = instance.id if hasattr(instance, 'id') else -1
    return log_entry
Ejemplo n.º 7
0
    def updated_by_someone(self):
        if self.status != Product.PROCESSING:
            return False

        last_user = self.get_last_update_user()
        owner = self.get_owner()
        current_user = get_request().user
        if owner and last_user and current_user:
            if last_user.id != owner.id:
                if current_user.id == owner.id:
                    return True
        return False
Ejemplo n.º 8
0
    def updated_by_someone(self):
        if self.status != Product.PROCESSING:
            return False

        last_user = self.get_last_update_user()
        owner = self.get_owner()
        current_user = get_request().user
        if owner and last_user and current_user:
            if last_user.id != owner.id:
                if current_user.id == owner.id:
                    return True
        return False
Ejemplo n.º 9
0
def logging_update(sender, instance, **kwargs):
    if instance.pk and sender.__name__ in list_of_models:
        from django.forms.models import model_to_dict

        company = None
        user_str = "System"

        if 'company' in dir(instance) and instance.company:
            company = instance.company

        http_request = get_request()
        if http_request:
            request_user = get_request().user
            user_str = 'User %s' % request_user
            if not company:
                if not request_user.is_authenticated():
                    # if 'User AnonymousUser' == user_str:
                    user_str = 'Anonymous User'
                elif request_user.profile.company:
                    company = request_user.profile.company

        new_values = model_to_dict(instance)
        old_values = sender.objects.get(pk=instance.pk).__dict__
        for key in new_values.keys():
            if key not in old_values.keys():  # because there is a things in new_values that we don't need
                new_values.pop(key, None)
        changed = [key for key in new_values.keys() if ((old_values[key] != new_values[key]) and
                                                        not ((old_values[key] is None and new_values[key] == '')
                                                             or (old_values[key] == '' and new_values[key] is None)))]
        if len(changed) > 0:
            update = ''
            for key in changed:
                update += key.replace('_', ' ').upper() + ': from ' + str(old_values[key]) + ' to ' + str(new_values[key]) + '; '
            note = '%s updated %s: %s \n' % (user_str, sender.__name__, str(instance))
            note += update
            Log.objects.create(company=company, note=note)
Ejemplo n.º 10
0
    def deliver(self, recipient, sender, notice_type, extra_context):
        try:
            request = get_request()
        except IndexError:
            # This may happen during unit testing
            return

        context = self.default_context()
        context.update(extra_context)
        messages = self.get_formatted_messages(['notice.html'],
                                               notice_type.label, context)
        persistent_messages.add_message(request,
                                        persistent_messages.INFO,
                                        messages['notice.html'],
                                        user=recipient)
Ejemplo n.º 11
0
    def deliver(self, recipient, sender, notice_type, extra_context):
        try:
            request = get_request()
        except IndexError:
            # This may happen during unit testing
            return

        context = self.default_context()
        context.update(extra_context)
        messages = self.get_formatted_messages(['notice.html'],
            notice_type.label, context)
        persistent_messages.add_message(
            request,
            persistent_messages.INFO,
            messages['notice.html'],
            user = recipient)
Ejemplo n.º 12
0
    def get_context_data(self, **kwargs):
        firstweekday = 0 + SHIFT_WEEKSTART
        while firstweekday < 0:
            firstweekday += 7
        while firstweekday > 6:
            firstweekday -= 7

        ctx = self.get_category_context()
        month = [[]]
        week = 0
        start = datetime(year=self.year, month=self.month, day=1, tzinfo=utc)
        end = datetime(
            year=self.year, month=self.month, day=1, tzinfo=utc
        ) + relativedelta(months=1)

        all_occurrences = Event.objects.get_occurrences(
            start, end, ctx.get('current_category'))
        cal = calendar.Calendar()
        cal.setfirstweekday(firstweekday)

        req = get_request()        
        user_perm = req.user.get_all_permissions(obj=None)
        print(user_perm)
        for day in cal.itermonthdays(self.year, self.month):
            current = False
            if day:
                date = datetime(year=self.year, month=self.month, day=day,
                                tzinfo=utc)
                occurrences = filter(
                    lambda occ, date=date: occ.start.replace(
                        hour=0, minute=0, second=0, microsecond=0) == date,
                    all_occurrences)
                if date.date() == now().date():
                    current = True
            else:
                occurrences = []
            month[week].append((day, occurrences, current))
            if len(month[week]) == 7:
                month.append([])
                week += 1
        calendar.setfirstweekday(firstweekday)
        weekdays = [_(header) for header in calendar.weekheader(10).split()]
        ctx.update({'month': month, 'date': date, 'weekdays': weekdays})
        return ctx
Ejemplo n.º 13
0
    def get_context_data(self, **kwargs):
        firstweekday = 0 + SHIFT_WEEKSTART
        while firstweekday < 0:
            firstweekday += 7
        while firstweekday > 6:
            firstweekday -= 7

        ctx = self.get_category_context()
        month = [[]]
        week = 0
        start = datetime(year=self.year, month=self.month, day=1, tzinfo=utc)
        end = datetime(year=self.year, month=self.month, day=1,
                       tzinfo=utc) + relativedelta(months=1)

        all_occurrences = Event.objects.get_occurrences(
            start, end, ctx.get('current_category'))
        cal = calendar.Calendar()
        cal.setfirstweekday(firstweekday)

        req = get_request()
        user_perm = req.user.get_all_permissions(obj=None)
        print(user_perm)
        for day in cal.itermonthdays(self.year, self.month):
            current = False
            if day:
                date = datetime(year=self.year,
                                month=self.month,
                                day=day,
                                tzinfo=utc)
                occurrences = filter(lambda occ, date=date: occ.start.replace(
                    hour=0, minute=0, second=0, microsecond=0) == date,
                                     all_occurrences)
                if date.date() == now().date():
                    current = True
            else:
                occurrences = []
            month[week].append((day, occurrences, current))
            if len(month[week]) == 7:
                month.append([])
                week += 1
        calendar.setfirstweekday(firstweekday)
        weekdays = [_(header) for header in calendar.weekheader(10).split()]
        ctx.update({'month': month, 'date': date, 'weekdays': weekdays})
        return ctx
Ejemplo n.º 14
0
 def __init__(self, *args, **kwargs):
     self.request = get_request()
     super(ChangeLanguageForm, self).__init__(*args, **kwargs)
     self.initial.update({"language": self.account.language})
Ejemplo n.º 15
0
 def __init__(self, *args, **kwargs):
     self.team = kwargs.pop("team")
     self.request = get_request()
     super(AddUserForm, self).__init__(*args, **kwargs)
Ejemplo n.º 16
0
 def __init__(self, *args, **kwargs):
     self.project = kwargs.pop("project")
     self.user = kwargs.pop("user")
     self.request = get_request()
     super(AddUserForm, self).__init__(*args, **kwargs)
Ejemplo n.º 17
0
 def __init__(self, *args, **kwargs):
     self.request = get_request()
     super(SignupForm, self).__init__(*args, **kwargs)
Ejemplo n.º 18
0
 def __init__(self, *args, **kwargs):
     self.request = get_request()
     super(TwitterForm, self).__init__(*args, **kwargs)
     self.initial.update(
         {"username": other_service(self.user, "twitter_user")})
Ejemplo n.º 19
0
 def __init__(self, *args, **kwargs):
     self.request = get_request()
     super(ChangeTimezoneForm, self).__init__(*args, **kwargs)
     self.initial.update({"timezone": self.account.timezone})
Ejemplo n.º 20
0
 def __init__(self, *args, **kwargs):
     self.request = get_request()
     super(ResetPasswordForm, self).__init__(*args, **kwargs)
Ejemplo n.º 21
0
 def __init__(self, *args, **kwargs):
     self.request = get_request()
     super(AddEmailForm, self).__init__(*args, **kwargs)