def unsubscribe(request, hash=None, token=None, perm_setting=None): """ Pulled from django contrib so that we can add user into the form so then we can show relevant messages about the user. """ assert hash is not None and token is not None user = None try: email = UnsubscribeCode.parse(token, hash) user = UserProfile.objects.get(email=email) except (ValueError, UserProfile.DoesNotExist): pass perm_settings = [] if user is not None: unsubscribed = True if not perm_setting: # TODO: make this work. nothing currently links to it, though. perm_settings = [l for l in notifications.NOTIFICATIONS if not l.mandatory] else: perm_setting = notifications.NOTIFICATIONS_BY_SHORT[perm_setting] UserNotification.update_or_create(update={'enabled': False}, user=user, notification_id=perm_setting.id) perm_settings = [perm_setting] else: unsubscribed = False email = '' return jingo.render(request, 'users/unsubscribe.html', {'unsubscribed': unsubscribed, 'email': email, 'perm_settings': perm_settings})
def save(self): u = super(UserEditForm, self).save(commit=False) data = self.cleaned_data photo = data['photo'] if photo: u.picture_type = 'image/png' tmp_destination = u.picture_path + '__unconverted' if not os.path.exists(u.picture_dir): os.makedirs(u.picture_dir) fh = open(tmp_destination, 'w') for chunk in photo.chunks(): fh.write(chunk) fh.close() resize_photo.delay(tmp_destination, u.picture_path, set_modified_on=[u]) for i, n in email.APP_NOTIFICATIONS_BY_ID.iteritems(): enabled = n.mandatory or (str(i) in data['notifications']) UserNotification.update_or_create(user=u, notification_id=i, update={'enabled': enabled}) log.debug(u'User (%s) updated their profile' % u) u.save() return u
def unsubscribe(request, hash=None, token=None, perm_setting=None): """ Pulled from django contrib so that we can add user into the form so then we can show relevant messages about the user. """ assert hash is not None and token is not None user = None try: email = UnsubscribeCode.parse(token, hash) user = UserProfile.objects.get(email=email) except (ValueError, UserProfile.DoesNotExist): pass perm_settings = [] if user is not None: unsubscribed = True if not perm_setting: # TODO: make this work. nothing currently links to it, though. perm_settings = [ l for l in notifications.NOTIFICATIONS if not l.mandatory ] else: perm_setting = notifications.NOTIFICATIONS_BY_SHORT[perm_setting] UserNotification.update_or_create(update={'enabled': False}, user=user, notification_id=perm_setting.id) perm_settings = [perm_setting] else: unsubscribed = False return jingo.render(request, 'users/unsubscribe.html', { 'unsubscribed': unsubscribed, 'perm_settings': perm_settings })