-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from sei-vsarvepalli/version-2.0.5
Version 2.0.5. Pretty close to our production. A few CSS files updates pending.
- Loading branch information
Showing
27 changed files
with
1,273 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from django.contrib.auth.models import User | ||
from vinny.views import VinceProfile as vp | ||
|
||
|
||
|
||
def mute_user(useremail,case_id,interactive=False): | ||
""" Mute case for a user with `useremail` identified for a `case_id` | ||
on success it return 0 (no need to update) or 1. If the user is not | ||
found or user has nor profile, it returns -ve number repsectively. | ||
You should use this with try/except block for web/API usage | ||
""" | ||
q = User.objects.filter(username=useremail).using('vincecomm').first() | ||
l = vp.objects.filter(user=q).first() | ||
if not q: | ||
if interactive: | ||
print(f"User {useremail} not found") | ||
return -1 | ||
if not l: | ||
if interactive: | ||
print(f"User {useremail} Profile not found") | ||
return -2 | ||
d = q.vinceprofile.settings.copy() | ||
if 'muted_cases' in d: | ||
if case_id in d['muted_cases']: | ||
if interactive: | ||
print(f"Case id {case_id} already muted for {useremail}") | ||
print(d) | ||
return 0 | ||
else: | ||
d['muted_cases'] += [case_id] | ||
else: | ||
d['muted_cases'] = [case_id] | ||
l._set_settings(d) | ||
l.save() | ||
if interactive: | ||
print("Updated profile settings are ") | ||
print(l._get_settings()) | ||
return 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import inspect | ||
import pathlib | ||
import mimetypes | ||
import uuid | ||
import re | ||
#Utilities for VINCE to use that are generic | ||
|
||
def get_ip(request): | ||
""" GET IP address of a request object and find it using simple | ||
method of the first X-Forwarded-For header IP from proxy/web server | ||
or the REMOTE_ADDR environment setup by the appserver. Returns a | ||
string not an IP validated item/object. | ||
""" | ||
try: | ||
if request.META.get('HTTP_X_FORWARDED_FOR'): | ||
return request.META.get('HTTP_X_FORWARDED_FOR').split(',')[0] | ||
elif request.META.get('REMOTE_ADDR'): | ||
return request.META.get('REMOTE_ADDR') | ||
else: | ||
return "Unknown" | ||
except Exception as e: | ||
return f"IP lookup Exception {e}" | ||
return "Unknown" | ||
|
||
|
||
def deepGet(obj,idir): | ||
""" Given an object of any kind find if it is a dictionary | ||
or a list or an abstract object or instance of a class | ||
that has a burried element. | ||
""" | ||
x = obj | ||
for s in idir.split("."): | ||
if not x: | ||
return None | ||
if isinstance(x,dict) and s in x: | ||
x = x[s] | ||
elif isinstance(x,list) and s.isdigit() and int(s) < len(x): | ||
x = x[int(s)] | ||
elif hasattr(x,s): | ||
x = getattr(x,s) | ||
if callable(x) and not inspect.isclass(x): | ||
x = x() | ||
else: | ||
return None | ||
return x | ||
|
||
def safe_filename(filename,file_uuid=str(uuid.uuid4()),mime_type="application/octet-stream"): | ||
filename = filename.replace("\r"," ").replace("\n"," ").strip() | ||
if re.search(r'[^\x00-\x7F]+',filename): | ||
#non-ascii filenames use uuid and extension | ||
if file_uuid == None: | ||
file_uuid = uuid.uuid4() | ||
file_extension = "".join(pathlib.Path(filename).suffixes) | ||
if file_extension: | ||
filename = file_uuid + file_extension | ||
elif mimetypes.guess_extension(mime_type): | ||
filename = file_uuid + mimetypes.guess_extension(mime_type) | ||
else: | ||
filename = file_uuid | ||
return filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.